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, ) -> Result>, 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::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(); // Default to LZ4 compression for the API status endpoint let enabled_compression_type = Some(CompressionType::LZ4); 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)) }