6e7b96cd66
- Move fetch_plugin from finalize::plugin::fetch to utils::fetch_plugin - Delete unused crates: workshop-cert, workshop-deviceid, workshop-vault - Remove parser benchmarks and empty daemon/socket modules - Add new workshop-getterurl crate for resource fetching
46 lines
1.2 KiB
Rust
46 lines
1.2 KiB
Rust
mod checksum;
|
|
mod error;
|
|
mod extract;
|
|
mod file;
|
|
mod git;
|
|
mod http;
|
|
mod scheme;
|
|
mod types;
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
pub use error::FetchError;
|
|
pub use scheme::Scheme;
|
|
pub use types::FetchArgument;
|
|
|
|
/// Fetch an external resource to a target directory. Returns the local path.
|
|
///
|
|
/// - `git://repo@tag` → clone
|
|
/// - `https://url` → download (+ checksum + extract)
|
|
/// - `file:///path` → copy to target
|
|
///
|
|
/// Note: `workspace://` must be converted to `file://` by the caller before passing.
|
|
pub async fn fetch_resource(
|
|
name: &str,
|
|
url: &str,
|
|
target: &Path,
|
|
) -> Result<PathBuf, FetchError> {
|
|
let scheme = scheme::parse_url(url)?;
|
|
match scheme {
|
|
Scheme::Git { repo, git_ref } => {
|
|
let full_url = if git_ref.is_empty() {
|
|
repo.clone()
|
|
} else {
|
|
format!("{}@{}", repo, git_ref)
|
|
};
|
|
git::fetch_git_plugin(&full_url, name, target, None).await?;
|
|
Ok(target.join(name))
|
|
}
|
|
Scheme::Http { url, checksum } => {
|
|
http::fetch_http_plugin(&url, name, target, checksum.as_deref()).await?;
|
|
Ok(target.join(name))
|
|
}
|
|
Scheme::File { path } => file::fetch_file(&path, name, target).await,
|
|
}
|
|
}
|