diff --git a/src/meta_plugin.rs b/src/meta_plugin.rs index 0e8b9f8..a9c69ff 100644 --- a/src/meta_plugin.rs +++ b/src/meta_plugin.rs @@ -41,12 +41,33 @@ pub enum MetaPluginType { } /// Central function to handle metadata output with name mapping -pub fn output_metadata(conn: &Connection, item_id: i64, name: &str, value: String, output_names: &std::collections::HashMap) -> Result<()> { - let output_name = output_names.get(name).cloned().unwrap_or_else(|| name.to_string()); - debug!("META: Saving metadata: item_id={}, name={}, value={}", item_id, output_name, value); +/// outputs: HashMap where key is internal name, value is either custom name or "false" to disable +pub fn output_metadata(conn: &Connection, item_id: i64, internal_name: &str, value: String, outputs: &std::collections::HashMap) -> Result<()> { + // Check if this output is disabled + if let Some(mapping) = outputs.get(internal_name) { + if let Some(false_val) = mapping.as_bool() { + if !false_val { + debug!("META: Skipping disabled output: {}", internal_name); + return Ok(()); + } + } + if let Some(custom_name) = mapping.as_str() { + debug!("META: Saving metadata: item_id={}, internal_name={}, custom_name={}, value={}", item_id, internal_name, custom_name, value); + let meta = crate::db::Meta { + id: item_id, + name: custom_name.to_string(), + value, + }; + crate::db::store_meta(conn, meta)?; + return Ok(()); + } + } + + // Default: use internal name as output name + debug!("META: Saving metadata: item_id={}, name={}, value={}", item_id, internal_name, value); let meta = crate::db::Meta { id: item_id, - name: output_name, + name: internal_name.to_string(), value, }; crate::db::store_meta(conn, meta)?; @@ -80,21 +101,20 @@ pub trait MetaPlugin { } // Save metadata to database using central output handler - fn save_meta(&mut self, conn: &Connection, item_id: i64, value: String) -> Result<()> { - let meta_name = self.meta_name(); - // Default implementation: no output name mapping - output_metadata(conn, item_id, &meta_name, value, &std::collections::HashMap::new()) + fn save_meta(&mut self, conn: &Connection, item_id: i64, internal_name: &str, value: String) -> Result<()> { + output_metadata(conn, item_id, internal_name, value, self.get_outputs()) } - // Configure plugin with options + // Configure plugin with options and outputs 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() - } + // Get outputs mapping + fn get_outputs(&self) -> &std::collections::HashMap; + + // Set outputs mapping + fn set_outputs(&mut self, outputs: std::collections::HashMap); } pub fn get_meta_plugin(meta_plugin_type: MetaPluginType) -> Box { diff --git a/src/meta_plugin/binary.rs b/src/meta_plugin/binary.rs index dec68cf..2ff70ed 100644 --- a/src/meta_plugin/binary.rs +++ b/src/meta_plugin/binary.rs @@ -11,7 +11,7 @@ pub struct BinaryMetaPlugin { max_buffer_size: usize, is_saved: bool, item_id: Option, - output_names: std::collections::HashMap, + outputs: std::collections::HashMap, } impl BinaryMetaPlugin { @@ -22,7 +22,7 @@ impl BinaryMetaPlugin { max_buffer_size: 4096, // 4KB is_saved: false, item_id: None, - output_names: std::collections::HashMap::new(), + outputs: std::collections::HashMap::new(), } } @@ -33,7 +33,7 @@ impl BinaryMetaPlugin { let value = if is_binary_result { "true".to_string() } else { "false".to_string() }; // Save to database immediately using central output handler - let _ = output_metadata(conn, item_id, &self.meta_name, value, &self.output_names); + let _ = self.save_meta(conn, item_id, "binary", value); self.is_saved = true; } @@ -93,8 +93,8 @@ impl MetaPlugin for BinaryMetaPlugin { 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(key_str) = key.as_str() { + self.outputs.insert(key_str.to_string(), value.clone()); } } } @@ -102,7 +102,11 @@ impl MetaPlugin for BinaryMetaPlugin { Ok(()) } - fn get_output_name(&self, default_name: &str) -> String { - self.output_names.get(default_name).cloned().unwrap_or_else(|| default_name.to_string()) + fn get_outputs(&self) -> &std::collections::HashMap { + &self.outputs + } + + fn set_outputs(&mut self, outputs: std::collections::HashMap) { + self.outputs = outputs; } } diff --git a/src/meta_plugin/digest.rs b/src/meta_plugin/digest.rs index 5ecf8dd..5da7c01 100644 --- a/src/meta_plugin/digest.rs +++ b/src/meta_plugin/digest.rs @@ -10,7 +10,7 @@ pub struct DigestSha256MetaPlugin { hasher: Sha256, meta_name: String, item_id: Option, - output_names: std::collections::HashMap, + outputs: std::collections::HashMap, } impl DigestSha256MetaPlugin { @@ -19,7 +19,7 @@ impl DigestSha256MetaPlugin { hasher: Sha256::new(), meta_name: "digest_sha256".to_string(), item_id: None, - output_names: std::collections::HashMap::new(), + outputs: std::collections::HashMap::new(), } } } @@ -41,7 +41,7 @@ impl MetaPlugin for DigestSha256MetaPlugin { let hex_string = format!("{:x}", hash_result); // Save the hash as metadata using central output handler - let _ = output_metadata(conn, item_id, &self.meta_name, hex_string, &self.output_names); + let _ = self.save_meta(conn, item_id, "digest_sha256", hex_string); } Ok(()) } @@ -58,8 +58,8 @@ impl MetaPlugin for DigestSha256MetaPlugin { 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(key_str) = key.as_str() { + self.outputs.insert(key_str.to_string(), value.clone()); } } } @@ -67,8 +67,12 @@ impl MetaPlugin for DigestSha256MetaPlugin { Ok(()) } - fn get_output_name(&self, default_name: &str) -> String { - self.output_names.get(default_name).cloned().unwrap_or_else(|| default_name.to_string()) + fn get_outputs(&self) -> &std::collections::HashMap { + &self.outputs + } + + fn set_outputs(&mut self, outputs: std::collections::HashMap) { + self.outputs = outputs; } } @@ -77,6 +81,7 @@ impl MetaPlugin for DigestSha256MetaPlugin { pub struct ReadTimeMetaPlugin { start_time: Option, meta_name: String, + outputs: std::collections::HashMap, } impl ReadTimeMetaPlugin { @@ -84,6 +89,7 @@ impl ReadTimeMetaPlugin { ReadTimeMetaPlugin { start_time: None, meta_name: "read_time".to_string(), + outputs: std::collections::HashMap::new(), } } } @@ -106,6 +112,27 @@ impl MetaPlugin for ReadTimeMetaPlugin { 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) = key.as_str() { + self.outputs.insert(key_str.to_string(), value.clone()); + } + } + } + } + Ok(()) + } + + fn get_outputs(&self) -> &std::collections::HashMap { + &self.outputs + } + + fn set_outputs(&mut self, outputs: std::collections::HashMap) { + self.outputs = outputs; + } } #[derive(Debug, Clone, Default)] @@ -113,6 +140,7 @@ pub struct ReadRateMetaPlugin { start_time: Option, bytes_read: u64, meta_name: String, + outputs: std::collections::HashMap, } impl ReadRateMetaPlugin { @@ -121,6 +149,7 @@ impl ReadRateMetaPlugin { start_time: None, bytes_read: 0, meta_name: "read_rate".to_string(), + outputs: std::collections::HashMap::new(), } } } @@ -144,4 +173,25 @@ impl MetaPlugin for ReadRateMetaPlugin { 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) = key.as_str() { + self.outputs.insert(key_str.to_string(), value.clone()); + } + } + } + } + Ok(()) + } + + fn get_outputs(&self) -> &std::collections::HashMap { + &self.outputs + } + + fn set_outputs(&mut self, outputs: std::collections::HashMap) { + self.outputs = outputs; + } } diff --git a/src/meta_plugin/magic.rs b/src/meta_plugin/magic.rs index 5707cb7..ee1d8a4 100644 --- a/src/meta_plugin/magic.rs +++ b/src/meta_plugin/magic.rs @@ -12,7 +12,7 @@ pub struct MagicFileMetaPlugin { is_saved: bool, item_id: Option, cookie: Option, - output_names: std::collections::HashMap, + outputs: std::collections::HashMap, } impl MagicFileMetaPlugin { @@ -23,7 +23,7 @@ impl MagicFileMetaPlugin { is_saved: false, item_id: None, cookie: None, - output_names: std::collections::HashMap::new(), + outputs: std::collections::HashMap::new(), } } @@ -56,10 +56,22 @@ impl MagicFileMetaPlugin { fn save_all_magic_metadata(&mut self, conn: &Connection) -> Result<()> { if let Some(item_id) = self.item_id { - // Only save MIME type since that's what's mapped in the config + // Save all three magic outputs: mime_type, mime_encoding, and file_type if let Ok(mime_type) = self.get_magic_result(CookieFlags::MIME_TYPE) { if !mime_type.is_empty() { - let _ = output_metadata(conn, item_id, "mime_type", mime_type, &self.output_names); + let _ = self.save_meta(conn, item_id, "mime_type", mime_type); + } + } + + if let Ok(mime_encoding) = self.get_magic_result(CookieFlags::MIME_ENCODING) { + if !mime_encoding.is_empty() { + let _ = self.save_meta(conn, item_id, "mime_encoding", mime_encoding); + } + } + + if let Ok(file_type) = self.get_magic_result(CookieFlags::default()) { + if !file_type.is_empty() { + let _ = self.save_meta(conn, item_id, "file_type", file_type); } } @@ -121,8 +133,8 @@ impl MetaPlugin for MagicFileMetaPlugin { 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(key_str) = key.as_str() { + self.outputs.insert(key_str.to_string(), value.clone()); } } } @@ -137,8 +149,12 @@ impl MetaPlugin for MagicFileMetaPlugin { Ok(()) } - fn get_output_name(&self, default_name: &str) -> String { - self.output_names.get(default_name).cloned().unwrap_or_else(|| default_name.to_string()) + fn get_outputs(&self) -> &std::collections::HashMap { + &self.outputs + } + + fn set_outputs(&mut self, outputs: std::collections::HashMap) { + self.outputs = outputs; } } diff --git a/src/meta_plugin/program.rs b/src/meta_plugin/program.rs index d2bb034..09b5681 100644 --- a/src/meta_plugin/program.rs +++ b/src/meta_plugin/program.rs @@ -17,6 +17,7 @@ pub struct MetaPluginProgram { writer: Option>, item_id: Option, result: Option, + outputs: std::collections::HashMap, } impl std::fmt::Debug for MetaPluginProgram { @@ -29,6 +30,7 @@ impl std::fmt::Debug for MetaPluginProgram { .field("split_whitespace", &self.split_whitespace) .field("process", &self.process) .field("writer", &"Box") + .field("outputs", &self.outputs) .finish() } } @@ -48,6 +50,7 @@ impl MetaPluginProgram { writer: None, item_id: None, result: None, + outputs: std::collections::HashMap::new(), } } } @@ -115,12 +118,7 @@ impl MetaPlugin for MetaPluginProgram { // Save the result to database if we have item_id if let Some(item_id) = self.item_id { - let meta = crate::db::Meta { - id: item_id, - name: self.meta_name.clone(), - value: self.result.clone().unwrap(), - }; - let _ = crate::db::store_meta(conn, meta); + let _ = self.save_meta(conn, item_id, &self.meta_name.clone(), self.result.clone().unwrap()); } } } else { @@ -153,4 +151,25 @@ impl MetaPlugin for MetaPluginProgram { None } } + + 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) = key.as_str() { + self.outputs.insert(key_str.to_string(), value.clone()); + } + } + } + } + Ok(()) + } + + fn get_outputs(&self) -> &std::collections::HashMap { + &self.outputs + } + + fn set_outputs(&mut self, outputs: std::collections::HashMap) { + self.outputs = outputs; + } } diff --git a/src/meta_plugin/system.rs b/src/meta_plugin/system.rs index f38967f..a6cf4fc 100644 --- a/src/meta_plugin/system.rs +++ b/src/meta_plugin/system.rs @@ -13,7 +13,7 @@ use crate::meta_plugin::{MetaPlugin, output_metadata}; pub struct CwdMetaPlugin { meta_name: String, is_saved: bool, - output_names: std::collections::HashMap, + outputs: std::collections::HashMap, } impl CwdMetaPlugin { @@ -21,7 +21,7 @@ impl CwdMetaPlugin { CwdMetaPlugin { meta_name: "cwd".to_string(), is_saved: false, - output_names: std::collections::HashMap::new(), + outputs: std::collections::HashMap::new(), } } } @@ -50,7 +50,7 @@ impl MetaPlugin for CwdMetaPlugin { Err(_) => "unknown".to_string(), }; // Use central output handler - output_metadata(conn, item_id, &self.meta_name, cwd, &self.output_names)?; + self.save_meta(conn, item_id, "cwd", cwd)?; self.is_saved = true; Ok(()) } @@ -59,8 +59,8 @@ impl MetaPlugin for CwdMetaPlugin { 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(key_str) = key.as_str() { + self.outputs.insert(key_str.to_string(), value.clone()); } } } @@ -68,8 +68,12 @@ impl MetaPlugin for CwdMetaPlugin { Ok(()) } - fn get_output_name(&self, default_name: &str) -> String { - self.output_names.get(default_name).cloned().unwrap_or_else(|| default_name.to_string()) + fn get_outputs(&self) -> &std::collections::HashMap { + &self.outputs + } + + fn set_outputs(&mut self, outputs: std::collections::HashMap) { + self.outputs = outputs; } } @@ -77,6 +81,7 @@ impl MetaPlugin for CwdMetaPlugin { pub struct UidMetaPlugin { meta_name: String, is_saved: bool, + outputs: std::collections::HashMap, } impl UidMetaPlugin { @@ -84,6 +89,7 @@ impl UidMetaPlugin { UidMetaPlugin { meta_name: "uid".to_string(), is_saved: false, + outputs: std::collections::HashMap::new(), } } } @@ -108,16 +114,38 @@ impl MetaPlugin for UidMetaPlugin { fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> { let uid = get_current_uid().to_string(); - self.save_meta(conn, item_id, uid)?; + self.save_meta(conn, item_id, "uid", uid)?; self.is_saved = true; Ok(()) } + + 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) = key.as_str() { + self.outputs.insert(key_str.to_string(), value.clone()); + } + } + } + } + Ok(()) + } + + fn get_outputs(&self) -> &std::collections::HashMap { + &self.outputs + } + + fn set_outputs(&mut self, outputs: std::collections::HashMap) { + self.outputs = outputs; + } } #[derive(Debug, Clone, Default)] pub struct UserMetaPlugin { meta_name: String, is_saved: bool, + outputs: std::collections::HashMap, } impl UserMetaPlugin { @@ -125,6 +153,7 @@ impl UserMetaPlugin { UserMetaPlugin { meta_name: "user".to_string(), is_saved: false, + outputs: std::collections::HashMap::new(), } } } @@ -152,16 +181,38 @@ impl MetaPlugin for UserMetaPlugin { Some(username) => username.to_string_lossy().to_string(), None => "unknown".to_string(), }; - self.save_meta(conn, item_id, user)?; + self.save_meta(conn, item_id, "user", user)?; self.is_saved = true; Ok(()) } + + 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) = key.as_str() { + self.outputs.insert(key_str.to_string(), value.clone()); + } + } + } + } + Ok(()) + } + + fn get_outputs(&self) -> &std::collections::HashMap { + &self.outputs + } + + fn set_outputs(&mut self, outputs: std::collections::HashMap) { + self.outputs = outputs; + } } #[derive(Debug, Clone, Default)] pub struct GidMetaPlugin { meta_name: String, is_saved: bool, + outputs: std::collections::HashMap, } impl GidMetaPlugin { @@ -169,6 +220,7 @@ impl GidMetaPlugin { GidMetaPlugin { meta_name: "gid".to_string(), is_saved: false, + outputs: std::collections::HashMap::new(), } } } @@ -193,16 +245,38 @@ impl MetaPlugin for GidMetaPlugin { fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> { let gid = get_current_gid().to_string(); - self.save_meta(conn, item_id, gid)?; + self.save_meta(conn, item_id, "gid", gid)?; self.is_saved = true; Ok(()) } + + 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) = key.as_str() { + self.outputs.insert(key_str.to_string(), value.clone()); + } + } + } + } + Ok(()) + } + + fn get_outputs(&self) -> &std::collections::HashMap { + &self.outputs + } + + fn set_outputs(&mut self, outputs: std::collections::HashMap) { + self.outputs = outputs; + } } #[derive(Debug, Clone, Default)] pub struct GroupMetaPlugin { meta_name: String, is_saved: bool, + outputs: std::collections::HashMap, } impl GroupMetaPlugin { @@ -210,6 +284,7 @@ impl GroupMetaPlugin { GroupMetaPlugin { meta_name: "group".to_string(), is_saved: false, + outputs: std::collections::HashMap::new(), } } } @@ -237,16 +312,38 @@ impl MetaPlugin for GroupMetaPlugin { Some(groupname) => groupname.to_string_lossy().to_string(), None => "unknown".to_string(), }; - self.save_meta(conn, item_id, group)?; + self.save_meta(conn, item_id, "group", group)?; self.is_saved = true; Ok(()) } + + 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) = key.as_str() { + self.outputs.insert(key_str.to_string(), value.clone()); + } + } + } + } + Ok(()) + } + + fn get_outputs(&self) -> &std::collections::HashMap { + &self.outputs + } + + fn set_outputs(&mut self, outputs: std::collections::HashMap) { + self.outputs = outputs; + } } #[derive(Debug, Clone, Default)] pub struct ShellMetaPlugin { meta_name: String, is_saved: bool, + outputs: std::collections::HashMap, } impl ShellMetaPlugin { @@ -254,6 +351,7 @@ impl ShellMetaPlugin { ShellMetaPlugin { meta_name: "shell".to_string(), is_saved: false, + outputs: std::collections::HashMap::new(), } } } @@ -281,16 +379,38 @@ impl MetaPlugin for ShellMetaPlugin { Ok(shell) => shell, Err(_) => "unknown".to_string(), }; - self.save_meta(conn, item_id, shell)?; + self.save_meta(conn, item_id, "shell", shell)?; self.is_saved = true; Ok(()) } + + 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) = key.as_str() { + self.outputs.insert(key_str.to_string(), value.clone()); + } + } + } + } + Ok(()) + } + + fn get_outputs(&self) -> &std::collections::HashMap { + &self.outputs + } + + fn set_outputs(&mut self, outputs: std::collections::HashMap) { + self.outputs = outputs; + } } #[derive(Debug, Clone, Default)] pub struct ShellPidMetaPlugin { meta_name: String, is_saved: bool, + outputs: std::collections::HashMap, } impl ShellPidMetaPlugin { @@ -298,6 +418,7 @@ impl ShellPidMetaPlugin { ShellPidMetaPlugin { meta_name: "shell_pid".to_string(), is_saved: false, + outputs: std::collections::HashMap::new(), } } } @@ -325,16 +446,38 @@ impl MetaPlugin for ShellPidMetaPlugin { Ok(ppid) => ppid, Err(_) => process::id().to_string(), }; - self.save_meta(conn, item_id, pid)?; + self.save_meta(conn, item_id, "shell_pid", pid)?; self.is_saved = true; Ok(()) } + + 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) = key.as_str() { + self.outputs.insert(key_str.to_string(), value.clone()); + } + } + } + } + Ok(()) + } + + fn get_outputs(&self) -> &std::collections::HashMap { + &self.outputs + } + + fn set_outputs(&mut self, outputs: std::collections::HashMap) { + self.outputs = outputs; + } } #[derive(Debug, Clone, Default)] pub struct KeepPidMetaPlugin { meta_name: String, is_saved: bool, + outputs: std::collections::HashMap, } impl KeepPidMetaPlugin { @@ -342,6 +485,7 @@ impl KeepPidMetaPlugin { KeepPidMetaPlugin { meta_name: "keep_pid".to_string(), is_saved: false, + outputs: std::collections::HashMap::new(), } } } @@ -366,16 +510,38 @@ impl MetaPlugin for KeepPidMetaPlugin { fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> { let pid = process::id().to_string(); - self.save_meta(conn, item_id, pid)?; + self.save_meta(conn, item_id, "keep_pid", pid)?; self.is_saved = true; Ok(()) } + + 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) = key.as_str() { + self.outputs.insert(key_str.to_string(), value.clone()); + } + } + } + } + Ok(()) + } + + fn get_outputs(&self) -> &std::collections::HashMap { + &self.outputs + } + + fn set_outputs(&mut self, outputs: std::collections::HashMap) { + self.outputs = outputs; + } } #[derive(Debug, Clone, Default)] pub struct HostnameMetaPlugin { meta_name: String, is_saved: bool, + outputs: std::collections::HashMap, } impl HostnameMetaPlugin { @@ -383,6 +549,7 @@ impl HostnameMetaPlugin { HostnameMetaPlugin { meta_name: "hostname".to_string(), is_saved: false, + outputs: std::collections::HashMap::new(), } } } @@ -410,16 +577,38 @@ impl MetaPlugin for HostnameMetaPlugin { Ok(hostname) => hostname, Err(_) => "unknown".to_string(), }; - self.save_meta(conn, item_id, hostname)?; + self.save_meta(conn, item_id, "hostname", hostname)?; self.is_saved = true; Ok(()) } + + 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) = key.as_str() { + self.outputs.insert(key_str.to_string(), value.clone()); + } + } + } + } + Ok(()) + } + + fn get_outputs(&self) -> &std::collections::HashMap { + &self.outputs + } + + fn set_outputs(&mut self, outputs: std::collections::HashMap) { + self.outputs = outputs; + } } #[derive(Debug, Clone, Default)] pub struct FullHostnameMetaPlugin { meta_name: String, is_saved: bool, + outputs: std::collections::HashMap, } impl FullHostnameMetaPlugin { @@ -427,6 +616,7 @@ impl FullHostnameMetaPlugin { FullHostnameMetaPlugin { meta_name: "full_hostname".to_string(), is_saved: false, + outputs: std::collections::HashMap::new(), } } } @@ -472,8 +662,29 @@ impl MetaPlugin for FullHostnameMetaPlugin { } } }; - self.save_meta(conn, item_id, hostname)?; + self.save_meta(conn, item_id, "full_hostname", hostname)?; self.is_saved = true; Ok(()) } + + 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) = key.as_str() { + self.outputs.insert(key_str.to_string(), value.clone()); + } + } + } + } + Ok(()) + } + + fn get_outputs(&self) -> &std::collections::HashMap { + &self.outputs + } + + fn set_outputs(&mut self, outputs: std::collections::HashMap) { + self.outputs = outputs; + } } diff --git a/src/modes/save.rs b/src/modes/save.rs index 9beb0bd..fd0ec28 100644 --- a/src/modes/save.rs +++ b/src/modes/save.rs @@ -42,11 +42,19 @@ fn setup_compression_and_plugins( .map(|meta_plugin_type| crate::meta_plugin::get_meta_plugin(meta_plugin_type.clone())) .collect(); - // Configure meta plugins with their options from settings + // Configure meta plugins with their options and outputs from settings if let Some(meta_plugin_configs) = &settings.meta_plugins { for meta_plugin in meta_plugins.iter_mut() { let plugin_name = meta_plugin.meta_name(); if let Some(config) = meta_plugin_configs.iter().find(|c| c.name == plugin_name) { + // Set outputs first + let mut outputs = std::collections::HashMap::new(); + for (key, value) in &config.outputs { + outputs.insert(key.clone(), serde_yaml::Value::String(value.clone())); + } + meta_plugin.set_outputs(outputs); + + // Then configure with options if let Err(e) = meta_plugin.configure(&config.options) { eprintln!("Warning: Failed to configure meta plugin '{}': {}", plugin_name, e); }