Extract epub covers

This commit is contained in:
2026-03-23 22:40:32 -07:00
parent 0792b2f2c6
commit d95ebeaba0
2 changed files with 95 additions and 0 deletions

View File

@@ -1,6 +1,9 @@
use pile_config::Label;
use std::sync::Arc;
mod epub_cover;
pub use epub_cover::*;
mod epub_meta;
pub use epub_meta::*;
@@ -15,6 +18,7 @@ use crate::{
pub struct EpubExtractor {
text: Arc<EpubTextExtractor>,
meta: Arc<EpubMetaExtractor>,
cover: Arc<EpubCoverExtractor>,
}
impl EpubExtractor {
@@ -22,6 +26,7 @@ impl EpubExtractor {
Self {
text: Arc::new(EpubTextExtractor::new(item)),
meta: Arc::new(EpubMetaExtractor::new(item)),
cover: Arc::new(EpubCoverExtractor::new(item)),
}
}
}
@@ -43,6 +48,7 @@ impl ObjectExtractor for EpubExtractor {
)),
("meta", None) => Ok(Some(PileValue::ObjectExtractor(self.meta.clone()))),
("cover", None) => self.cover.get(state).await,
_ => Ok(None),
}
}
@@ -52,6 +58,7 @@ impl ObjectExtractor for EpubExtractor {
Ok(vec![
Label::new("text").unwrap(),
Label::new("meta").unwrap(),
Label::new("cover").unwrap(),
])
}
@@ -78,6 +85,18 @@ impl ObjectExtractor for EpubExtractor {
continue;
}
if k.as_str() == "cover" {
let summary = match &v {
PileValue::Blob { mime, bytes } => {
format!("<Blob ({}, {} bytes)>", mime, bytes.len())
}
PileValue::Null => "<null>".to_owned(),
_ => "<cover>".to_owned(),
};
map.insert(k.to_string(), serde_json::Value::String(summary));
continue;
}
map.insert(k.to_string(), Box::pin(v.to_json(state)).await?);
}