Refactor sidecars
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use mime::Mime;
|
||||
use pile_config::Label;
|
||||
use smartstring::{LazyCompact, SmartString};
|
||||
use std::{fs::File, path::PathBuf, sync::Arc};
|
||||
use std::{collections::HashMap, fs::File, path::PathBuf, sync::Arc};
|
||||
|
||||
use crate::{
|
||||
source::{DirDataSource, S3DataSource},
|
||||
@@ -19,7 +20,7 @@ pub enum Item {
|
||||
mime: Mime,
|
||||
|
||||
path: PathBuf,
|
||||
sidecar: Option<Box<Item>>,
|
||||
group: Arc<HashMap<Label, Box<Item>>>,
|
||||
},
|
||||
|
||||
S3 {
|
||||
@@ -27,7 +28,7 @@ pub enum Item {
|
||||
mime: Mime,
|
||||
|
||||
key: SmartString<LazyCompact>,
|
||||
sidecar: Option<Box<Item>>,
|
||||
group: Arc<HashMap<Label, Box<Item>>>,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -71,7 +72,12 @@ impl Item {
|
||||
#[expect(clippy::expect_used)]
|
||||
pub fn key(&self) -> SmartString<LazyCompact> {
|
||||
match self {
|
||||
Self::File { path, .. } => path.to_str().expect("path is not utf-8").into(),
|
||||
Self::File { source, path, .. } => path
|
||||
.strip_prefix(&source.dir)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.expect("path is not utf-8")
|
||||
.into(),
|
||||
Self::S3 { key, .. } => key.clone(),
|
||||
}
|
||||
}
|
||||
@@ -96,10 +102,10 @@ impl Item {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sidecar(&self) -> Option<&Self> {
|
||||
pub fn group(&self) -> &HashMap<Label, Box<Self>> {
|
||||
match self {
|
||||
Self::File { sidecar, .. } => sidecar.as_ref().map(|x| &**x),
|
||||
Self::S3 { sidecar, .. } => sidecar.as_ref().map(|x| &**x),
|
||||
Self::File { group, .. } => group,
|
||||
Self::S3 { group, .. } => group,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user