diff --git a/src/api/processing.rs b/src/api/processing.rs index cb5b5a9e..541320d4 100644 --- a/src/api/processing.rs +++ b/src/api/processing.rs @@ -788,6 +788,51 @@ struct ProcessorCountsResponse { processors: Vec, } +/// GET /api/v1/processor-json?file_hash=...&processor=... +/// Serves raw processor output JSON files from the output directory. +async fn get_processor_json( + Query(params): Query>, +) -> Result, (StatusCode, Json)> { + let file_uuid = params.get("file_hash").ok_or(( + StatusCode::BAD_REQUEST, + Json(serde_json::json!({"error": "Missing file_hash"})), + ))?; + let processor = params.get("processor").ok_or(( + StatusCode::BAD_REQUEST, + Json(serde_json::json!({"error": "Missing processor"})), + ))?; + + // Map processor name to output file extension. + let ext = match processor.as_str() { + "asrx" => "asrx", + "face" => "face", + "face_cluster" => "face_cluster", + "face_trace" | "face_traced" => "face_traced", + "ocr" => "ocr", + "cut" => "cut", + "scenes" | "scene_vlm" => "scenes", + "probe" => "probe", + "tkg" => "tkg", + other => other, + }; + let output_dir = crate::core::config::OUTPUT_DIR.as_str(); + let path = format!("{}/{}.{}.json", output_dir.trim_end_matches('/'), file_uuid, ext); + + match std::fs::read_to_string(&path) { + Ok(content) => match serde_json::from_str(&content) { + Ok(json) => Ok(Json(json)), + Err(e) => Err(( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({"error": format!("Parse error: {}", e)})), + )), + }, + Err(_) => Err(( + StatusCode::NOT_FOUND, + Json(serde_json::json!({"error": format!("No {} output for {}", processor, file_uuid)})), + )), + } +} + async fn get_processor_counts( State(state): State, Path(file_uuid): Path, @@ -821,8 +866,14 @@ async fn get_processor_counts( for processor in &processors { let proc_name = processor.as_str(); + // resolve output filename: some processors write under a different + // extension than their queue name (face_trace → face_traced.json). + let json_ext = match proc_name { + "face_trace" => "face_traced", + other => other, + }; let json_path = - std::path::Path::new(&output_dir).join(format!("{}.{}.json", file_uuid, proc_name)); + std::path::Path::new(&output_dir).join(format!("{}.{}.json", file_uuid, json_ext)); let has_json = json_path.exists(); let mut frame_count = None; @@ -1016,6 +1067,10 @@ pub fn processing_routes() -> Router { "/api/v1/file/:file_uuid/processor-counts", get(get_processor_counts), ) + .route( + "/api/v1/processor-json", + get(get_processor_json), + ) .route("/api/v1/file/:file_uuid/verify", get(verify_file_handler)) // [DISABLED] FS VLM Summary API removed (2026-09-22) // .route(