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,
|
response::Json,
|
||||||
};
|
};
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use serde_json::json;
|
|
||||||
use std::net::SocketAddr;
|
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::server::common::{AppState, ApiResponse, check_auth};
|
||||||
|
use crate::modes::status::{generate_status_info, StatusInfo};
|
||||||
|
use crate::meta_plugin::MetaPluginType;
|
||||||
|
|
||||||
pub async fn handle_status(
|
pub async fn handle_status(
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
ConnectInfo(addr): ConnectInfo<SocketAddr>,
|
ConnectInfo(addr): ConnectInfo<SocketAddr>,
|
||||||
) -> Result<Json<ApiResponse<HashMap<String, serde_json::Value>>>, StatusCode> {
|
) -> Result<Json<ApiResponse<StatusInfo>>, StatusCode> {
|
||||||
if !check_auth(&headers, &state.password) {
|
if !check_auth(&headers, &state.password) {
|
||||||
warn!("Unauthorized request to /api/status from {}", addr);
|
warn!("Unauthorized request to /api/status from {}", addr);
|
||||||
return Err(StatusCode::UNAUTHORIZED);
|
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
|
// Get all meta plugin types that are supported
|
||||||
status_info.insert(
|
let supported_meta_plugins: Vec<MetaPluginType> = [
|
||||||
"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> = [
|
|
||||||
MetaPluginType::FileMagic,
|
MetaPluginType::FileMagic,
|
||||||
MetaPluginType::FileMime,
|
MetaPluginType::FileMime,
|
||||||
MetaPluginType::FileEncoding,
|
MetaPluginType::FileEncoding,
|
||||||
@@ -83,20 +40,23 @@ pub async fn handle_status(
|
|||||||
MetaPluginType::KeepPid,
|
MetaPluginType::KeepPid,
|
||||||
MetaPluginType::Hostname,
|
MetaPluginType::Hostname,
|
||||||
MetaPluginType::FullHostname,
|
MetaPluginType::FullHostname,
|
||||||
|
MetaPluginType::DigestSha256,
|
||||||
|
MetaPluginType::DigestMd5,
|
||||||
|
MetaPluginType::ReadTime,
|
||||||
|
MetaPluginType::ReadRate,
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
.map(|mpt| mpt.to_string())
|
|
||||||
.filter(|mpt| {
|
.filter(|mpt| {
|
||||||
let plugin = crate::meta_plugin::get_meta_plugin(
|
let plugin = crate::meta_plugin::get_meta_plugin((*mpt).clone());
|
||||||
mpt.parse().unwrap_or(MetaPluginType::FileMagic)
|
|
||||||
);
|
|
||||||
plugin.is_supported()
|
plugin.is_supported()
|
||||||
})
|
})
|
||||||
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
status_info.insert(
|
let status_info = generate_status_info(
|
||||||
"meta_plugins".to_string(),
|
state.data_dir.clone(),
|
||||||
json!(meta_plugins)
|
db_path.into(),
|
||||||
|
&supported_meta_plugins,
|
||||||
);
|
);
|
||||||
|
|
||||||
let response = ApiResponse {
|
let response = ApiResponse {
|
||||||
|
|||||||
Reference in New Issue
Block a user