refactor: update meta plugins to use new trait interface
Co-authored-by: aider (openai/andrew/openrouter/mistralai/mistral-medium-3.1) <aider@aider.chat>
This commit is contained in:
@@ -82,40 +82,62 @@ impl MetaPlugin for BinaryMetaPlugin {
|
||||
true
|
||||
}
|
||||
|
||||
fn finalize(&mut self, conn: &Connection) -> Result<()> {
|
||||
fn finalize(&mut self) -> Result<PluginResponse> {
|
||||
let mut metadata = Vec::new();
|
||||
|
||||
// Save the binary detection result when finalizing, if not already saved
|
||||
self.save_metadata(conn)
|
||||
if let Some(item_id) = self.item_id {
|
||||
let is_binary_result = is_binary(&self.buffer);
|
||||
let value = if is_binary_result { "true".to_string() } else { "false".to_string() };
|
||||
|
||||
if let Some(meta) = self.create_meta(item_id, "binary", value) {
|
||||
metadata.push(meta);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(PluginResponse {
|
||||
metadata: Some(metadata),
|
||||
is_finalized: true,
|
||||
})
|
||||
}
|
||||
|
||||
fn update(&mut self, data: &[u8], conn: &Connection) {
|
||||
// If we've already saved the metadata, no need to collect more data
|
||||
if self.is_saved {
|
||||
return;
|
||||
}
|
||||
|
||||
fn update(&mut self, data: &[u8]) -> Result<PluginResponse> {
|
||||
// Calculate how much data we can still accept
|
||||
let remaining_capacity = self.max_buffer_size.saturating_sub(self.buffer.len());
|
||||
if remaining_capacity > 0 {
|
||||
// Determine how much data to copy
|
||||
let bytes_to_take = std::cmp::min(data.len(), remaining_capacity);
|
||||
|
||||
|
||||
// Add data to our buffer
|
||||
self.buffer.extend_from_slice(&data[..bytes_to_take]);
|
||||
}
|
||||
|
||||
// If we've reached our buffer limit, save the metadata immediately
|
||||
|
||||
// If we've reached our buffer limit, return metadata
|
||||
let mut metadata = Vec::new();
|
||||
if self.buffer.len() >= self.max_buffer_size {
|
||||
let _ = self.save_metadata(conn);
|
||||
if let Some(item_id) = self.item_id {
|
||||
let is_binary_result = is_binary(&self.buffer);
|
||||
let value = if is_binary_result { "true".to_string() } else { "false".to_string() };
|
||||
|
||||
if let Some(meta) = self.create_meta(item_id, "binary", value) {
|
||||
metadata.push(meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(PluginResponse {
|
||||
metadata: if metadata.is_empty() { None } else { Some(metadata) },
|
||||
is_finalized: !metadata.is_empty(),
|
||||
})
|
||||
}
|
||||
|
||||
fn meta_name(&self) -> String {
|
||||
self.meta_name.clone()
|
||||
}
|
||||
|
||||
fn initialize(&mut self, _conn: &Connection, item_id: i64) -> Result<()> {
|
||||
fn initialize(&mut self, item_id: i64) -> Result<PluginResponse> {
|
||||
self.item_id = Some(item_id);
|
||||
Ok(())
|
||||
Ok(PluginResponse::default())
|
||||
}
|
||||
|
||||
fn configure_options(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user