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:
@@ -12,7 +12,7 @@ pub struct MagicFileMetaPlugin {
|
||||
is_saved: bool,
|
||||
item_id: Option<i64>,
|
||||
cookie: Option<Cookie>,
|
||||
output_names: std::collections::HashMap<String, String>,
|
||||
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||
}
|
||||
|
||||
impl MagicFileMetaPlugin {
|
||||
@@ -23,7 +23,7 @@ impl MagicFileMetaPlugin {
|
||||
is_saved: false,
|
||||
item_id: None,
|
||||
cookie: None,
|
||||
output_names: std::collections::HashMap::new(),
|
||||
outputs: std::collections::HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,10 +56,22 @@ impl MagicFileMetaPlugin {
|
||||
|
||||
fn save_all_magic_metadata(&mut self, conn: &Connection) -> Result<()> {
|
||||
if let Some(item_id) = self.item_id {
|
||||
// Only save MIME type since that's what's mapped in the config
|
||||
// Save all three magic outputs: mime_type, mime_encoding, and file_type
|
||||
if let Ok(mime_type) = self.get_magic_result(CookieFlags::MIME_TYPE) {
|
||||
if !mime_type.is_empty() {
|
||||
let _ = output_metadata(conn, item_id, "mime_type", mime_type, &self.output_names);
|
||||
let _ = self.save_meta(conn, item_id, "mime_type", mime_type);
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(mime_encoding) = self.get_magic_result(CookieFlags::MIME_ENCODING) {
|
||||
if !mime_encoding.is_empty() {
|
||||
let _ = self.save_meta(conn, item_id, "mime_encoding", mime_encoding);
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(file_type) = self.get_magic_result(CookieFlags::default()) {
|
||||
if !file_type.is_empty() {
|
||||
let _ = self.save_meta(conn, item_id, "file_type", file_type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,8 +133,8 @@ impl MetaPlugin for MagicFileMetaPlugin {
|
||||
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(key_str) = key.as_str() {
|
||||
self.outputs.insert(key_str.to_string(), value.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,8 +149,12 @@ impl MetaPlugin for MagicFileMetaPlugin {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_output_name(&self, default_name: &str) -> String {
|
||||
self.output_names.get(default_name).cloned().unwrap_or_else(|| default_name.to_string())
|
||||
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&self.outputs
|
||||
}
|
||||
|
||||
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||
self.outputs = outputs;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user