feat: implement status endpoint with version, paths, and plugin info
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -0,0 +1,114 @@
|
|||||||
|
use axum::{
|
||||||
|
extract::{ConnectInfo, State},
|
||||||
|
http::{HeaderMap, StatusCode},
|
||||||
|
response::Json,
|
||||||
|
http::header,
|
||||||
|
};
|
||||||
|
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};
|
||||||
|
|
||||||
|
pub async fn handle_status(
|
||||||
|
State(state): State<AppState>,
|
||||||
|
headers: HeaderMap,
|
||||||
|
ConnectInfo(addr): ConnectInfo<SocketAddr>,
|
||||||
|
) -> Result<Json<ApiResponse<HashMap<String, serde_json::Value>>>, 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();
|
||||||
|
|
||||||
|
// 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,
|
||||||
|
CompressionType::Program("test".to_string())
|
||||||
|
]
|
||||||
|
.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::FileMime,
|
||||||
|
MetaPluginType::FileEncoding,
|
||||||
|
MetaPluginType::LineCount,
|
||||||
|
MetaPluginType::WordCount,
|
||||||
|
MetaPluginType::Cwd,
|
||||||
|
MetaPluginType::Binary,
|
||||||
|
MetaPluginType::Uid,
|
||||||
|
MetaPluginType::User,
|
||||||
|
MetaPluginType::Gid,
|
||||||
|
MetaPluginType::Shell,
|
||||||
|
MetaPluginType::ShellPid,
|
||||||
|
MetaPluginType::KeepPid,
|
||||||
|
MetaPluginType::Hostname,
|
||||||
|
MetaPluginType::FullHostname,
|
||||||
|
MetaPluginType::Sha256,
|
||||||
|
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)
|
||||||
|
);
|
||||||
|
plugin.is_supported()
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
status_info.insert(
|
||||||
|
"meta_plugins".to_string(),
|
||||||
|
json!(meta_plugins)
|
||||||
|
);
|
||||||
|
|
||||||
|
let response = ApiResponse {
|
||||||
|
success: true,
|
||||||
|
data: Some(status_info),
|
||||||
|
error: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(Json(response))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user