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, pub meta_plugins: Vec, } #[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)] pub struct MetaPluginInfo { pub meta_name: String, pub found: bool, pub enabled: bool, pub binary: String, pub args: String, } pub fn generate_status_info( data_path: PathBuf, db_path: PathBuf, enabled_meta_plugins: &Vec, enabled_compression_type: Option, ) -> StatusInfo { 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::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() { "".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_plugin_info = Vec::new(); // Sort meta plugin types by their meta name let mut sorted_meta_plugins: Vec = MetaPluginType::iter().collect(); sorted_meta_plugins.sort_by_key(|meta_plugin_type| { let mut meta_plugin = meta_plugin::get_meta_plugin(meta_plugin_type.clone()); meta_plugin.meta_name() }); for meta_plugin_type in sorted_meta_plugins { let mut meta_plugin = meta_plugin::get_meta_plugin(meta_plugin_type.clone()); let is_supported = meta_plugin.is_supported(); let is_enabled = enabled_meta_plugins.contains(&meta_plugin_type); let (binary_display, args_display) = if !is_supported { ("".to_string(), "".to_string()) } else { if meta_plugin.is_internal() { ("".to_string(), "".to_string()) } else { if let Some((program, args)) = meta_plugin.program_info() { (program.to_string(), args.join(" ")) } else { ("".to_string(), "".to_string()) } } }; meta_plugin_info.push(MetaPluginInfo { meta_name: meta_plugin.meta_name(), found: is_supported, enabled: is_enabled, binary: binary_display, args: args_display, }); } StatusInfo { paths: path_info, compression: compression_info, meta_plugins: meta_plugin_info, } }