From 592c277735125a902cdf1d1180c7a8653673a1a8 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Mon, 18 Aug 2025 10:07:51 -0300 Subject: [PATCH] feat: add support for meta plugin options and outputs Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) --- src/config.rs | 4 ++++ src/meta_plugin.rs | 10 ++++++++++ src/meta_plugin/digest.rs | 23 ++++++++++++++++++++++- src/meta_plugin/magic.rs | 32 +++++++++++++++++++++++++++++--- src/meta_plugin/system.rs | 16 +++++++++++++++- 5 files changed, 80 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index 8ca82e1..7e7c530 100644 --- a/src/config.rs +++ b/src/config.rs @@ -62,6 +62,10 @@ pub struct CompressionPluginConfig { #[derive(Debug, Clone, Deserialize, Serialize)] pub struct MetaPluginConfig { pub name: String, + #[serde(default)] + pub options: std::collections::HashMap, + #[serde(default)] + pub outputs: std::collections::HashMap, } /// Unified settings that merges config file and CLI arguments diff --git a/src/meta_plugin.rs b/src/meta_plugin.rs index 52b5582..17bc624 100644 --- a/src/meta_plugin.rs +++ b/src/meta_plugin.rs @@ -76,6 +76,16 @@ pub trait MetaPlugin { crate::db::store_meta(conn, meta)?; Ok(()) } + + // Configure plugin with options + fn configure(&mut self, _options: &std::collections::HashMap) -> Result<()> { + Ok(()) + } + + // Get output name mapping + fn get_output_name(&self, default_name: &str) -> String { + default_name.to_string() + } } pub fn get_meta_plugin(meta_plugin_type: MetaPluginType) -> Box { diff --git a/src/meta_plugin/digest.rs b/src/meta_plugin/digest.rs index f2586c1..d5bdbf7 100644 --- a/src/meta_plugin/digest.rs +++ b/src/meta_plugin/digest.rs @@ -11,6 +11,7 @@ pub struct DigestSha256MetaPlugin { meta_name: String, item_id: Option, conn: Option<*mut Connection>, + output_name: Option, } impl DigestSha256MetaPlugin { @@ -20,6 +21,7 @@ impl DigestSha256MetaPlugin { meta_name: "digest_sha256".to_string(), item_id: None, conn: None, + output_name: None, } } } @@ -48,7 +50,7 @@ impl MetaPlugin for DigestSha256MetaPlugin { // Save the hash as metadata let meta = crate::db::Meta { id: item_id, - name: self.meta_name.clone(), + name: self.get_output_name(&self.meta_name), value: hex_string, }; crate::db::store_meta(conn_ref, meta)?; @@ -63,6 +65,25 @@ impl MetaPlugin for DigestSha256MetaPlugin { fn meta_name(&mut self) -> String { self.meta_name.clone() } + + fn configure(&mut self, options: &std::collections::HashMap) -> Result<()> { + if let Some(outputs) = options.get("outputs") { + if let Some(outputs_map) = outputs.as_mapping() { + for (key, value) in outputs_map { + if let (Some(key_str), Some(value_str)) = (key.as_str(), value.as_str()) { + if key_str == "digest_sha256" { + self.output_name = Some(value_str.to_string()); + } + } + } + } + } + Ok(()) + } + + fn get_output_name(&self, default_name: &str) -> String { + self.output_name.clone().unwrap_or_else(|| default_name.to_string()) + } } diff --git a/src/meta_plugin/magic.rs b/src/meta_plugin/magic.rs index 0a4251a..7e1a517 100644 --- a/src/meta_plugin/magic.rs +++ b/src/meta_plugin/magic.rs @@ -13,6 +13,7 @@ pub struct MagicFileMetaPlugin { item_id: Option, conn: Option<*mut Connection>, cookie: Option, + output_names: std::collections::HashMap, } impl MagicFileMetaPlugin { @@ -24,6 +25,7 @@ impl MagicFileMetaPlugin { item_id: None, conn: None, cookie: None, + output_names: std::collections::HashMap::new(), } } @@ -64,7 +66,7 @@ impl MagicFileMetaPlugin { if !file_type.is_empty() { let meta = crate::db::Meta { id: item_id, - name: "file_type".to_string(), + name: self.get_output_name("file_type"), value: file_type, }; let _ = crate::db::store_meta(conn_ref, meta); @@ -76,7 +78,7 @@ impl MagicFileMetaPlugin { if !mime_type.is_empty() { let meta = crate::db::Meta { id: item_id, - name: "mime_type".to_string(), + name: self.get_output_name("mime_type"), value: mime_type, }; let _ = crate::db::store_meta(conn_ref, meta); @@ -88,7 +90,7 @@ impl MagicFileMetaPlugin { if !mime_encoding.is_empty() { let meta = crate::db::Meta { id: item_id, - name: "mime_encoding".to_string(), + name: self.get_output_name("mime_encoding"), value: mime_encoding, }; let _ = crate::db::store_meta(conn_ref, meta); @@ -150,5 +152,29 @@ impl MetaPlugin for MagicFileMetaPlugin { fn meta_name(&mut self) -> String { "magic_file".to_string() } + + fn configure(&mut self, options: &std::collections::HashMap) -> Result<()> { + if let Some(outputs) = options.get("outputs") { + if let Some(outputs_map) = outputs.as_mapping() { + for (key, value) in outputs_map { + if let (Some(key_str), Some(value_str)) = (key.as_str(), value.as_str()) { + self.output_names.insert(key_str.to_string(), value_str.to_string()); + } + } + } + } + + if let Some(max_buffer_size) = options.get("max_buffer_size") { + if let Ok(size) = max_buffer_size.as_u64() { + self.max_buffer_size = size as usize; + } + } + + Ok(()) + } + + fn get_output_name(&self, default_name: &str) -> String { + self.output_names.get(default_name).cloned().unwrap_or_else(|| default_name.to_string()) + } } diff --git a/src/meta_plugin/system.rs b/src/meta_plugin/system.rs index 543eba5..cfce618 100644 --- a/src/meta_plugin/system.rs +++ b/src/meta_plugin/system.rs @@ -25,6 +25,7 @@ pub struct BinaryMetaPlugin { is_saved: bool, item_id: Option, conn: Option<*mut Connection>, + output_name: Option, } impl BinaryMetaPlugin { @@ -36,6 +37,7 @@ impl BinaryMetaPlugin { is_saved: false, item_id: None, conn: None, + output_name: None, } } @@ -69,7 +71,7 @@ impl MetaPlugin for BinaryMetaPlugin { // Save to database immediately let meta = crate::db::Meta { id: item_id, - name: self.meta_name.clone(), + name: self.get_output_name(&self.meta_name), value, }; let _ = crate::db::store_meta(conn_ref, meta); @@ -91,6 +93,18 @@ impl MetaPlugin for BinaryMetaPlugin { Ok(()) } + fn configure(&mut self, options: &std::collections::HashMap) -> Result<()> { + if let Some(max_buffer_size) = options.get("max_buffer_size") { + if let Ok(size) = max_buffer_size.as_u64() { + self.max_buffer_size = size as usize; + } + } + Ok(()) + } + + fn get_output_name(&self, default_name: &str) -> String { + self.output_name.clone().unwrap_or_else(|| default_name.to_string()) + } } impl CwdMetaPlugin {