feat: add sync-status endpoint to update file status based on processor files
This commit is contained in:
@@ -1602,4 +1602,55 @@ pub fn file_routes() -> Router<AppState> {
|
|||||||
"/api/v1/file/:file_uuid/metadata",
|
"/api/v1/file/:file_uuid/metadata",
|
||||||
post(update_file_metadata),
|
post(update_file_metadata),
|
||||||
)
|
)
|
||||||
|
.route(
|
||||||
|
"/api/v1/file/:file_uuid/sync-status",
|
||||||
|
post(sync_file_status),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn sync_file_status(
|
||||||
|
Path(file_uuid): Path<String>,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
) -> Result<Json<serde_json::Value>, StatusCode> {
|
||||||
|
use crate::core::config::OUTPUT_DIR;
|
||||||
|
|
||||||
|
let output_dir = OUTPUT_DIR.as_str();
|
||||||
|
let required_processors = ["face.json", "asrx.json", "ocr.json", "pose.json", "appearance.json"];
|
||||||
|
|
||||||
|
let mut completed_count = 0;
|
||||||
|
for processor in &required_processors {
|
||||||
|
let path = std::path::Path::new(output_dir)
|
||||||
|
.join(format!("{}.{}", file_uuid, processor));
|
||||||
|
if path.exists() {
|
||||||
|
completed_count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let all_complete = completed_count == required_processors.len();
|
||||||
|
let new_status = if all_complete { "completed" } else { "processing" };
|
||||||
|
|
||||||
|
let videos_table = schema::table_name("videos");
|
||||||
|
let result = sqlx::query(&format!(
|
||||||
|
"UPDATE {} SET status = $1, updated_at = NOW() WHERE file_uuid = $2",
|
||||||
|
videos_table
|
||||||
|
))
|
||||||
|
.bind(new_status)
|
||||||
|
.bind(&file_uuid)
|
||||||
|
.execute(state.db.pool())
|
||||||
|
.await;
|
||||||
|
|
||||||
|
match result {
|
||||||
|
Ok(res) if res.rows_affected() > 0 => Ok(Json(serde_json::json!({
|
||||||
|
"success": true,
|
||||||
|
"file_uuid": file_uuid,
|
||||||
|
"status": new_status,
|
||||||
|
"processors_complete": completed_count,
|
||||||
|
"processors_total": required_processors.len()
|
||||||
|
}))),
|
||||||
|
Ok(_) => Err(StatusCode::NOT_FOUND),
|
||||||
|
Err(e) => {
|
||||||
|
tracing::error!("[SYNC_STATUS] Update failed: {}", e);
|
||||||
|
Err(StatusCode::INTERNAL_SERVER_ERROR)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user