refactor: modularize server.rs into separate route modules
- Extract scan.rs, files.rs, types.rs, processing.rs, visual_chunk_search.rs - Move AppState and AppConfig to types.rs - Each module exposes pub fn xxx_routes() -> Router<AppState> - server.rs reduced from 5005 to 118 lines (orchestrator only) - All stubs filled with real implementations from git history - Verify: cargo check, clippy, tests all pass
This commit is contained in:
@@ -10,7 +10,7 @@ use sqlx::Row;
|
||||
|
||||
use crate::core::db::ResourceRecord;
|
||||
|
||||
pub fn identity_routes() -> Router<crate::api::server::AppState> {
|
||||
pub fn identity_routes() -> Router<crate::api::types::AppState> {
|
||||
Router::new()
|
||||
.route("/api/v1/files", get(list_files))
|
||||
.route("/api/v1/file/:file_uuid", get(get_file_detail))
|
||||
@@ -65,7 +65,7 @@ pub struct FilesQuery {
|
||||
}
|
||||
|
||||
async fn list_files(
|
||||
State(state): State<crate::api::server::AppState>,
|
||||
State(state): State<crate::api::types::AppState>,
|
||||
Query(params): Query<FilesQuery>,
|
||||
) -> Result<Json<FilesResponse>, (StatusCode, String)> {
|
||||
let page = params.page.unwrap_or(1);
|
||||
@@ -158,7 +158,7 @@ pub struct FileDetailResponse {
|
||||
}
|
||||
|
||||
async fn get_file_detail(
|
||||
State(state): State<crate::api::server::AppState>,
|
||||
State(state): State<crate::api::types::AppState>,
|
||||
Path(file_uuid): Path<String>,
|
||||
) -> Result<Json<FileDetailResponse>, (StatusCode, String)> {
|
||||
let file = state
|
||||
@@ -212,7 +212,7 @@ pub struct FileIdentityItem {
|
||||
}
|
||||
|
||||
async fn get_file_identities(
|
||||
State(state): State<crate::api::server::AppState>,
|
||||
State(state): State<crate::api::types::AppState>,
|
||||
Path(file_uuid): Path<String>,
|
||||
Query(params): Query<FilesQuery>,
|
||||
) -> Result<Json<FileIdentitiesResponse>, (StatusCode, String)> {
|
||||
@@ -300,7 +300,7 @@ fn strip_uuid(u: &uuid::Uuid) -> String {
|
||||
}
|
||||
|
||||
async fn get_identity_detail(
|
||||
State(state): State<crate::api::server::AppState>,
|
||||
State(state): State<crate::api::types::AppState>,
|
||||
Path(identity_uuid): Path<String>,
|
||||
) -> Result<Json<IdentityDetailResponse>, (StatusCode, String)> {
|
||||
let uuid_clean = identity_uuid.replace('-', "");
|
||||
@@ -338,7 +338,7 @@ async fn get_identity_detail(
|
||||
}
|
||||
|
||||
async fn get_identity_status(
|
||||
State(state): State<crate::api::server::AppState>,
|
||||
State(state): State<crate::api::types::AppState>,
|
||||
Path(identity_uuid): Path<String>,
|
||||
) -> Result<Json<IdentityStatusResponse>, (StatusCode, String)> {
|
||||
let uuid_clean = identity_uuid.replace('-', "");
|
||||
@@ -386,7 +386,7 @@ pub struct IdentityFilesResponse {
|
||||
}
|
||||
|
||||
async fn delete_identity(
|
||||
State(state): State<crate::api::server::AppState>,
|
||||
State(state): State<crate::api::types::AppState>,
|
||||
Path(identity_uuid): Path<String>,
|
||||
) -> Result<StatusCode, StatusCode> {
|
||||
let table = crate::core::db::schema::table_name("face_detections");
|
||||
@@ -438,7 +438,7 @@ pub struct IdentityFileItem {
|
||||
}
|
||||
|
||||
async fn get_identity_files(
|
||||
State(state): State<crate::api::server::AppState>,
|
||||
State(state): State<crate::api::types::AppState>,
|
||||
Path(identity_uuid): Path<String>,
|
||||
Query(params): Query<FilesQuery>,
|
||||
) -> Result<Json<IdentityFilesResponse>, (StatusCode, String)> {
|
||||
@@ -524,7 +524,7 @@ pub struct BBox {
|
||||
}
|
||||
|
||||
async fn get_identity_faces(
|
||||
State(state): State<crate::api::server::AppState>,
|
||||
State(state): State<crate::api::types::AppState>,
|
||||
Path(identity_uuid): Path<String>,
|
||||
Query(params): Query<FilesQuery>,
|
||||
) -> Result<Json<IdentityFacesResponse>, (StatusCode, String)> {
|
||||
@@ -608,7 +608,7 @@ pub struct IdentityChunkItem {
|
||||
}
|
||||
|
||||
async fn get_identity_chunks(
|
||||
State(state): State<crate::api::server::AppState>,
|
||||
State(state): State<crate::api::types::AppState>,
|
||||
Path(identity_uuid): Path<String>,
|
||||
Query(params): Query<FilesQuery>,
|
||||
) -> Result<Json<IdentityChunksResponse>, (StatusCode, String)> {
|
||||
@@ -680,7 +680,7 @@ pub struct ResourceItem {
|
||||
}
|
||||
|
||||
async fn register_resource(
|
||||
State(state): State<crate::api::server::AppState>,
|
||||
State(state): State<crate::api::types::AppState>,
|
||||
Json(req): Json<RegisterResourceRequest>,
|
||||
) -> Result<Json<ResourceResponse>, (StatusCode, String)> {
|
||||
let resource = ResourceRecord {
|
||||
@@ -715,7 +715,7 @@ pub struct HeartbeatRequest {
|
||||
}
|
||||
|
||||
async fn heartbeat_resource(
|
||||
State(state): State<crate::api::server::AppState>,
|
||||
State(state): State<crate::api::types::AppState>,
|
||||
Json(req): Json<HeartbeatRequest>,
|
||||
) -> Result<Json<ResourceResponse>, (StatusCode, String)> {
|
||||
let status = req.status.unwrap_or("online".to_string());
|
||||
@@ -733,7 +733,7 @@ async fn heartbeat_resource(
|
||||
}
|
||||
|
||||
async fn list_resources(
|
||||
State(state): State<crate::api::server::AppState>,
|
||||
State(state): State<crate::api::types::AppState>,
|
||||
) -> Result<Json<ResourceResponse>, (StatusCode, String)> {
|
||||
let records = state
|
||||
.db
|
||||
@@ -771,7 +771,7 @@ struct IdentityUploadResponse {
|
||||
}
|
||||
|
||||
async fn upload_identity(
|
||||
State(state): State<crate::api::server::AppState>,
|
||||
State(state): State<crate::api::types::AppState>,
|
||||
Json(payload): Json<crate::core::identity::storage::IdentityFile>,
|
||||
) -> Result<Json<IdentityUploadResponse>, (StatusCode, Json<serde_json::Value>)> {
|
||||
let parsed = uuid::Uuid::parse_str(&payload.identity_uuid)
|
||||
@@ -838,7 +838,7 @@ struct ProfileImageResponse {
|
||||
}
|
||||
|
||||
async fn upload_profile_image(
|
||||
State(state): State<crate::api::server::AppState>,
|
||||
State(state): State<crate::api::types::AppState>,
|
||||
Path(identity_uuid): Path<String>,
|
||||
mut multipart: Multipart,
|
||||
) -> Result<Json<ProfileImageResponse>, (StatusCode, Json<serde_json::Value>)> {
|
||||
@@ -951,7 +951,7 @@ async fn get_profile_image(
|
||||
}
|
||||
|
||||
async fn get_identity_json(
|
||||
State(state): State<crate::api::server::AppState>,
|
||||
State(state): State<crate::api::types::AppState>,
|
||||
Path(identity_uuid): Path<String>,
|
||||
) -> Result<(StatusCode, [(String, String); 1], Vec<u8>), StatusCode> {
|
||||
let clean = identity_uuid.replace('-', "");
|
||||
@@ -1040,7 +1040,7 @@ struct IdentityTextResponse {
|
||||
|
||||
/// Path A: Search chunk text → associated identities
|
||||
async fn search_identity_text(
|
||||
State(state): State<crate::api::server::AppState>,
|
||||
State(state): State<crate::api::types::AppState>,
|
||||
Query(params): Query<IdentityTextQuery>,
|
||||
) -> Result<Json<IdentityTextResponse>, StatusCode> {
|
||||
use crate::core::db::schema;
|
||||
@@ -1148,7 +1148,7 @@ struct IdentitySearchResponse {
|
||||
|
||||
/// Path B: Search identity name → associated chunk text
|
||||
async fn search_identities_by_text(
|
||||
State(state): State<crate::api::server::AppState>,
|
||||
State(state): State<crate::api::types::AppState>,
|
||||
Query(params): Query<IdentitySearchQuery>,
|
||||
) -> Result<Json<IdentitySearchResponse>, StatusCode> {
|
||||
use crate::core::db::schema;
|
||||
|
||||
Reference in New Issue
Block a user