fix: appearance API per-library output path(與 trace_profile/face_cluster 同樣的 per-library fallback 模式)
Core Test / lint-and-test (push) Has been cancelled
Cross-Project Integration / integration (push) Has been cancelled

This commit is contained in:
Accusys
2026-11-17 19:46:13 +08:00
parent be16a588c2
commit 2a8bd88a3e
+20 -12
View File
@@ -1888,21 +1888,29 @@ async fn get_appearance_handler(
Path(file_uuid): Path<String>,
Query(params): Query<AppearanceQuery>,
) -> Result<axum::Json<AppearanceResponse>, StatusCode> {
use crate::core::config::OUTPUT_DIR;
let output_dir = OUTPUT_DIR.as_str();
// Try per-library dir first, fallback to global OUTPUT_DIR
let per_lib = crate::core::config::get_output_dir_for_file(&file_uuid, _state.db.pool()).await;
let appearance_path =
std::path::Path::new(output_dir).join(format!("{}.appearance.json", file_uuid));
std::path::Path::new(&per_lib).join(format!("{}.appearance.json", file_uuid));
if !appearance_path.exists() {
tracing::error!(
"[get_appearance] File not found: {}",
appearance_path.display()
);
// Fallback: global OUTPUT_DIR
let global = crate::core::config::OUTPUT_DIR.as_str();
let global_path = std::path::Path::new(global).join(format!("{}.appearance.json", file_uuid));
if global_path.exists() {
// use global_path
return read_appearance(&global_path, params.frame).await;
}
return Err(StatusCode::NOT_FOUND);
}
let content = std::fs::read_to_string(&appearance_path).map_err(|e| {
read_appearance(&appearance_path, params.frame).await
}
async fn read_appearance(
path: &std::path::Path,
frame: i64,
) -> Result<axum::Json<AppearanceResponse>, StatusCode> {
let content = std::fs::read_to_string(path).map_err(|e| {
tracing::error!("[get_appearance] Failed to read appearance.json: {}", e);
StatusCode::INTERNAL_SERVER_ERROR
})?;
@@ -1919,7 +1927,7 @@ async fn get_appearance_handler(
let frame_data = frames
.iter()
.find(|f| f.get("frame").and_then(|v| v.as_i64()) == Some(params.frame))
.find(|f| f.get("frame").and_then(|v| v.as_i64()) == Some(frame))
.ok_or(StatusCode::NOT_FOUND)?;
let hsv_histogram = frame_data
@@ -1937,7 +1945,7 @@ async fn get_appearance_handler(
.unwrap_or_default();
Ok(axum::Json(AppearanceResponse {
frame: params.frame,
frame,
dominant_colors: vec![],
hsv_histogram,
}))