feat: add support for meta plugin options and outputs
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -11,6 +11,7 @@ pub struct DigestSha256MetaPlugin {
|
||||
meta_name: String,
|
||||
item_id: Option<i64>,
|
||||
conn: Option<*mut Connection>,
|
||||
output_name: Option<String>,
|
||||
}
|
||||
|
||||
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<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()) {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ pub struct MagicFileMetaPlugin {
|
||||
item_id: Option<i64>,
|
||||
conn: Option<*mut Connection>,
|
||||
cookie: Option<Cookie>,
|
||||
output_names: std::collections::HashMap<String, String>,
|
||||
}
|
||||
|
||||
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<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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ pub struct BinaryMetaPlugin {
|
||||
is_saved: bool,
|
||||
item_id: Option<i64>,
|
||||
conn: Option<*mut Connection>,
|
||||
output_name: Option<String>,
|
||||
}
|
||||
|
||||
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<String, serde_yaml::Value>) -> 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 {
|
||||
|
||||
Reference in New Issue
Block a user