feat: Update /status route to match status mode JSON output
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -25,6 +25,10 @@ use tower_http::trace::TraceLayer;
|
|||||||
use crate::compression_engine::{CompressionType, get_compression_engine};
|
use crate::compression_engine::{CompressionType, get_compression_engine};
|
||||||
use crate::db;
|
use crate::db;
|
||||||
use crate::Args;
|
use crate::Args;
|
||||||
|
use crate::modes::status::{PathInfo, CompressionInfo, MetaPluginInfo, StatusInfo};
|
||||||
|
use crate::compression_engine::{CompressionType as CompressionTypeEnum, COMPRESSION_PROGRAMS};
|
||||||
|
use crate::compression_engine::program::CompressionEngineProgram;
|
||||||
|
use crate::meta_plugin::{MetaPluginType, get_meta_plugin};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ServerConfig {
|
pub struct ServerConfig {
|
||||||
@@ -67,14 +71,6 @@ struct ItemInfo {
|
|||||||
metadata: HashMap<String, String>,
|
metadata: HashMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
struct StatusInfo {
|
|
||||||
version: String,
|
|
||||||
database_path: String,
|
|
||||||
data_directory: String,
|
|
||||||
compression_engines: Vec<String>,
|
|
||||||
meta_plugins: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
struct TagsQuery {
|
struct TagsQuery {
|
||||||
@@ -199,26 +195,99 @@ async fn handle_status(
|
|||||||
return Err(StatusCode::UNAUTHORIZED);
|
return Err(StatusCode::UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create dummy command and args for compatibility with status mode functions
|
||||||
|
let mut cmd = Command::new("keep");
|
||||||
|
let args = Args::default(); // This will need to be properly initialized
|
||||||
|
|
||||||
|
// Determine which meta plugins would be enabled for a save operation
|
||||||
|
let mut meta_plugin_types: Vec<MetaPluginType> = vec![]; // Empty for now, could be extended
|
||||||
|
|
||||||
let mut db_path = state.data_dir.clone();
|
let mut db_path = state.data_dir.clone();
|
||||||
db_path.push("keep-1.db");
|
db_path.push("keep-1.db");
|
||||||
|
|
||||||
let status = StatusInfo {
|
let path_info = PathInfo {
|
||||||
version: env!("CARGO_PKG_VERSION").to_string(),
|
data: state.data_dir.to_string_lossy().to_string(),
|
||||||
database_path: db_path.to_string_lossy().to_string(),
|
database: db_path.to_string_lossy().to_string(),
|
||||||
data_directory: state.data_dir.to_string_lossy().to_string(),
|
};
|
||||||
compression_engines: vec!["gzip".to_string(), "lz4".to_string(), "none".to_string()],
|
|
||||||
meta_plugins: vec![
|
let default_type = crate::compression_engine::default_compression_type();
|
||||||
"file_magic".to_string(),
|
let mut compression_info = Vec::new();
|
||||||
"file_mime".to_string(),
|
|
||||||
"line_count".to_string(),
|
for compression_type in CompressionTypeEnum::iter() {
|
||||||
"word_count".to_string(),
|
let compression_program: CompressionEngineProgram =
|
||||||
"sha256".to_string(),
|
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();
|
||||||
|
|
||||||
|
for meta_plugin_type in MetaPluginType::iter() {
|
||||||
|
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 {
|
||||||
|
match meta_plugin_type {
|
||||||
|
MetaPluginType::DigestSha256 | MetaPluginType::ReadTime | MetaPluginType::ReadRate |
|
||||||
|
MetaPluginType::Cwd | MetaPluginType::Uid | MetaPluginType::User |
|
||||||
|
MetaPluginType::Gid | MetaPluginType::Group | MetaPluginType::Shell |
|
||||||
|
MetaPluginType::ShellPid | MetaPluginType::KeepPid | MetaPluginType::Hostname |
|
||||||
|
MetaPluginType::FullHostname => {
|
||||||
|
("<INTERNAL>".to_string(), "".to_string())
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
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 response = ApiResponse {
|
let response = ApiResponse {
|
||||||
success: true,
|
success: true,
|
||||||
data: Some(status),
|
data: Some(status_info),
|
||||||
error: None,
|
error: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -287,31 +287,8 @@ struct StatusInfo {
|
|||||||
meta_plugins: Vec<MetaPluginInfo>,
|
meta_plugins: Vec<MetaPluginInfo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
struct PathInfo {
|
|
||||||
data: String,
|
|
||||||
database: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
struct CompressionInfo {
|
|
||||||
#[serde(rename = "type")]
|
|
||||||
compression_type: String,
|
|
||||||
found: bool,
|
|
||||||
default: bool,
|
|
||||||
binary: String,
|
|
||||||
compress: String,
|
|
||||||
decompress: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
struct MetaPluginInfo {
|
|
||||||
meta_name: String,
|
|
||||||
found: bool,
|
|
||||||
enabled: bool,
|
|
||||||
binary: String,
|
|
||||||
args: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn mode_status(
|
pub fn mode_status(
|
||||||
_cmd: &mut Command,
|
_cmd: &mut Command,
|
||||||
|
|||||||
Reference in New Issue
Block a user