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

@@ -3,7 +3,7 @@ use sha2::{Digest, Sha256};
use std::time::Instant;
use rusqlite::Connection;
use crate::meta_plugin::MetaPlugin;
use crate::meta_plugin::{MetaPlugin, output_metadata};
#[derive(Debug, Clone, Default)]
pub struct DigestSha256MetaPlugin {
@@ -11,7 +11,7 @@ pub struct DigestSha256MetaPlugin {
meta_name: String,
item_id: Option<i64>,
conn: Option<*mut Connection>,
output_name: Option<String>,
output_names: std::collections::HashMap<String, String>,
}
impl DigestSha256MetaPlugin {
@@ -21,7 +21,7 @@ impl DigestSha256MetaPlugin {
meta_name: "digest_sha256".to_string(),
item_id: None,
conn: None,
output_name: None,
output_names: std::collections::HashMap::new(),
}
}
}
@@ -47,13 +47,8 @@ impl MetaPlugin for DigestSha256MetaPlugin {
let hash_result = self.hasher.finalize_reset();
let hex_string = format!("{:x}", hash_result);
// Save the hash as metadata
let meta = crate::db::Meta {
id: item_id,
name: self.get_output_name(&self.meta_name),
value: hex_string,
};
crate::db::store_meta(conn_ref, meta)?;
// Save the hash as metadata using central output handler
let _ = output_metadata(conn_ref, item_id, &self.meta_name, hex_string, &self.output_names);
}
Ok(())
}
@@ -71,9 +66,7 @@ impl MetaPlugin for DigestSha256MetaPlugin {
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());
}
self.output_names.insert(key_str.to_string(), value_str.to_string());
}
}
}
@@ -82,7 +75,7 @@ impl MetaPlugin for DigestSha256MetaPlugin {
}
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())
}
}