feat: add pose and appearance endpoints for face detail display

- Add GET /api/v1/file/:file_uuid/pose endpoint
- Add GET /api/v1/file/:file_uuid/appearance endpoint
- Keypoint deduplication (highest confidence)
- Add face-groups endpoint for Studio integration
- Add profile routes (trace-profile, file-profile)
- Update API documentation
This commit is contained in:
Accusys
2026-07-19 20:43:35 +08:00
parent 455c6b81e6
commit d0b7bfa56b
7 changed files with 824 additions and 2 deletions
+83 -1
View File
@@ -1,10 +1,11 @@
use axum::{
Extension, Json,
extract::{Query, State},
extract::{Path, Query, State},
http::StatusCode,
};
use serde::{Deserialize, Serialize};
use sqlx::PgPool;
use std::collections::HashMap;
use crate::core::db::schema;
use crate::api::middleware::UserAuth;
@@ -375,6 +376,86 @@ pub async fn update_file_profile_handler(
}
}
// ─── Face Groups ───
#[derive(Debug, Serialize, Deserialize)]
pub struct FaceGroup {
pub group_id: i32,
pub name: String,
pub trace_ids: Vec<i64>,
pub trace_count: i32,
pub representative_trace: i64,
pub editable: bool,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct FaceGroupsResponse {
pub success: bool,
pub file_uuid: String,
pub face_groups: Vec<FaceGroup>,
pub total_groups: i32,
pub unassigned_traces: Vec<i64>,
}
pub async fn get_face_groups_handler(
State(state): State<AppState>,
Extension(_auth): Extension<UserAuth>,
Path(file_uuid): Path<String>,
) -> Result<Json<FaceGroupsResponse>, StatusCode> {
let tkg_table = schema::table_name("tkg_nodes");
let rows: Vec<(String, serde_json::Value)> = sqlx::query_as(&format!(
"SELECT label, properties FROM {} \
WHERE file_uuid = $1 AND node_type = 'face_track' \
ORDER BY (properties->>'trace_id')::int",
tkg_table
))
.bind(&file_uuid)
.fetch_all(state.db.pool())
.await
.map_err(|e| {
tracing::error!("[FaceGroups] DB error: {}", e);
StatusCode::INTERNAL_SERVER_ERROR
})?;
let mut groups: HashMap<String, Vec<i64>> = HashMap::new();
let mut unassigned: Vec<i64> = Vec::new();
for (label, properties) in rows {
let trace_id = properties
.get("trace_id")
.and_then(|v| v.as_i64())
.unwrap_or(0);
if label.starts_with("Face Trace ") || label.starts_with("Trace ") {
unassigned.push(trace_id);
} else {
groups.entry(label).or_default().push(trace_id);
}
}
let face_groups: Vec<FaceGroup> = groups
.into_iter()
.enumerate()
.map(|(idx, (name, trace_ids))| FaceGroup {
group_id: (idx + 1) as i32,
name,
trace_count: trace_ids.len() as i32,
representative_trace: trace_ids.first().copied().unwrap_or(0),
trace_ids,
editable: true,
})
.collect();
Ok(Json(FaceGroupsResponse {
success: true,
file_uuid,
total_groups: face_groups.len() as i32,
unassigned_traces: unassigned,
face_groups,
}))
}
// ─── Routes ───
pub fn profile_routes() -> axum::Router<AppState> {
@@ -388,4 +469,5 @@ pub fn profile_routes() -> axum::Router<AppState> {
)
.route("/api/v1/file-profile", get(get_file_profile_handler))
.route("/api/v1/file-profile", put(update_file_profile_handler))
.route("/api/v1/file/:file_uuid/face-groups", get(get_face_groups_handler))
}