feat: add central metadata output handler

Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-18 10:51:58 -03:00
parent ecd3e316c5
commit 7f28129c00
4 changed files with 64 additions and 54 deletions

View File

@@ -8,12 +8,13 @@ use uzers::{get_current_uid, get_current_gid, get_current_username, get_current_
use rusqlite::Connection;
use crate::common::is_binary::is_binary;
use crate::meta_plugin::MetaPlugin;
use crate::meta_plugin::{MetaPlugin, output_metadata};
#[derive(Debug, Clone, Default)]
pub struct CwdMetaPlugin {
meta_name: String,
is_saved: bool,
output_names: std::collections::HashMap<String, String>,
}
#[derive(Debug, Clone, Default)]
@@ -24,7 +25,7 @@ pub struct BinaryMetaPlugin {
is_saved: bool,
item_id: Option<i64>,
conn: Option<*mut Connection>,
output_name: Option<String>,
output_names: std::collections::HashMap<String, String>,
}
impl BinaryMetaPlugin {
@@ -36,7 +37,7 @@ impl BinaryMetaPlugin {
is_saved: false,
item_id: None,
conn: None,
output_name: None,
output_names: std::collections::HashMap::new(),
}
}
@@ -67,13 +68,8 @@ impl MetaPlugin for BinaryMetaPlugin {
let is_binary = is_binary(&self.buffer);
let value = if is_binary { "true".to_string() } else { "false".to_string() };
// Save to database immediately
let meta = crate::db::Meta {
id: item_id,
name: self.get_output_name(&self.meta_name),
value,
};
let _ = crate::db::store_meta(conn_ref, meta);
// Save to database immediately using central output handler
let _ = output_metadata(conn_ref, item_id, &self.meta_name, value, &self.output_names);
self.is_saved = true;
}
@@ -98,11 +94,21 @@ impl MetaPlugin for BinaryMetaPlugin {
self.max_buffer_size = size as usize;
}
}
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());
}
}
}
}
Ok(())
}
fn get_output_name(&self, default_name: &str) -> String {
self.output_name.clone().unwrap_or_else(|| default_name.to_string())
self.output_names.get(default_name).cloned().unwrap_or_else(|| default_name.to_string())
}
}
@@ -111,6 +117,7 @@ impl CwdMetaPlugin {
CwdMetaPlugin {
meta_name: "cwd".to_string(),
is_saved: false,
output_names: std::collections::HashMap::new(),
}
}
}
@@ -138,10 +145,28 @@ impl MetaPlugin for CwdMetaPlugin {
Ok(path) => path.to_string_lossy().to_string(),
Err(_) => "unknown".to_string(),
};
self.save_meta(conn, item_id, cwd)?;
// Use central output handler
output_metadata(conn, item_id, &self.meta_name, cwd, &self.output_names)?;
self.is_saved = true;
Ok(())
}
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> 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());
}
}
}
}
Ok(())
}
fn get_output_name(&self, default_name: &str) -> String {
self.output_names.get(default_name).cloned().unwrap_or_else(|| default_name.to_string())
}
}
#[derive(Debug, Clone, Default)]