diff --git a/src/api/processing.rs b/src/api/processing.rs index c4ebf432..7985c6bf 100644 --- a/src/api/processing.rs +++ b/src/api/processing.rs @@ -23,6 +23,28 @@ use crate::core::probe::ffprobe; use crate::worker::processor; use crate::{Embedder, FileManager}; +fn delete_output_files_for_uuid(uuid: &str, output_dir: &str) -> u64 { + let mut deleted_count = 0u64; + if let Ok(entries) = std::fs::read_dir(output_dir) { + for entry in entries.flatten() { + let path = entry.path(); + if let Some(name) = path.file_name().and_then(|n| n.to_str()) { + let is_uuid_file = name.starts_with(uuid) && !path.is_dir(); + let is_pipeline_log = name.starts_with("pipeline_") + && name.contains(uuid) + && name.ends_with(".log"); + if is_uuid_file || is_pipeline_log { + if std::fs::remove_file(&path).is_ok() { + deleted_count += 1; + tracing::info!("[FORCE_RESCAN] Deleted output file: {}", name); + } + } + } + } + } + deleted_count +} + #[derive(Debug, Serialize)] struct JobListResponse { jobs: Vec, @@ -122,6 +144,8 @@ struct ProcessRequest { rules: Option>, processors: Option>, face_settings: Option, + #[serde(default)] + force: bool, } #[derive(Debug, Serialize, Deserialize)] @@ -321,6 +345,18 @@ async fn trigger_processing( })?; tracing::info!("[TRIGGER] Cleaned processor_results for job {}", job_id); + // If force=true, delete output files to force re-processing + if req.force { + let output_dir = std::env::var("MOMENTRY_OUTPUT_DIR") + .unwrap_or_else(|_| "/Users/accusys/momentry/output".to_string()); + let deleted_count = delete_output_files_for_uuid(&file_uuid, &output_dir); + tracing::info!( + "[TRIGGER] Force re-scan: deleted {} output files for {}", + deleted_count, + file_uuid + ); + } + // Update existing job with new face_settings if provided if let Some(ref fs_json) = face_settings_json { sqlx::query(&format!(