Files
keep/src/modes/server/api/status.rs
Andrew Phillips 898622ff6c feat: add compression type support to status endpoint
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
2025-08-15 17:10:59 -03:00

87 lines
2.9 KiB
Rust

use axum::{
extract::State,
http::StatusCode,
response::Json,
};
use std::str::FromStr;
use crate::modes::server::common::{AppState, ApiResponse, StatusInfoResponse};
use crate::common::status::{generate_status_info, StatusInfo};
use crate::meta_plugin::MetaPluginType;
use crate::compression_engine::CompressionType;
#[utoipa::path(
get,
path = "/api/status",
operation_id = "status",
summary = "Get system status",
description = "Retrieve comprehensive system status information including database configuration, data storage paths, supported compression engines, available metadata plugins, and system capabilities. This endpoint is useful for health checks and system diagnostics.",
responses(
(status = 200, description = "Successfully retrieved complete system status including database path, data directory, supported plugins, and system information", body = StatusInfoResponse),
(status = 401, description = "Unauthorized - Invalid or missing authentication credentials"),
(status = 500, description = "Internal server error - Failed to retrieve status information due to system error")
),
security(
("bearerAuth" = [])
),
tag = "status"
)]
pub async fn handle_status(
State(state): State<AppState>,
) -> Result<Json<ApiResponse<StatusInfo>>, StatusCode> {
// Get database path
let db_path = state.db.lock().await.path().unwrap_or("unknown").to_string();
// Get all meta plugin types that are supported
let supported_meta_plugins: Vec<MetaPluginType> = [
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::DigestSha256,
MetaPluginType::DigestMd5,
MetaPluginType::ReadTime,
MetaPluginType::ReadRate,
]
.iter()
.filter(|mpt| {
let plugin = crate::meta_plugin::get_meta_plugin((*mpt).clone());
plugin.is_supported()
})
.cloned()
.collect();
let enabled_compression_type = if let Some(compression_name) = &state.settings.compression {
CompressionType::from_str(compression_name).ok()
} else {
Some(crate::compression_engine::default_compression_type())
};
let status_info = generate_status_info(
state.data_dir.clone(),
db_path.into(),
&supported_meta_plugins,
enabled_compression_type,
);
let response = ApiResponse {
success: true,
data: Some(status_info),
error: None,
};
Ok(Json(response))
}