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:
@@ -62,6 +62,10 @@ pub struct CompressionPluginConfig {
|
|||||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
pub struct MetaPluginConfig {
|
pub struct MetaPluginConfig {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
#[serde(default)]
|
||||||
|
pub options: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub outputs: std::collections::HashMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unified settings that merges config file and CLI arguments
|
/// Unified settings that merges config file and CLI arguments
|
||||||
|
|||||||
@@ -76,6 +76,16 @@ pub trait MetaPlugin {
|
|||||||
crate::db::store_meta(conn, meta)?;
|
crate::db::store_meta(conn, meta)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Configure plugin with options
|
||||||
|
fn configure(&mut self, _options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get output name mapping
|
||||||
|
fn get_output_name(&self, default_name: &str) -> String {
|
||||||
|
default_name.to_string()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_meta_plugin(meta_plugin_type: MetaPluginType) -> Box<dyn MetaPlugin> {
|
pub fn get_meta_plugin(meta_plugin_type: MetaPluginType) -> Box<dyn MetaPlugin> {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ pub struct DigestSha256MetaPlugin {
|
|||||||
meta_name: String,
|
meta_name: String,
|
||||||
item_id: Option<i64>,
|
item_id: Option<i64>,
|
||||||
conn: Option<*mut Connection>,
|
conn: Option<*mut Connection>,
|
||||||
|
output_name: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DigestSha256MetaPlugin {
|
impl DigestSha256MetaPlugin {
|
||||||
@@ -20,6 +21,7 @@ impl DigestSha256MetaPlugin {
|
|||||||
meta_name: "digest_sha256".to_string(),
|
meta_name: "digest_sha256".to_string(),
|
||||||
item_id: None,
|
item_id: None,
|
||||||
conn: None,
|
conn: None,
|
||||||
|
output_name: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,7 +50,7 @@ impl MetaPlugin for DigestSha256MetaPlugin {
|
|||||||
// Save the hash as metadata
|
// Save the hash as metadata
|
||||||
let meta = crate::db::Meta {
|
let meta = crate::db::Meta {
|
||||||
id: item_id,
|
id: item_id,
|
||||||
name: self.meta_name.clone(),
|
name: self.get_output_name(&self.meta_name),
|
||||||
value: hex_string,
|
value: hex_string,
|
||||||
};
|
};
|
||||||
crate::db::store_meta(conn_ref, meta)?;
|
crate::db::store_meta(conn_ref, meta)?;
|
||||||
@@ -63,6 +65,25 @@ impl MetaPlugin for DigestSha256MetaPlugin {
|
|||||||
fn meta_name(&mut self) -> String {
|
fn meta_name(&mut self) -> String {
|
||||||
self.meta_name.clone()
|
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>,
|
item_id: Option<i64>,
|
||||||
conn: Option<*mut Connection>,
|
conn: Option<*mut Connection>,
|
||||||
cookie: Option<Cookie>,
|
cookie: Option<Cookie>,
|
||||||
|
output_names: std::collections::HashMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MagicFileMetaPlugin {
|
impl MagicFileMetaPlugin {
|
||||||
@@ -24,6 +25,7 @@ impl MagicFileMetaPlugin {
|
|||||||
item_id: None,
|
item_id: None,
|
||||||
conn: None,
|
conn: None,
|
||||||
cookie: None,
|
cookie: None,
|
||||||
|
output_names: std::collections::HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +66,7 @@ impl MagicFileMetaPlugin {
|
|||||||
if !file_type.is_empty() {
|
if !file_type.is_empty() {
|
||||||
let meta = crate::db::Meta {
|
let meta = crate::db::Meta {
|
||||||
id: item_id,
|
id: item_id,
|
||||||
name: "file_type".to_string(),
|
name: self.get_output_name("file_type"),
|
||||||
value: file_type,
|
value: file_type,
|
||||||
};
|
};
|
||||||
let _ = crate::db::store_meta(conn_ref, meta);
|
let _ = crate::db::store_meta(conn_ref, meta);
|
||||||
@@ -76,7 +78,7 @@ impl MagicFileMetaPlugin {
|
|||||||
if !mime_type.is_empty() {
|
if !mime_type.is_empty() {
|
||||||
let meta = crate::db::Meta {
|
let meta = crate::db::Meta {
|
||||||
id: item_id,
|
id: item_id,
|
||||||
name: "mime_type".to_string(),
|
name: self.get_output_name("mime_type"),
|
||||||
value: mime_type,
|
value: mime_type,
|
||||||
};
|
};
|
||||||
let _ = crate::db::store_meta(conn_ref, meta);
|
let _ = crate::db::store_meta(conn_ref, meta);
|
||||||
@@ -88,7 +90,7 @@ impl MagicFileMetaPlugin {
|
|||||||
if !mime_encoding.is_empty() {
|
if !mime_encoding.is_empty() {
|
||||||
let meta = crate::db::Meta {
|
let meta = crate::db::Meta {
|
||||||
id: item_id,
|
id: item_id,
|
||||||
name: "mime_encoding".to_string(),
|
name: self.get_output_name("mime_encoding"),
|
||||||
value: mime_encoding,
|
value: mime_encoding,
|
||||||
};
|
};
|
||||||
let _ = crate::db::store_meta(conn_ref, meta);
|
let _ = crate::db::store_meta(conn_ref, meta);
|
||||||
@@ -150,5 +152,29 @@ impl MetaPlugin for MagicFileMetaPlugin {
|
|||||||
fn meta_name(&mut self) -> String {
|
fn meta_name(&mut self) -> String {
|
||||||
"magic_file".to_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,
|
is_saved: bool,
|
||||||
item_id: Option<i64>,
|
item_id: Option<i64>,
|
||||||
conn: Option<*mut Connection>,
|
conn: Option<*mut Connection>,
|
||||||
|
output_name: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BinaryMetaPlugin {
|
impl BinaryMetaPlugin {
|
||||||
@@ -36,6 +37,7 @@ impl BinaryMetaPlugin {
|
|||||||
is_saved: false,
|
is_saved: false,
|
||||||
item_id: None,
|
item_id: None,
|
||||||
conn: None,
|
conn: None,
|
||||||
|
output_name: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +71,7 @@ impl MetaPlugin for BinaryMetaPlugin {
|
|||||||
// Save to database immediately
|
// Save to database immediately
|
||||||
let meta = crate::db::Meta {
|
let meta = crate::db::Meta {
|
||||||
id: item_id,
|
id: item_id,
|
||||||
name: self.meta_name.clone(),
|
name: self.get_output_name(&self.meta_name),
|
||||||
value,
|
value,
|
||||||
};
|
};
|
||||||
let _ = crate::db::store_meta(conn_ref, meta);
|
let _ = crate::db::store_meta(conn_ref, meta);
|
||||||
@@ -91,6 +93,18 @@ impl MetaPlugin for BinaryMetaPlugin {
|
|||||||
Ok(())
|
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 {
|
impl CwdMetaPlugin {
|
||||||
|
|||||||
Reference in New Issue
Block a user