refactor: unify status data generation and output formatting
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -25,7 +25,7 @@ use tower_http::trace::TraceLayer;
|
||||
use crate::compression_engine::{CompressionType, get_compression_engine};
|
||||
use crate::db;
|
||||
use crate::Args;
|
||||
use crate::modes::status::{PathInfo, CompressionInfo, MetaPluginInfo, StatusInfo};
|
||||
use crate::modes::status::{StatusInfo, generate_status_info};
|
||||
use crate::compression_engine::{CompressionType as CompressionTypeEnum, COMPRESSION_PROGRAMS};
|
||||
use crate::compression_engine::program::CompressionEngineProgram;
|
||||
use crate::meta_plugin::{MetaPluginType, get_meta_plugin};
|
||||
@@ -220,89 +220,7 @@ async fn handle_status(
|
||||
let mut db_path = state.data_dir.clone();
|
||||
db_path.push("keep-1.db");
|
||||
|
||||
let path_info = PathInfo {
|
||||
data: state.data_dir.to_string_lossy().to_string(),
|
||||
database: db_path.to_string_lossy().to_string(),
|
||||
};
|
||||
|
||||
let default_type = crate::compression_engine::default_compression_type();
|
||||
let mut compression_info = Vec::new();
|
||||
|
||||
// Sort compression types by their string representation
|
||||
let mut sorted_compression_types: Vec<CompressionTypeEnum> = CompressionTypeEnum::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 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_default,
|
||||
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> = MetaPluginType::iter().collect();
|
||||
sorted_meta_plugins.sort_by_key(|meta_plugin_type| {
|
||||
let mut 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 = get_meta_plugin(meta_plugin_type.clone());
|
||||
let is_supported = meta_plugin.is_supported();
|
||||
let is_enabled = meta_plugin_types.contains(&meta_plugin_type);
|
||||
|
||||
let (binary_display, args_display) = if !is_supported {
|
||||
("<NOT FOUND>".to_string(), "".to_string())
|
||||
} else {
|
||||
if meta_plugin.is_internal() {
|
||||
("<INTERNAL>".to_string(), "".to_string())
|
||||
} else {
|
||||
if let Some((program, args)) = meta_plugin.program_info() {
|
||||
(program.to_string(), args.join(" "))
|
||||
} else {
|
||||
("<NOT FOUND>".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,
|
||||
});
|
||||
}
|
||||
|
||||
let status_info = StatusInfo {
|
||||
paths: path_info,
|
||||
compression: compression_info,
|
||||
meta_plugins: meta_plugin_info,
|
||||
};
|
||||
let status_info = generate_status_info(state.data_dir.clone(), db_path, &meta_plugin_types);
|
||||
|
||||
let response = ApiResponse {
|
||||
success: true,
|
||||
|
||||
Reference in New Issue
Block a user