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)
This commit is contained in:
@@ -71,14 +71,42 @@ launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.momentry.worker.plis
|
|||||||
|
|
||||||
## API 參數設定
|
## 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**:
|
**Request Body**:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"file_uuid": "0489e104d7d1e11e613da01f7aa130ca",
|
|
||||||
"processors": ["face"],
|
"processors": ["face"],
|
||||||
"face_settings": {
|
"face_settings": {
|
||||||
"min_confidence": 0.5,
|
"min_confidence": 0.5,
|
||||||
@@ -89,11 +117,10 @@ launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.momentry.worker.plis
|
|||||||
|
|
||||||
**完整 curl 範例**:
|
**完整 curl 範例**:
|
||||||
```bash
|
```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 "Authorization: Bearer muser_demo_key_32chars_abcdef1234567890" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{
|
-d '{
|
||||||
"file_uuid": "0489e104d7d1e11e613da01f7aa130ca",
|
|
||||||
"processors": ["face"],
|
"processors": ["face"],
|
||||||
"face_settings": {
|
"face_settings": {
|
||||||
"min_confidence": 0.5,
|
"min_confidence": 0.5,
|
||||||
|
|||||||
+8
-1
@@ -805,6 +805,13 @@ async fn register_file(
|
|||||||
{
|
{
|
||||||
let auto_uuid = resp.file_uuid.clone();
|
let auto_uuid = resp.file_uuid.clone();
|
||||||
let auto_state = state.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::spawn(async move {
|
||||||
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
|
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
|
||||||
let video_path: Option<String> = sqlx::query_scalar(&format!(
|
let video_path: Option<String> = sqlx::query_scalar(&format!(
|
||||||
@@ -818,7 +825,7 @@ async fn register_file(
|
|||||||
.flatten();
|
.flatten();
|
||||||
|
|
||||||
if let Some(ref vp) = video_path {
|
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);
|
tracing::info!("[AUTO-PIPELINE] Job {} created for {}", job.id, auto_uuid);
|
||||||
let all_procs: Vec<&str> =
|
let all_procs: Vec<&str> =
|
||||||
vec!["cut", "asr", "asrx", "ocr", "face", "pose", "appearance"];
|
vec!["cut", "asr", "asrx", "ocr", "face", "pose", "appearance"];
|
||||||
|
|||||||
+31
-1
@@ -108,10 +108,17 @@ struct WatcherAutoRegisterToggleResponse {
|
|||||||
message: String,
|
message: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
struct FaceSettings {
|
||||||
|
min_confidence: Option<f64>,
|
||||||
|
min_size: Option<i32>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
struct ProcessRequest {
|
struct ProcessRequest {
|
||||||
rules: Option<Vec<String>>,
|
rules: Option<Vec<String>>,
|
||||||
processors: Option<Vec<String>>,
|
processors: Option<Vec<String>>,
|
||||||
|
face_settings: Option<FaceSettings>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
@@ -260,6 +267,14 @@ async fn trigger_processing(
|
|||||||
.await
|
.await
|
||||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
.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 {
|
if let Some(job_id) = existing_id {
|
||||||
// Clean up stale processor_results from previous runs
|
// Clean up stale processor_results from previous runs
|
||||||
// Old entries with status='running' from a dead worker session
|
// Old entries with status='running' from a dead worker session
|
||||||
@@ -278,10 +293,25 @@ async fn trigger_processing(
|
|||||||
StatusCode::INTERNAL_SERVER_ERROR
|
StatusCode::INTERNAL_SERVER_ERROR
|
||||||
})?;
|
})?;
|
||||||
tracing::info!("[TRIGGER] Cleaned processor_results for job {}", job_id);
|
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 {
|
} else {
|
||||||
state
|
state
|
||||||
.db
|
.db
|
||||||
.create_monitor_job(&file_uuid, Some(&file_path), None)
|
.create_monitor_job(&file_uuid, Some(&file_path), face_settings_json.as_ref())
|
||||||
.await
|
.await
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
tracing::error!(
|
tracing::error!(
|
||||||
|
|||||||
Reference in New Issue
Block a user