refactor: update meta plugin to use output mappings
Co-authored-by: aider (openai/andrew/openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
This commit is contained in:
@@ -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<String, String>) -> 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<String, serde_yaml::Value>) -> 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<String, serde_yaml::Value>) -> 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<String, serde_yaml::Value>;
|
||||
|
||||
// Set outputs mapping
|
||||
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>);
|
||||
}
|
||||
|
||||
pub fn get_meta_plugin(meta_plugin_type: MetaPluginType) -> Box<dyn MetaPlugin> {
|
||||
|
||||
Reference in New Issue
Block a user