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:
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user