refactor: remove redundant server modules after api refactoring

Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-12 14:32:44 -03:00
parent 077adc0cb0
commit 703ae3b776
2 changed files with 1 additions and 99 deletions

View File

@@ -3,25 +3,4 @@ use axum::{
Router, Router,
}; };
use crate::modes::server::common::AppState; use
pub mod item;
pub mod status;
pub mod docs;
pub fn api_routes() -> Router<AppState> {
Router::new()
// Item endpoints
.route("/api/item/", get(item::handle_list_items).post(item::handle_post_item))
.route("/api/item/latest", get(item::handle_get_item_latest))
.route("/api/item/latest/meta", get(item::handle_get_item_latest_meta))
.route("/api/item/latest/content", get(item::handle_get_content_latest_raw))
.route("/api/item/:id", get(item::handle_get_item).delete(item::handle_delete_item))
.route("/api/item/:id/meta", get(item::handle_get_item_meta))
.route("/api/item/:id/content", get(item::handle_get_content_raw))
// Status endpoint
.route("/api/status", get(status::handle_status))
// Documentation endpoints
.route("/api/openapi.json", get(docs::handle_openapi))
.route("/api/docs", get(docs::handle_swagger_ui))
}

View File

@@ -1,77 +0,0 @@
use axum::{
extract::{ConnectInfo, State},
http::{HeaderMap, StatusCode},
response::Json,
};
use clap::Command;
use log::warn;
use serde_json::json;
use std::net::SocketAddr;
use crate::meta_plugin::MetaPluginType;
use crate::modes::status::{StatusInfo, generate_status_info};
use super::common::{AppState, ApiResponse, check_auth};
pub async fn handle_status(
State(state): State<AppState>,
headers: HeaderMap,
ConnectInfo(addr): ConnectInfo<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))
}
pub fn get_status_openapi_spec() -> serde_json::Value {
json!({
"/api/status": {
"get": {
"summary": "Get system status",
"responses": {
"200": {
"description": "System status",
"content": {
"application/json": {
"schema": {"$ref": "#/components/schemas/StatusInfo"}
}
}
}
}
}
}
})
}