From 2117ca60b83f0c6bb4e8c60317dd69edc247a590 Mon Sep 17 00:00:00 2001 From: Accusys Date: Wed, 5 Aug 2026 02:42:38 +0800 Subject: [PATCH] fix: trace thumbnail now uses trace_profile key_face.jpg for consistency - Thumbnail endpoint was using select_rep_face (blurdetect) which could pick a different frame than the trace_profile's key_frame/key_face - This caused mismatch between Face Detail modal and thumbnail in trace list - Fix: add Step 1.5 to check trace_profile's key_face.jpg before falling back to select_rep_face - Ensures thumbnail always matches what Face Detail modal shows Verified: trace_21 thumbnail now matches key_face.jpg (same hash) --- src/api/trace_agent_api.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/api/trace_agent_api.rs b/src/api/trace_agent_api.rs index e522e2b8..981bed10 100644 --- a/src/api/trace_agent_api.rs +++ b/src/api/trace_agent_api.rs @@ -768,6 +768,28 @@ async fn get_trace_thumbnail_inner( } } + // Step 1.5: Check trace_profile's key_face.jpg for consistency with Face Detail modal + let profile_trace_dir = std::path::PathBuf::from(output_dir) + .join(&file_uuid) + .join(format!("trace_{}", trace_id)); + let key_face_path = profile_trace_dir.join("key_face.jpg"); + if key_face_path.exists() { + if let Ok(bytes) = tokio::fs::read(&key_face_path).await { + if crate::core::thumbnail::validator::validate_jpeg(&bytes).is_ok() { + tracing::info!( + "[trace_thumbnail] Using trace_profile key_face.jpg: {}", + key_face_path.display() + ); + return 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()); + } + } + } + // Step 2: Fallback to ffmpeg on-demand extraction let sel = select_rep_face(state.db.pool(), &file_uuid, trace_id, |e| { (