diff --git a/src/api/files.rs b/src/api/files.rs index 4780d6e0..69afc842 100644 --- a/src/api/files.rs +++ b/src/api/files.rs @@ -17,11 +17,18 @@ use crate::core::storage::content_hash; use crate::FileManager; #[derive(Debug, Deserialize)] +struct FaceSettings { + min_confidence: Option, + min_size: Option, +} + +#[derive(Deserialize)] struct RegisterFileRequest { file_path: String, user_id: Option, content_hash: Option, pattern: Option, + face_settings: Option, #[serde(default = "default_force")] force: bool, } @@ -811,7 +818,7 @@ async fn register_file( .flatten(); if let Some(ref vp) = video_path { - if let Ok(job) = auto_state.db.create_monitor_job(&auto_uuid, Some(vp)).await { + if let Ok(job) = auto_state.db.create_monitor_job(&auto_uuid, Some(vp), None).await { tracing::info!("[AUTO-PIPELINE] Job {} created for {}", job.id, auto_uuid); let all_procs: Vec<&str> = vec!["cut", "asr", "asrx", "ocr", "face", "pose", "appearance"]; diff --git a/src/api/processing.rs b/src/api/processing.rs index e2f197e6..7d34430b 100644 --- a/src/api/processing.rs +++ b/src/api/processing.rs @@ -281,7 +281,7 @@ async fn trigger_processing( } else { state .db - .create_monitor_job(&file_uuid, Some(&file_path)) + .create_monitor_job(&file_uuid, Some(&file_path), None) .await .map_err(|e| { tracing::error!( diff --git a/src/core/db/postgres_db.rs b/src/core/db/postgres_db.rs index a10fa65e..1db92772 100644 --- a/src/core/db/postgres_db.rs +++ b/src/core/db/postgres_db.rs @@ -452,6 +452,7 @@ pub struct MonitorJob { pub completed_processors: Vec, pub failed_processors: Vec, pub video_id: Option, + pub face_settings: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -1946,6 +1947,7 @@ impl PostgresDb { &self, uuid: &str, video_path: Option<&str>, + face_settings: Option<&serde_json::Value>, ) -> Result { let videos_table = schema::table_name("videos"); let jobs_table = schema::table_name("monitor_jobs"); @@ -1969,20 +1971,23 @@ impl PostgresDb { .fetch_optional(&self.pool) .await?; + let face_settings_json = face_settings.map(|v| v.to_string()).unwrap_or_else(|| "{\"min_confidence\": 0.75, \"min_size\": 64}".to_string()); + let row = if let Some(job_id) = existing_id { // Update existing job sqlx::query( &format!( r#" - UPDATE {} SET status = 'pending', video_path = $1, video_id = $2, updated_at = NOW() - WHERE id = $3 - RETURNING id, uuid, video_path, status, current_processor, progress_total, progress_current, error_count, last_error, started_at::TEXT, updated_at::TEXT, created_at::TEXT, processors, completed_processors, failed_processors, video_id + UPDATE {} SET status = 'pending', video_path = $1, video_id = $2, face_settings = $3::jsonb, updated_at = NOW() + WHERE id = $4 + RETURNING id, uuid, video_path, status, current_processor, progress_total, progress_current, error_count, last_error, started_at::TEXT, updated_at::TEXT, created_at::TEXT, processors, completed_processors, failed_processors, video_id, face_settings::text "#, jobs_table ) ) .bind(video_path) .bind(video_id_i64) + .bind(&face_settings_json) .bind(job_id) .fetch_one(&self.pool) .await? @@ -1991,9 +1996,9 @@ impl PostgresDb { sqlx::query( &format!( r#" - INSERT INTO {} (uuid, video_path, status, video_id, processors) - VALUES ($1, $2, 'pending', $3, ARRAY['cut','asr','face','ocr','asrx','pose']) - RETURNING id, uuid, video_path, status, current_processor, progress_total, progress_current, error_count, last_error, started_at::TEXT, updated_at::TEXT, created_at::TEXT, processors, completed_processors, failed_processors, video_id + INSERT INTO {} (uuid, video_path, status, video_id, processors, face_settings) + VALUES ($1, $2, 'pending', $3, ARRAY['cut','asr','face','ocr','asrx','pose'], $4::jsonb) + RETURNING id, uuid, video_path, status, current_processor, progress_total, progress_current, error_count, last_error, started_at::TEXT, updated_at::TEXT, created_at::TEXT, processors, completed_processors, failed_processors, video_id, face_settings::text "#, jobs_table ) @@ -2001,6 +2006,7 @@ impl PostgresDb { .bind(uuid) .bind(video_path) .bind(video_id_i64) + .bind(&face_settings_json) .fetch_one(&self.pool) .await? }; @@ -2009,6 +2015,9 @@ impl PostgresDb { let status = MonitorJobStatus::from_db_str(&status_str).unwrap_or(MonitorJobStatus::Pending); + let face_settings_raw: Option = row.get(16); + let face_settings = face_settings_raw.and_then(|s| serde_json::from_str(&s).ok()); + Ok(MonitorJob { id: row.get(0), uuid: row.get(1), @@ -2026,6 +2035,7 @@ impl PostgresDb { completed_processors: row.get::>, _>(13).unwrap_or_default(), failed_processors: row.get::>, _>(14).unwrap_or_default(), video_id: row.get(15), + face_settings, }) } @@ -2120,6 +2130,7 @@ impl PostgresDb { completed_processors: r.get::>, _>(13).unwrap_or_default(), failed_processors: r.get::>, _>(14).unwrap_or_default(), video_id: r.get(15), + face_settings: r.get::, _>(16).and_then(|s| serde_json::from_str(&s).ok()), })) } else { Ok(None) @@ -2168,6 +2179,7 @@ impl PostgresDb { completed_processors: r.get::>, _>(13).unwrap_or_default(), failed_processors: r.get::>, _>(14).unwrap_or_default(), video_id: r.get(15), + face_settings: r.get::, _>(16).and_then(|s| serde_json::from_str(&s).ok()), } }) .collect(); @@ -4906,6 +4918,7 @@ mod tests { completed_processors: vec!["asr".to_string()], failed_processors: vec![], video_id: None, + face_settings: None, }; let json = serde_json::to_string(&job).unwrap();