mod local_fs;
mod single_get;
use std::path::Path;
use crate::WyrdClient;
use wyrd_spec::storage::DownloadPlan;
use crate::storage::{DownloadProgressSink, error::StorageClientError};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DownloadOutcome {
pub bytes_written: u64,
}
pub(crate) async fn dispatch(
client: &WyrdClient,
plan: &DownloadPlan,
dest: &Path,
) -> Result<DownloadOutcome, StorageClientError> {
if plan.get_url.contains("/v1/cards/download/local?") {
local_fs::download(client, plan, dest).await
} else {
single_get::download(client, plan, dest).await
}
}
#[derive(Debug, Clone, Copy)]
pub(crate) struct DownloadVerification<'a> {
pub(crate) expected_sha256: &'a str,
pub(crate) expected_size_bytes: u64,
}
pub(crate) async fn dispatch_verified(
client: &WyrdClient,
plan: &DownloadPlan,
dest: &Path,
expected_sha256: &str,
expected_size_bytes: u64,
progress: DownloadProgressSink,
) -> Result<DownloadOutcome, StorageClientError> {
let verification = DownloadVerification {
expected_sha256,
expected_size_bytes,
};
if plan.get_url.contains("/v1/cards/download/local?") {
local_fs::download_verified(client, plan, dest, verification, &progress).await
} else {
single_get::download_verified(client, plan, dest, verification, &progress).await
}
}