From 658f50950053699c160f66a599d63a052897d4fa Mon Sep 17 00:00:00 2001 From: Accusys Date: Sat, 8 Aug 2026 22:16:06 +0800 Subject: [PATCH] fix: pass face_settings to create_monitor_job in register and process endpoints - files.rs: register_file now converts FaceSettings to json and passes to create_monitor_job - processing.rs: ProcessRequest now includes face_settings field - processing.rs: trigger_processing now passes face_settings to create_monitor_job and updates existing jobs - docs: updated API examples to use correct endpoints (/api/v1/files/register and /api/v1/files/:uuid/process) --- .../2026-08-08_face_settings_studio_guide.md | 37 ++++++++++++++++--- src/api/files.rs | 9 ++++- src/api/processing.rs | 32 +++++++++++++++- 3 files changed, 71 insertions(+), 7 deletions(-) diff --git a/docs_v1.0/M4_workspace/2026-08-08_face_settings_studio_guide.md b/docs_v1.0/M4_workspace/2026-08-08_face_settings_studio_guide.md index aff4b963..777dacb5 100644 --- a/docs_v1.0/M4_workspace/2026-08-08_face_settings_studio_guide.md +++ b/docs_v1.0/M4_workspace/2026-08-08_face_settings_studio_guide.md @@ -71,14 +71,42 @@ launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.momentry.worker.plis ## API 參數設定 -### 創建 Job 時指定 face_settings +### 方法 1:Register 時指定 face_settings -**Endpoint**: `POST /api/v1/jobs` +**Endpoint**: `POST /api/v1/files/register` + +**Request Body**: +```json +{ + "file_path": "/path/to/video.mp4", + "face_settings": { + "min_confidence": 0.5, + "min_size": 1 + } +} +``` + +**完整 curl 範例**: +```bash +curl -s -X POST http://localhost:3002/api/v1/files/register \ + -H "Authorization: Bearer muser_demo_key_32chars_abcdef1234567890" \ + -H "Content-Type: application/json" \ + -d '{ + "file_path": "/Users/accusys/momentry/var/sftpgo/data/demo/Accusys-WD_FilmRiot_test.mp4", + "face_settings": { + "min_confidence": 0.5, + "min_size": 1 + } + }' +``` + +### 方法 2:Deep Scan 時指定 face_settings + +**Endpoint**: `POST /api/v1/files/{file_uuid}/process` **Request Body**: ```json { - "file_uuid": "0489e104d7d1e11e613da01f7aa130ca", "processors": ["face"], "face_settings": { "min_confidence": 0.5, @@ -89,11 +117,10 @@ launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.momentry.worker.plis **完整 curl 範例**: ```bash -curl -s -X POST http://localhost:3002/api/v1/jobs \ +curl -s -X POST http://localhost:3002/api/v1/files/0489e104d7d1e11e613da01f7aa130ca/process \ -H "Authorization: Bearer muser_demo_key_32chars_abcdef1234567890" \ -H "Content-Type: application/json" \ -d '{ - "file_uuid": "0489e104d7d1e11e613da01f7aa130ca", "processors": ["face"], "face_settings": { "min_confidence": 0.5, diff --git a/src/api/files.rs b/src/api/files.rs index 7b186554..4a7bd5a3 100644 --- a/src/api/files.rs +++ b/src/api/files.rs @@ -805,6 +805,13 @@ async fn register_file( { let auto_uuid = resp.file_uuid.clone(); let auto_state = state.clone(); + // Convert face_settings to serde_json::Value for create_monitor_job + let face_settings_json = req.face_settings.as_ref().map(|fs| { + serde_json::json!({ + "min_confidence": fs.min_confidence.unwrap_or(0.75), + "min_size": fs.min_size.unwrap_or(64) + }) + }); tokio::spawn(async move { tokio::time::sleep(std::time::Duration::from_secs(2)).await; let video_path: Option = sqlx::query_scalar(&format!( @@ -818,7 +825,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), None).await { + if let Ok(job) = auto_state.db.create_monitor_job(&auto_uuid, Some(vp), face_settings_json.as_ref()).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 128f5346..a57925be 100644 --- a/src/api/processing.rs +++ b/src/api/processing.rs @@ -108,10 +108,17 @@ struct WatcherAutoRegisterToggleResponse { message: String, } +#[derive(Debug, Deserialize)] +struct FaceSettings { + min_confidence: Option, + min_size: Option, +} + #[derive(Debug, Deserialize)] struct ProcessRequest { rules: Option>, processors: Option>, + face_settings: Option, } #[derive(Debug, Serialize, Deserialize)] @@ -260,6 +267,14 @@ async fn trigger_processing( .await .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; + // Convert face_settings to serde_json::Value for create_monitor_job + let face_settings_json = req.face_settings.as_ref().map(|fs| { + serde_json::json!({ + "min_confidence": fs.min_confidence.unwrap_or(0.75), + "min_size": fs.min_size.unwrap_or(64) + }) + }); + if let Some(job_id) = existing_id { // Clean up stale processor_results from previous runs // Old entries with status='running' from a dead worker session @@ -278,10 +293,25 @@ async fn trigger_processing( StatusCode::INTERNAL_SERVER_ERROR })?; tracing::info!("[TRIGGER] Cleaned processor_results for job {}", job_id); + + // Update existing job with new face_settings if provided + if let Some(ref fs_json) = face_settings_json { + sqlx::query(&format!( + "UPDATE {monitor_jobs_table} SET face_settings = $1::jsonb WHERE id = $2" + )) + .bind(&fs_json.to_string()) + .bind(job_id) + .execute(state.db.pool()) + .await + .map_err(|e| { + tracing::error!("[TRIGGER] Failed to update face_settings for job {}: {}", job_id, e); + StatusCode::INTERNAL_SERVER_ERROR + })?; + } } else { state .db - .create_monitor_job(&file_uuid, Some(&file_path), None) + .create_monitor_job(&file_uuid, Some(&file_path), face_settings_json.as_ref()) .await .map_err(|e| { tracing::error!(