diff --git a/crates/pile-value/src/extract/item/epub/mod.rs b/crates/pile-value/src/extract/item/epub/mod.rs index ccf96a7..a67e4f4 100644 --- a/crates/pile-value/src/extract/item/epub/mod.rs +++ b/crates/pile-value/src/extract/item/epub/mod.rs @@ -54,4 +54,33 @@ impl ObjectExtractor for EpubExtractor { Label::new("meta").unwrap(), ]) } + + async fn to_json(&self, state: &ExtractState) -> Result { + let keys = self.fields().await?; + let mut map = serde_json::Map::new(); + for k in &keys { + let v = match self.field(state, k, None).await? { + Some(x) => x, + None => continue, + }; + + if k.as_str() == "text" { + map.insert( + k.to_string(), + serde_json::Value::String(format!( + " x.len(), + _ => 0, + } + )), + ); + continue; + } + + map.insert(k.to_string(), Box::pin(v.to_json(state)).await?); + } + + Ok(serde_json::Value::Object(map)) + } } diff --git a/crates/pile-value/src/extract/item/pdf/mod.rs b/crates/pile-value/src/extract/item/pdf/mod.rs index f603535..cdb23a4 100644 --- a/crates/pile-value/src/extract/item/pdf/mod.rs +++ b/crates/pile-value/src/extract/item/pdf/mod.rs @@ -68,4 +68,33 @@ impl ObjectExtractor for PdfExtractor { Label::new("pages").unwrap(), ]) } + + async fn to_json(&self, state: &ExtractState) -> Result { + let keys = self.fields().await?; + let mut map = serde_json::Map::new(); + for k in &keys { + let v = match self.field(state, k, None).await? { + Some(x) => x, + None => continue, + }; + + if k.as_str() == "text" { + map.insert( + k.to_string(), + serde_json::Value::String(format!( + " x.len(), + _ => 0, + } + )), + ); + continue; + } + + map.insert(k.to_string(), Box::pin(v.to_json(state)).await?); + } + + Ok(serde_json::Value::Object(map)) + } }