fix: face/trace 縮圖 API 使用 per-library 路徑
- face_thumbnail: .faces cache + trace_{id}/key_face.jpg 改 per-library + global fallback
- trace_thumbnail: key_face.jpg 改 per-library + global fallback
- 驗證: test library face 縮圖 HTTP 200 (422x422 JPEG), demo 也正常
This commit is contained in:
+20
-11
@@ -1058,14 +1058,18 @@ async fn thumbnail_by_path(
|
||||
/// 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>,
|
||||
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)
|
||||
// Try per-library dir first, then global OUTPUT_DIR (legacy)
|
||||
let per_lib = crate::core::config::get_output_dir_for_file(&file_uuid, state.db.pool()).await;
|
||||
let global_dir = crate::core::config::OUTPUT_DIR.as_str();
|
||||
let rel = std::path::PathBuf::from(&file_uuid)
|
||||
.join(format!("trace_{}", trace_id))
|
||||
.join("key_face.jpg");
|
||||
let candidate1 = std::path::PathBuf::from(&per_lib).join(&rel);
|
||||
let candidate2 = std::path::PathBuf::from(global_dir).join(&rel);
|
||||
let key_face_path = if candidate1.exists() { candidate1 } else { candidate2 };
|
||||
|
||||
if !key_face_path.exists() {
|
||||
return Err(StatusCode::NOT_FOUND);
|
||||
@@ -1185,14 +1189,17 @@ async fn face_thumbnail(
|
||||
|
||||
// Step 1: Check for pre-stored face crop if trace_id is provided
|
||||
if let Some(trace_id) = q.trace_id {
|
||||
let output_dir = crate::core::config::OUTPUT_DIR.as_str();
|
||||
let per_lib_dir = crate::core::config::get_output_dir_for_file(&file_uuid, state.db.pool()).await;
|
||||
let global_dir = crate::core::config::OUTPUT_DIR.as_str();
|
||||
|
||||
// Check .faces cache first
|
||||
let cached_path = std::path::PathBuf::from(output_dir)
|
||||
.join(".faces")
|
||||
// Check .faces cache first (per-library + global)
|
||||
let rel_cache = std::path::PathBuf::from(".faces")
|
||||
.join(&file_uuid)
|
||||
.join(trace_id.to_string())
|
||||
.join(format!("{}.jpg", frame));
|
||||
let cached_path_c1 = std::path::PathBuf::from(&per_lib_dir).join(&rel_cache);
|
||||
let cached_path_c2 = std::path::PathBuf::from(global_dir).join(&rel_cache);
|
||||
let cached_path = if cached_path_c1.exists() { cached_path_c1 } else { cached_path_c2.clone() };
|
||||
|
||||
if cached_path.exists() {
|
||||
tracing::debug!(
|
||||
@@ -1212,11 +1219,13 @@ async fn face_thumbnail(
|
||||
return Ok(image_response(bytes));
|
||||
}
|
||||
|
||||
// Fallback: check trace directory for key_face.jpg
|
||||
let trace_key_face = std::path::PathBuf::from(output_dir)
|
||||
.join(&file_uuid)
|
||||
// Fallback: check trace directory for key_face.jpg (per-library + global)
|
||||
let rel_trace = std::path::PathBuf::from(&file_uuid)
|
||||
.join(format!("trace_{}", trace_id))
|
||||
.join("key_face.jpg");
|
||||
let tc1 = std::path::PathBuf::from(&per_lib_dir).join(&rel_trace);
|
||||
let tc2 = std::path::PathBuf::from(global_dir).join(&rel_trace);
|
||||
let trace_key_face = if tc1.exists() { tc1 } else { tc2 };
|
||||
|
||||
if trace_key_face.exists() {
|
||||
tracing::debug!(
|
||||
|
||||
Reference in New Issue
Block a user