From 1e4e039672a83535e44dd559b4483f6978de962c Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Mon, 18 Aug 2025 08:47:04 -0300 Subject: [PATCH] feat: add combined mime info support and remove metadata filtering Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) --- src/meta_plugin/magic.rs | 56 ++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/src/meta_plugin/magic.rs b/src/meta_plugin/magic.rs index ec46ebe..3b2925a 100644 --- a/src/meta_plugin/magic.rs +++ b/src/meta_plugin/magic.rs @@ -60,32 +60,50 @@ impl MagicFileMetaPlugin { // Save file type if let Ok(file_type) = self.get_magic_result(CookieFlags::empty()) { - let meta = crate::db::Meta { - id: item_id, - name: "magic_file_type".to_string(), - value: file_type, - }; - let _ = crate::db::store_meta(conn_ref, meta); + if !file_type.is_empty() { + let meta = crate::db::Meta { + id: item_id, + name: "magic_file_type".to_string(), + value: file_type, + }; + let _ = crate::db::store_meta(conn_ref, meta); + } } // Save MIME type if let Ok(mime_type) = self.get_magic_result(CookieFlags::MIME_TYPE) { - let meta = crate::db::Meta { - id: item_id, - name: "magic_mime_type".to_string(), - value: mime_type, - }; - let _ = crate::db::store_meta(conn_ref, meta); + if !mime_type.is_empty() { + let meta = crate::db::Meta { + id: item_id, + name: "magic_mime_type".to_string(), + value: mime_type, + }; + let _ = crate::db::store_meta(conn_ref, meta); + } } // Save MIME encoding if let Ok(mime_encoding) = self.get_magic_result(CookieFlags::MIME_ENCODING) { - let meta = crate::db::Meta { - id: item_id, - name: "magic_mime_encoding".to_string(), - value: mime_encoding, - }; - let _ = crate::db::store_meta(conn_ref, meta); + if !mime_encoding.is_empty() { + let meta = crate::db::Meta { + id: item_id, + name: "magic_mime_encoding".to_string(), + value: mime_encoding, + }; + let _ = crate::db::store_meta(conn_ref, meta); + } + } + + // Save combined MIME info (type and encoding together) + if let Ok(mime_combined) = self.get_magic_result(CookieFlags::MIME) { + if !mime_combined.is_empty() { + let meta = crate::db::Meta { + id: item_id, + name: "magic_mime_combined".to_string(), + value: mime_combined, + }; + let _ = crate::db::store_meta(conn_ref, meta); + } } self.is_saved = true; @@ -105,7 +123,7 @@ impl MetaPlugin for MagicFileMetaPlugin { self.conn = Some(conn as *const _ as *mut Connection); // Initialize magic cookie with flags for comprehensive detection - let cookie = Cookie::open(CookieFlags::MIME_TYPE | CookieFlags::MIME_ENCODING) + let cookie = Cookie::open(CookieFlags::MIME_TYPE | CookieFlags::MIME_ENCODING | CookieFlags::MIME) .map_err(|e| anyhow::anyhow!("Failed to open magic cookie: {}", e))?; cookie.load(&[] as &[&str]) .map_err(|e| anyhow::anyhow!("Failed to load magic database: {}", e))?;