feat: update core API, database layer, and worker modules

- Remove unused imports (n8n_search, universal_search, Client, Arc, etc.)
- Update API endpoints for identity, face recognition, search
- Fix postgres_db.rs search_videos parent_uuid column
- Add snapshot API and identity agent API
- Clean up backup files (.bak, .bak2)
This commit is contained in:
Warren
2026-04-30 15:07:02 +08:00
parent 8f2208dd63
commit 2b23d1cfbd
148 changed files with 8553 additions and 48637 deletions

View File

@@ -16,7 +16,7 @@ use crate::core::processor::face_recognition::{
#[derive(Debug, Deserialize)]
pub struct FaceRecognitionRequest {
pub video_uuid: String,
pub file_uuid: String,
pub enable_recognition: Option<bool>,
pub enable_tracking: Option<bool>,
pub enable_clustering: Option<bool>,
@@ -33,7 +33,7 @@ pub struct FaceRecognitionResponse {
#[derive(Debug, Deserialize)]
pub struct FaceRegistrationRequest {
pub video_uuid: String,
pub file_uuid: String,
pub name: String,
pub metadata: Option<serde_json::Value>,
}
@@ -47,7 +47,7 @@ pub struct FaceRegistrationApiResponse {
#[derive(Debug, Deserialize)]
pub struct FaceSearchRequest {
pub video_uuid: String,
pub file_uuid: String,
pub embedding: Vec<f32>,
pub similarity_threshold: Option<f64>,
pub limit: Option<i32>,
@@ -71,7 +71,7 @@ pub struct FaceSearchResult {
#[derive(Debug, Deserialize)]
pub struct FaceListQuery {
pub video_uuid: String,
pub file_uuid: String,
pub page: Option<usize>,
pub page_size: Option<usize>,
pub active_only: Option<bool>,
@@ -106,7 +106,7 @@ pub fn face_recognition_routes() -> Router<crate::api::server::AppState> {
.route("/api/v1/face/:face_id", get(get_face_details))
.route("/api/v1/face/:face_id", axum::routing::delete(delete_face))
.route(
"/api/v1/face/results/:video_uuid",
"/api/v1/face/results/:file_uuid",
get(get_recognition_results),
)
}
@@ -119,7 +119,7 @@ async fn recognize_faces(
tracing::info!(
"[FACE_RECOGNITION] Starting recognition for video: {}, processing_id: {}",
request.video_uuid,
request.file_uuid,
processing_id
);
@@ -134,12 +134,12 @@ async fn recognize_faces(
}
};
let video_record = match db.get_video_by_uuid(&request.video_uuid).await {
let video_record = match db.get_video_by_uuid(&request.file_uuid).await {
Ok(Some(record)) => record,
Ok(None) => {
return Err((
StatusCode::NOT_FOUND,
format!("Video not found: {}", request.video_uuid),
format!("Video not found: {}", request.file_uuid),
))
}
Err(e) => {
@@ -178,13 +178,13 @@ async fn recognize_faces(
};
// Store results in database
if let Err(e) = store_recognition_results(&db, &request.video_uuid, &result).await {
if let Err(e) = store_recognition_results(&db, &request.file_uuid, &result).await {
tracing::warn!("Failed to store recognition results: {}", e);
}
Ok(Json(FaceRecognitionResponse {
success: true,
message: format!("Face recognition completed for {}", request.video_uuid),
message: format!("Face recognition completed for {}", request.file_uuid),
result: Some(result),
processing_id,
}))
@@ -334,7 +334,7 @@ async fn register_face_api(
.bind(&name)
.bind(&embedding_str)
.bind(&attrs_json)
.bind(&metadata.unwrap_or(serde_json::json!({})))
.bind(serde_json::to_string(&metadata.unwrap_or(serde_json::json!({}))).unwrap())
.execute(db.pool())
.await
{
@@ -694,7 +694,7 @@ async fn delete_face(
async fn get_recognition_results(
State(_state): State<crate::api::server::AppState>,
Path(video_uuid): Path<String>,
Path(file_uuid): Path<String>,
) -> Result<Json<serde_json::Value>, (StatusCode, String)> {
let db = match PostgresDb::init().await {
Ok(db) => db,
@@ -708,7 +708,7 @@ async fn get_recognition_results(
let query = r#"
SELECT
video_uuid,
file_uuid,
frame_count,
fps,
total_faces,
@@ -718,7 +718,7 @@ async fn get_recognition_results(
processing_time_secs,
created_at
FROM face_recognition_results
WHERE video_uuid = $1
WHERE file_uuid = $1
ORDER BY created_at DESC
LIMIT 1
"#;
@@ -734,7 +734,7 @@ async fn get_recognition_results(
Option<f64>,
chrono::DateTime<chrono::Utc>,
)> = match sqlx::query_as(query)
.bind(&video_uuid)
.bind(&file_uuid)
.fetch_optional(db.pool())
.await
{
@@ -749,7 +749,7 @@ async fn get_recognition_results(
match result {
Some((
video_uuid,
file_uuid,
frame_count,
fps,
total_faces,
@@ -761,7 +761,7 @@ async fn get_recognition_results(
)) => {
let response = serde_json::json!({
"success": true,
"video_uuid": video_uuid,
"file_uuid": file_uuid,
"frame_count": frame_count,
"fps": fps,
"total_faces": total_faces,
@@ -776,14 +776,14 @@ async fn get_recognition_results(
}
None => Err((
StatusCode::NOT_FOUND,
format!("No recognition results found for video: {}", video_uuid),
format!("No recognition results found for video: {}", file_uuid),
)),
}
}
async fn store_recognition_results(
db: &PostgresDb,
video_uuid: &str,
file_uuid: &str,
result: &FaceRecognitionResult,
) -> Result<(), anyhow::Error> {
let total_faces = result.frames.iter().map(|f| f.faces.len()).sum::<usize>();
@@ -796,7 +796,7 @@ async fn store_recognition_results(
let query = r#"
INSERT INTO face_recognition_results (
video_uuid,
file_uuid,
frame_count,
fps,
total_faces,
@@ -804,7 +804,7 @@ async fn store_recognition_results(
clusters_count,
result_data
) VALUES ($1, $2, $3, $4, $5, $6, $7)
ON CONFLICT (video_uuid) DO UPDATE SET
ON CONFLICT (file_uuid) DO UPDATE SET
frame_count = EXCLUDED.frame_count,
fps = EXCLUDED.fps,
total_faces = EXCLUDED.total_faces,
@@ -815,7 +815,7 @@ async fn store_recognition_results(
"#;
sqlx::query(query)
.bind(video_uuid)
.bind(file_uuid)
.bind(result.frame_count as i64)
.bind(result.fps)
.bind(total_faces as i32)
@@ -840,7 +840,7 @@ async fn store_recognition_results(
let insert_query = r#"
INSERT INTO face_detections (
video_uuid,
file_uuid,
frame_number,
timestamp_secs,
face_id,
@@ -854,7 +854,7 @@ async fn store_recognition_results(
identity_confidence,
cluster_id
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10::vector, $11, $12, $13)
ON CONFLICT (video_uuid, frame_number, x, y, width, height) DO UPDATE SET
ON CONFLICT (file_uuid, frame_number, x, y, width, height) DO UPDATE SET
face_id = EXCLUDED.face_id,
confidence = EXCLUDED.confidence,
embedding = EXCLUDED.embedding,
@@ -874,7 +874,7 @@ async fn store_recognition_results(
.map(|c| c.cluster_id.clone());
sqlx::query(insert_query)
.bind(video_uuid)
.bind(file_uuid)
.bind(frame.frame as i64)
.bind(frame.timestamp)
.bind(face.face_id.as_deref())
@@ -908,7 +908,7 @@ async fn store_recognition_results(
let cluster_query = r#"
INSERT INTO face_clusters (
cluster_id,
video_uuid,
file_uuid,
centroid,
size,
representative_face_id,
@@ -923,7 +923,7 @@ async fn store_recognition_results(
sqlx::query(cluster_query)
.bind(&cluster.cluster_id)
.bind(video_uuid)
.bind(file_uuid)
.bind(&centroid_str)
.bind(cluster.size as i32)
.bind(cluster.representative_face_id.as_deref())