refactor: reorganize REST API into modular endpoint files
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
use axum::{
|
||||
extract::{ConnectInfo, State},
|
||||
http::{HeaderMap, StatusCode},
|
||||
response::Json,
|
||||
};
|
||||
use clap::Command;
|
||||
use log::warn;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::meta_plugin::MetaPluginType;
|
||||
use crate::modes::status::{StatusInfo, generate_status_info};
|
||||
use crate::modes::server::common::{AppState, ApiResponse, check_auth};
|
||||
|
||||
pub async fn handle_status(
|
||||
State(state): State<AppState>,
|
||||
headers: HeaderMap,
|
||||
ConnectInfo(addr): ConnectInfo<std::net::SocketAddr>,
|
||||
) -> Result<Json<ApiResponse<StatusInfo>>, StatusCode> {
|
||||
if !check_auth(&headers, &state.password) {
|
||||
warn!("Unauthorized request from {}", addr);
|
||||
return Err(StatusCode::UNAUTHORIZED);
|
||||
}
|
||||
|
||||
// Use the actual args that the server was started with
|
||||
let args = &state.args;
|
||||
|
||||
// Determine which meta plugins would be enabled for a save operation
|
||||
let mut meta_plugin_types: Vec<MetaPluginType> = crate::modes::common::cmd_args_meta_plugin_types(&mut Command::new("keep"), args);
|
||||
|
||||
// Add digest type if specified
|
||||
let digest_type = crate::modes::common::cmd_args_digest_type(&mut Command::new("keep"), args);
|
||||
let digest_meta_plugin_type = match digest_type {
|
||||
crate::meta_plugin::MetaPluginType::DigestSha256 => Some(MetaPluginType::DigestSha256),
|
||||
crate::meta_plugin::MetaPluginType::DigestMd5 => Some(MetaPluginType::DigestMd5),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
if let Some(digest_plugin_type) = digest_meta_plugin_type {
|
||||
if !meta_plugin_types.contains(&digest_plugin_type) {
|
||||
meta_plugin_types.push(digest_plugin_type);
|
||||
}
|
||||
}
|
||||
|
||||
let mut db_path = state.data_dir.clone();
|
||||
db_path.push("keep-1.db");
|
||||
|
||||
let status_info = generate_status_info(state.data_dir.clone(), db_path, &meta_plugin_types);
|
||||
|
||||
let response = ApiResponse {
|
||||
success: true,
|
||||
data: Some(status_info),
|
||||
error: None,
|
||||
};
|
||||
|
||||
Ok(Json(response))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user