use std::path::Path;
use crate::ShunError;
use crate::config::{AttachmentConfig, ShunConfig};
use crate::flow::FlowEvent;
use crate::payload::ArchivePayload;
#[cfg(feature = "online")]
use crate::payload_online::OnlinePayload;
pub struct ResolvedAttachment {
pub config: AttachmentConfig,
pub included: bool,
}
pub fn resolve(config: &ShunConfig, payload: &ArchivePayload) -> Vec<ResolvedAttachment> {
config
.attachments
.iter()
.map(|config| ResolvedAttachment {
included: payload.has_prefix(&config.dest),
config: config.clone(),
})
.collect()
}
#[cfg(feature = "online")]
pub fn download(
attachment: &AttachmentConfig,
install_dir: &Path,
on_event: &mut dyn FnMut(FlowEvent),
) -> Result<(), ShunError> {
let dest = install_dir.join(&attachment.dest);
OnlinePayload::new(attachment.online.url.clone()).extract(&dest, on_event)
}