fix: align /api/status endpoint with --status --output-format=json command output
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -4,70 +4,27 @@ use axum::{
|
||||
response::Json,
|
||||
};
|
||||
use log::warn;
|
||||
use serde_json::json;
|
||||
use std::net::SocketAddr;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::compression_engine::CompressionType;
|
||||
use crate::meta_plugin::MetaPluginType;
|
||||
use crate::modes::server::common::{AppState, ApiResponse, check_auth};
|
||||
use crate::modes::status::{generate_status_info, StatusInfo};
|
||||
use crate::meta_plugin::MetaPluginType;
|
||||
|
||||
pub async fn handle_status(
|
||||
State(state): State<AppState>,
|
||||
headers: HeaderMap,
|
||||
ConnectInfo(addr): ConnectInfo<SocketAddr>,
|
||||
) -> Result<Json<ApiResponse<HashMap<String, serde_json::Value>>>, StatusCode> {
|
||||
) -> Result<Json<ApiResponse<StatusInfo>>, StatusCode> {
|
||||
if !check_auth(&headers, &state.password) {
|
||||
warn!("Unauthorized request to /api/status from {}", addr);
|
||||
return Err(StatusCode::UNAUTHORIZED);
|
||||
}
|
||||
|
||||
let mut status_info = HashMap::new();
|
||||
// Get database path
|
||||
let db_path = state.db.lock().await.path().unwrap_or("unknown").to_string();
|
||||
|
||||
// Add version info
|
||||
status_info.insert(
|
||||
"version".to_string(),
|
||||
json!(env!("CARGO_PKG_VERSION"))
|
||||
);
|
||||
|
||||
// Add database path
|
||||
status_info.insert(
|
||||
"database_path".to_string(),
|
||||
json!(state.db.lock().await.path().unwrap_or("unknown"))
|
||||
);
|
||||
|
||||
// Add data directory
|
||||
status_info.insert(
|
||||
"data_directory".to_string(),
|
||||
json!(state.data_dir.to_string_lossy())
|
||||
);
|
||||
|
||||
// Add compression engines
|
||||
let compression_engines: Vec<String> = [
|
||||
CompressionType::GZip,
|
||||
CompressionType::LZ4,
|
||||
CompressionType::None,
|
||||
]
|
||||
.iter()
|
||||
.map(|ct| ct.to_string())
|
||||
.filter(|ct| {
|
||||
if let Ok(engine) = crate::compression_engine::get_compression_engine(
|
||||
ct.parse().unwrap_or(CompressionType::None)
|
||||
) {
|
||||
engine.is_supported()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
status_info.insert(
|
||||
"compression_engines".to_string(),
|
||||
json!(compression_engines)
|
||||
);
|
||||
|
||||
// Add meta plugins
|
||||
let meta_plugins: Vec<String> = [
|
||||
// Get all meta plugin types that are supported
|
||||
let supported_meta_plugins: Vec<MetaPluginType> = [
|
||||
MetaPluginType::FileMagic,
|
||||
MetaPluginType::FileMime,
|
||||
MetaPluginType::FileEncoding,
|
||||
@@ -83,20 +40,23 @@ pub async fn handle_status(
|
||||
MetaPluginType::KeepPid,
|
||||
MetaPluginType::Hostname,
|
||||
MetaPluginType::FullHostname,
|
||||
MetaPluginType::DigestSha256,
|
||||
MetaPluginType::DigestMd5,
|
||||
MetaPluginType::ReadTime,
|
||||
MetaPluginType::ReadRate,
|
||||
]
|
||||
.iter()
|
||||
.map(|mpt| mpt.to_string())
|
||||
.filter(|mpt| {
|
||||
let plugin = crate::meta_plugin::get_meta_plugin(
|
||||
mpt.parse().unwrap_or(MetaPluginType::FileMagic)
|
||||
);
|
||||
let plugin = crate::meta_plugin::get_meta_plugin((*mpt).clone());
|
||||
plugin.is_supported()
|
||||
})
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
status_info.insert(
|
||||
"meta_plugins".to_string(),
|
||||
json!(meta_plugins)
|
||||
let status_info = generate_status_info(
|
||||
state.data_dir.clone(),
|
||||
db_path.into(),
|
||||
&supported_meta_plugins,
|
||||
);
|
||||
|
||||
let response = ApiResponse {
|
||||
|
||||
Reference in New Issue
Block a user