Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
147 lines
5.5 KiB
Rust
147 lines
5.5 KiB
Rust
use std::path::PathBuf;
|
|
use strum::IntoEnumIterator;
|
|
use utoipa::ToSchema;
|
|
|
|
use crate::compression_engine;
|
|
use crate::compression_engine::COMPRESSION_PROGRAMS;
|
|
use crate::compression_engine::CompressionType;
|
|
use crate::compression_engine::program::CompressionEngineProgram;
|
|
use crate::meta_plugin::MetaPluginType;
|
|
use crate::meta_plugin;
|
|
|
|
#[derive(serde::Serialize, serde::Deserialize, ToSchema)]
|
|
pub struct StatusInfo {
|
|
pub paths: PathInfo,
|
|
pub compression: Vec<CompressionInfo>,
|
|
pub meta_plugins: std::collections::HashMap<String, MetaPluginInfo>,
|
|
pub enabled_meta_plugins: Vec<String>,
|
|
}
|
|
|
|
#[derive(serde::Serialize, serde::Deserialize, ToSchema)]
|
|
pub struct PathInfo {
|
|
pub data: String,
|
|
pub database: String,
|
|
}
|
|
|
|
#[derive(serde::Serialize, serde::Deserialize, ToSchema)]
|
|
pub struct CompressionInfo {
|
|
#[serde(rename = "type")]
|
|
pub compression_type: String,
|
|
pub found: bool,
|
|
pub default: bool,
|
|
pub binary: String,
|
|
pub compress: String,
|
|
pub decompress: String,
|
|
}
|
|
|
|
#[derive(serde::Serialize, serde::Deserialize, ToSchema, Clone)]
|
|
pub struct MetaPluginInfo {
|
|
pub meta_name: String,
|
|
pub outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
|
pub options: std::collections::HashMap<String, serde_yaml::Value>,
|
|
}
|
|
|
|
pub fn generate_status_info(
|
|
data_path: PathBuf,
|
|
db_path: PathBuf,
|
|
enabled_meta_plugins: &Vec<MetaPluginType>,
|
|
enabled_compression_type: Option<CompressionType>,
|
|
) -> StatusInfo {
|
|
log::debug!("STATUS: Starting status info generation");
|
|
let path_info = PathInfo {
|
|
data: data_path.into_os_string().into_string().expect("Unable to convert data path to string"),
|
|
database: db_path.into_os_string().into_string().expect("Unable to convert DB path to string"),
|
|
};
|
|
|
|
let default_type = compression_engine::default_compression_type();
|
|
let mut compression_info = Vec::new();
|
|
|
|
// Sort compression types by their string representation
|
|
let mut sorted_compression_types: Vec<CompressionType> = CompressionType::iter().collect();
|
|
sorted_compression_types.sort_by_key(|ct| ct.to_string());
|
|
|
|
for compression_type in sorted_compression_types {
|
|
let compression_program: CompressionEngineProgram =
|
|
match &COMPRESSION_PROGRAMS[compression_type.clone()] {
|
|
Some(compression_program) => compression_program.clone(),
|
|
None => CompressionEngineProgram {
|
|
program: "".to_string(),
|
|
compress: Vec::new(),
|
|
decompress: Vec::new(),
|
|
supported: true,
|
|
},
|
|
};
|
|
|
|
let _is_default = compression_type == default_type;
|
|
let is_enabled = enabled_compression_type.as_ref().map_or(false, |ct| *ct == compression_type);
|
|
let binary = if compression_program.program.is_empty() {
|
|
"<INTERNAL>".to_string()
|
|
} else {
|
|
compression_program.program
|
|
};
|
|
|
|
compression_info.push(CompressionInfo {
|
|
compression_type: compression_type.to_string(),
|
|
found: compression_program.supported,
|
|
default: is_enabled, // Changed from is_default to is_enabled
|
|
binary,
|
|
compress: compression_program.compress.join(" "),
|
|
decompress: compression_program.decompress.join(" "),
|
|
});
|
|
}
|
|
|
|
let mut meta_plugins_map = std::collections::HashMap::new();
|
|
let mut enabled_meta_plugins_vec = Vec::new();
|
|
|
|
// Sort meta plugin types by their string representation to avoid creating plugins just for sorting
|
|
let mut sorted_meta_plugins: Vec<MetaPluginType> = MetaPluginType::iter().collect();
|
|
sorted_meta_plugins.sort_by_key(|meta_plugin_type| meta_plugin_type.to_string());
|
|
|
|
for meta_plugin_type in sorted_meta_plugins {
|
|
log::debug!("STATUS: Processing meta plugin type: {:?}", meta_plugin_type);
|
|
log::debug!("STATUS: About to call get_meta_plugin");
|
|
let meta_plugin = meta_plugin::get_meta_plugin(meta_plugin_type.clone(), None, None);
|
|
log::debug!("STATUS: Created meta plugin instance");
|
|
|
|
// Get meta name first to avoid borrowing issues
|
|
log::debug!("STATUS: Getting meta name...");
|
|
let meta_name = meta_plugin.meta_type().to_string();
|
|
log::debug!("STATUS: Got meta name: {}", meta_name);
|
|
|
|
// Check if this plugin is enabled
|
|
let is_enabled = enabled_meta_plugins.contains(&meta_plugin_type);
|
|
if is_enabled {
|
|
enabled_meta_plugins_vec.push(meta_name.clone());
|
|
}
|
|
|
|
// Create a display of outputs for status - use configured outputs if available, otherwise defaults
|
|
let outputs_display = if meta_plugin.outputs().is_empty() {
|
|
// No configured outputs, use defaults
|
|
let mut default_outputs = std::collections::HashMap::new();
|
|
for output_name in meta_plugin.default_outputs() {
|
|
default_outputs.insert(output_name.clone(), serde_yaml::Value::String(output_name));
|
|
}
|
|
default_outputs
|
|
} else {
|
|
// Use configured outputs
|
|
meta_plugin.outputs().clone()
|
|
};
|
|
|
|
// Get options
|
|
let options = meta_plugin.options().clone();
|
|
|
|
meta_plugins_map.insert(meta_name.clone(), MetaPluginInfo {
|
|
meta_name,
|
|
outputs: outputs_display,
|
|
options,
|
|
});
|
|
}
|
|
|
|
StatusInfo {
|
|
paths: path_info,
|
|
compression: compression_info,
|
|
meta_plugins: meta_plugins_map,
|
|
enabled_meta_plugins: enabled_meta_plugins_vec,
|
|
}
|
|
}
|