fix: Face processor now saves status and total_faces to face.json
This commit is contained in:
@@ -87,6 +87,10 @@ pub fn bbox_routes() -> Router<crate::api::types::AppState> {
|
||||
"/api/v1/file/:file_uuid/chunk/:chunk_id/thumbnail",
|
||||
get(chunk_thumbnail),
|
||||
)
|
||||
.route(
|
||||
"/api/v1/file/:file_uuid/scenes/:filename",
|
||||
get(scene_thumbnail),
|
||||
)
|
||||
.route("/api/v1/file/:file_uuid/clip", get(video_clip))
|
||||
}
|
||||
|
||||
@@ -955,6 +959,59 @@ async fn trace_thumbnail(
|
||||
.unwrap())
|
||||
}
|
||||
|
||||
/// Serve a scene frame image (`scene_*.jpg`) directly from the output dir.
|
||||
/// Path mirrors `thumbnail_url` produced by the VLM scene search API.
|
||||
/// e.g. /api/v1/file/{file_uuid}/scenes/scene_000.jpg
|
||||
async fn scene_thumbnail(
|
||||
State(_state): State<crate::api::types::AppState>,
|
||||
Path((file_uuid, filename)): Path<(String, String)>,
|
||||
) -> Result<impl IntoResponse, StatusCode> {
|
||||
let output_dir = crate::core::config::OUTPUT_DIR.as_str();
|
||||
|
||||
// Security: only allow scene_*.jpg filenames (no path traversal)
|
||||
let safe_name = filename
|
||||
.strip_prefix("scene_")
|
||||
.and_then(|rest| rest.strip_suffix(".jpg"))
|
||||
.filter(|rest| !rest.is_empty() && rest.chars().all(|c| c.is_ascii_digit()))
|
||||
.map(|_| filename.clone())
|
||||
.ok_or(StatusCode::NOT_FOUND)?;
|
||||
|
||||
let file_path = std::path::PathBuf::from(output_dir)
|
||||
.join(&file_uuid)
|
||||
.join("scenes")
|
||||
.join(&safe_name);
|
||||
|
||||
if !file_path.exists() {
|
||||
return Err(StatusCode::NOT_FOUND);
|
||||
}
|
||||
|
||||
let bytes = tokio::fs::read(&file_path).await.map_err(|e| {
|
||||
tracing::warn!(
|
||||
"[scene-thumb] Failed to read {}: {}",
|
||||
file_path.display(),
|
||||
e
|
||||
);
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
|
||||
crate::core::thumbnail::validator::validate_jpeg(&bytes).map_err(|e| {
|
||||
tracing::warn!("[scene-thumb] JPEG validation failed: {}", e);
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
|
||||
// Generate ETag from file content (first 16 chars of sha256)
|
||||
use sha2::{Digest, Sha256};
|
||||
let etag = format!("\"{}\"", hex::encode(&Sha256::digest(&bytes)[..8]));
|
||||
|
||||
Ok(Response::builder()
|
||||
.status(StatusCode::OK)
|
||||
.header(header::CONTENT_TYPE, "image/jpeg")
|
||||
.header(header::CACHE_CONTROL, "no-cache, must-revalidate")
|
||||
.header(header::ETAG, etag)
|
||||
.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