fix: appearance API per-library output path(與 trace_profile/face_cluster 同樣的 per-library fallback 模式)
This commit is contained in:
+20
-12
@@ -1888,21 +1888,29 @@ async fn get_appearance_handler(
|
|||||||
Path(file_uuid): Path<String>,
|
Path(file_uuid): Path<String>,
|
||||||
Query(params): Query<AppearanceQuery>,
|
Query(params): Query<AppearanceQuery>,
|
||||||
) -> Result<axum::Json<AppearanceResponse>, StatusCode> {
|
) -> Result<axum::Json<AppearanceResponse>, StatusCode> {
|
||||||
use crate::core::config::OUTPUT_DIR;
|
// 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 output_dir = OUTPUT_DIR.as_str();
|
|
||||||
let appearance_path =
|
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() {
|
if !appearance_path.exists() {
|
||||||
tracing::error!(
|
// Fallback: global OUTPUT_DIR
|
||||||
"[get_appearance] File not found: {}",
|
let global = crate::core::config::OUTPUT_DIR.as_str();
|
||||||
appearance_path.display()
|
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);
|
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);
|
tracing::error!("[get_appearance] Failed to read appearance.json: {}", e);
|
||||||
StatusCode::INTERNAL_SERVER_ERROR
|
StatusCode::INTERNAL_SERVER_ERROR
|
||||||
})?;
|
})?;
|
||||||
@@ -1919,7 +1927,7 @@ async fn get_appearance_handler(
|
|||||||
|
|
||||||
let frame_data = frames
|
let frame_data = frames
|
||||||
.iter()
|
.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)?;
|
.ok_or(StatusCode::NOT_FOUND)?;
|
||||||
|
|
||||||
let hsv_histogram = frame_data
|
let hsv_histogram = frame_data
|
||||||
@@ -1937,7 +1945,7 @@ async fn get_appearance_handler(
|
|||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
Ok(axum::Json(AppearanceResponse {
|
Ok(axum::Json(AppearanceResponse {
|
||||||
frame: params.frame,
|
frame,
|
||||||
dominant_colors: vec![],
|
dominant_colors: vec![],
|
||||||
hsv_histogram,
|
hsv_histogram,
|
||||||
}))
|
}))
|
||||||
|
|||||||
Reference in New Issue
Block a user