From c4fbbfda4aa5b25bc4e3783e3c54520780905d66 Mon Sep 17 00:00:00 2001 From: Accusys Date: Thu, 19 Nov 2026 13:35:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20pipeline=20log=20=E5=AF=AB=E5=85=A5=20ou?= =?UTF-8?q?tput=20root=20+=20processor-counts/json=20=E4=BD=BF=E7=94=A8=20?= =?UTF-8?q?per-library=20=E8=B7=AF=E5=BE=91=20-=20write=5Fpipeline=5Ftimel?= =?UTF-8?q?ine:=20log=20=E5=AF=AB=E5=88=B0=20~/momentry/output=20(parent?= =?UTF-8?q?=20of=20per-lib=20dir)=20-=20get=5Fprocessor=5Fcounts:=20?= =?UTF-8?q?=E7=94=A8=20get=5Foutput=5Fdir=5Ffor=5Ffile=20+=20global=20fall?= =?UTF-8?q?back=20-=20get=5Fprocessor=5Fjson:=20=E5=8A=A0=20State,=20per-l?= =?UTF-8?q?ibrary=20=E5=84=AA=E5=85=88=20+=20global=20fallback=20-=20delet?= =?UTF-8?q?e=5Foutput=5Ffiles=5Ffor=5Fuuid:=20=E5=90=8C=E6=99=82=E6=8E=83?= =?UTF-8?q?=20output=20root=20=E6=B8=85=20pipeline=20log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/processing.rs | 42 ++++++++++++++++++++++++++++---------- src/core/db/postgres_db.rs | 10 +++++++-- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/api/processing.rs b/src/api/processing.rs index 5552171a..a019ab55 100644 --- a/src/api/processing.rs +++ b/src/api/processing.rs @@ -25,6 +25,14 @@ use crate::{Embedder, FileManager}; fn delete_output_files_for_uuid(uuid: &str, output_dir: &str) -> u64 { let mut deleted_count = 0u64; + // Also scan output root (parent of per-library dir) for pipeline logs + let mut dirs = vec![output_dir.to_string()]; + if let Some(parent) = std::path::Path::new(output_dir).parent() { + if parent.file_name().and_then(|n| n.to_str()) == Some("output") { + dirs.push(parent.to_string_lossy().to_string()); + } + } + for output_dir in &dirs { if let Ok(entries) = std::fs::read_dir(output_dir) { for entry in entries.flatten() { let path = entry.path(); @@ -41,6 +49,7 @@ fn delete_output_files_for_uuid(uuid: &str, output_dir: &str) -> u64 { } } } + } deleted_count } @@ -999,6 +1008,7 @@ async fn get_output_completeness( } async fn get_processor_json( + State(state): State, Query(params): Query>, ) -> Result, (StatusCode, Json)> { let file_uuid = params.get("file_hash").ok_or(( @@ -1023,8 +1033,16 @@ async fn get_processor_json( "tkg" => "tkg", other => other, }; - let output_dir = crate::core::config::OUTPUT_DIR.as_str(); - let path = format!("{}/{}.{}.json", output_dir.trim_end_matches('/'), file_uuid, ext); + // Try per-library dir first, then global OUTPUT_DIR (legacy) + 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(); + let candidates = [ + format!("{}/{}.{}.json", per_lib_dir.trim_end_matches('/'), file_uuid, ext), + format!("{}/{}.{}.json", global_dir.trim_end_matches('/'), file_uuid, ext), + ]; + let path = candidates.iter().find(|p| std::path::Path::new(p).exists()) + .cloned() + .unwrap_or_else(|| candidates[0].clone()); match std::fs::read_to_string(&path) { Ok(content) => match serde_json::from_str(&content) { @@ -1067,37 +1085,39 @@ async fn get_processor_counts( }); let file_uuid = full_uuid.ok_or(StatusCode::NOT_FOUND)?; - let output_dir = crate::core::config::OUTPUT_DIR.to_string(); + // Use per-library output dir (test files live in output/test, not output/demo) + 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(); let processors = crate::core::db::ProcessorType::all(); let mut results = Vec::new(); for processor in &processors { let proc_name = processor.as_str(); - // resolve output filename: some processors write under a different - // extension than their queue name (face_trace → face_traced.json). let json_ext = match proc_name { "face_trace" => "face_traced", other => other, }; - let json_path = - std::path::Path::new(&output_dir).join(format!("{}.{}.json", file_uuid, json_ext)); + let filename = format!("{}.{}.json", file_uuid, json_ext); + let json_path = std::path::Path::new(&per_lib_dir).join(&filename); + let fallback_path = std::path::Path::new(global_dir).join(&filename); + let effective_path = if json_path.exists() { json_path } else { fallback_path }; - let has_json = json_path.exists(); + let has_json = effective_path.exists(); let mut frame_count = None; let mut segment_count = None; let mut chunk_count = None; let mut last_modified = None; if has_json { - if let Ok(metadata) = std::fs::metadata(&json_path) { + if let Ok(metadata) = std::fs::metadata(&effective_path) { if let Ok(modified) = metadata.modified() { let chrono_dt: chrono::DateTime = modified.into(); last_modified = Some(chrono_dt.to_rfc3339()); } } - if let Ok(content) = std::fs::read_to_string(&json_path) { + if let Ok(content) = std::fs::read_to_string(&effective_path) { if let Ok(json) = serde_json::from_str::(&content) { // CUT: prioritize scenes count over frame_count if proc_name == "cut" { @@ -1166,7 +1186,7 @@ async fn get_processor_counts( Ok(Json(ProcessorCountsResponse { file_uuid, - output_dir, + output_dir: per_lib_dir, processors: results, })) } diff --git a/src/core/db/postgres_db.rs b/src/core/db/postgres_db.rs index 7e9f23d0..0a7321e7 100644 --- a/src/core/db/postgres_db.rs +++ b/src/core/db/postgres_db.rs @@ -3976,8 +3976,14 @@ pub async fn get_session_by_id( "processor": processor, "status": status, }); - let path = std::path::Path::new(crate::core::config::OUTPUT_DIR.as_str()) - .join(format!("pipeline_{}.log", uuid)); + // Pipeline timeline logs go to the output ROOT (parent of per-library dir). + // OUTPUT_DIR may be a per-library dir like output/demo — strip it to output/. + let output_root = std::path::Path::new(crate::core::config::OUTPUT_DIR.as_str()) + .parent() + .filter(|p| p.file_name().and_then(|n| n.to_str()) == Some("output")) + .map(|p| p.to_path_buf()) + .unwrap_or_else(|| std::path::PathBuf::from(crate::core::config::OUTPUT_DIR.as_str())); + let path = output_root.join(format!("pipeline_{}.log", uuid)); if let Ok(mut file) = std::fs::OpenOptions::new() .create(true) .append(true)