perf: add /api/v1/trace-thumb/:uuid/:tid endpoint
Direct access to trace key_face.jpg — simpler URL, faster routing.
Response: ~8ms (read from disk, no ffmpeg).
Studio can use: /api/v1/trace-thumb/{file_uuid}/{trace_id}
Instead of: /api/v1/face-thumbnail?uuid={uuid}&trace_id={tid}&frame={frame}
This commit is contained in:
@@ -52,6 +52,7 @@ fn ffmpeg_cmd() -> std::process::Command {
|
||||
pub fn bbox_routes() -> Router<crate::api::types::AppState> {
|
||||
Router::new()
|
||||
.route("/api/v1/face-thumbnail", get(face_thumbnail_compat))
|
||||
.route("/api/v1/trace-thumb/:file_uuid/:trace_id", get(trace_thumbnail))
|
||||
.route(
|
||||
"/api/v1/file/:file_uuid/video/bbox",
|
||||
get(bbox_overlay_video),
|
||||
@@ -869,6 +870,40 @@ async fn face_thumbnail_compat(
|
||||
face_thumbnail(State(state), Path(file_uuid), Query(q)).await
|
||||
}
|
||||
|
||||
/// Direct access to trace key_face.jpg — bypasses ffmpeg, reads pre-cached file.
|
||||
/// Used by Studio for fast face group thumbnail loading.
|
||||
async fn trace_thumbnail(
|
||||
State(_state): State<crate::api::types::AppState>,
|
||||
Path((file_uuid, trace_id)): Path<(String, i32)>,
|
||||
) -> Result<impl IntoResponse, StatusCode> {
|
||||
let output_dir = crate::core::config::OUTPUT_DIR.as_str();
|
||||
let key_face_path = std::path::PathBuf::from(output_dir)
|
||||
.join(&file_uuid)
|
||||
.join(format!("trace_{}", trace_id))
|
||||
.join("key_face.jpg");
|
||||
|
||||
if !key_face_path.exists() {
|
||||
return Err(StatusCode::NOT_FOUND);
|
||||
}
|
||||
|
||||
let bytes = tokio::fs::read(&key_face_path).await.map_err(|e| {
|
||||
tracing::warn!("[trace-thumb] Failed to read {}: {}", key_face_path.display(), e);
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
|
||||
crate::core::thumbnail::validator::validate_jpeg(&bytes).map_err(|e| {
|
||||
tracing::warn!("[trace-thumb] JPEG validation failed: {}", e);
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
|
||||
Ok(Response::builder()
|
||||
.status(StatusCode::OK)
|
||||
.header(header::CONTENT_TYPE, "image/jpeg")
|
||||
.header(header::CACHE_CONTROL, "public, max-age=86400")
|
||||
.body(Body::from(bytes))
|
||||
.unwrap())
|
||||
}
|
||||
|
||||
async fn face_thumbnail(
|
||||
State(state): State<crate::api::types::AppState>,
|
||||
Path(file_uuid): Path<String>,
|
||||
|
||||
Reference in New Issue
Block a user