fix: face group name read consistency, sync_file_status fix, cleanup ghost records, identity_agent replaced with face_dedup

- get_face_groups_handler: COALESCE(tp.name, tn.label) for name consistency
- sync_file_status: compare JSON vs pre_chunks (not chunk table)
- face consistency: compare frames.len() not total_faces
- cleanup 2 ghost records with NULL file_name/file_path
- replace identity_agent with face_dedup in pipeline stages
- remove identity_agent_api.rs and all references
- update required_processors to match actual processors
- update AGENTS.md with team responsibilities
- add Studio pipeline changes documentation
This commit is contained in:
Accusys
2026-07-27 02:15:51 +08:00
parent fcdeab82e6
commit 39a2cbc65b
118 changed files with 19386 additions and 2964 deletions
+130 -43
View File
@@ -666,19 +666,31 @@ async fn stream_video(
use tokio::io::{AsyncReadExt, AsyncSeekExt};
let (_mode, audio) = parse_video_params(&params);
let use_original = params.get("original").map(|v| v == "true").unwrap_or(false);
let videos_table = schema::table_name("videos");
let row: Option<(String,)> = sqlx::query_as(&format!(
"SELECT file_path FROM {} WHERE file_uuid = $1",
let row: Option<(String, Option<String>)> = sqlx::query_as(&format!(
"SELECT file_path, proxy_path FROM {} WHERE file_uuid = $1",
videos_table
))
.bind(&file_uuid)
.fetch_optional(state.db.pool())
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
let (file_path,) = row.ok_or(StatusCode::NOT_FOUND)?;
let (file_path, proxy_path) = row.ok_or(StatusCode::NOT_FOUND)?;
let src = std::path::PathBuf::from(&file_path);
// Use proxy if available and not explicitly requesting original
let effective_path = if !use_original {
proxy_path
.as_ref()
.filter(|p| std::path::Path::new(p).exists())
.unwrap_or(&file_path)
.clone()
} else {
file_path.clone()
};
let src = std::path::PathBuf::from(&effective_path);
if !src.exists() {
return Err(StatusCode::NOT_FOUND);
}
@@ -723,7 +735,7 @@ async fn stream_video(
let tmp_str = tmp.to_str().unwrap_or("").to_string();
let ss = start_sec.to_string();
let d = dur.to_string();
let mut chunk_args = vec!["-ss", &ss, "-i", &file_path, "-t", &d, "-c", "copy"];
let mut chunk_args = vec!["-ss", &ss, "-i", &effective_path, "-t", &d, "-c", "copy"];
if audio == "off" {
chunk_args.push("-an");
}
@@ -736,15 +748,57 @@ async fn stream_video(
let _ = std::fs::remove_file(&tmp);
return Err(StatusCode::INTERNAL_SERVER_ERROR);
}
let data = tokio::fs::read(&tmp)
let clip_size = tokio::fs::metadata(&tmp)
.await
.map(|m| m.len())
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
let _ = std::fs::remove_file(&tmp);
return Ok(Response::builder()
.header(header::CONTENT_TYPE, "video/mp4")
.header(header::CONTENT_LENGTH, data.len())
.body(Body::from(data))
.unwrap());
let range_hdr = request
.headers()
.get(header::RANGE)
.and_then(|v| v.to_str().ok());
if let Some(range_str) = range_hdr {
let (start, end) = parse_range(range_str, clip_size);
let length = end - start + 1;
let mut file = tokio::fs::File::open(&tmp)
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
file.seek(std::io::SeekFrom::Start(start))
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
let take = file.take(length);
let stream = tokio_util::io::ReaderStream::new(take);
let body = Body::from_stream(stream);
let resp = Response::builder()
.status(StatusCode::PARTIAL_CONTENT)
.header(header::CONTENT_TYPE, "video/mp4")
.header(
header::CONTENT_RANGE,
format!("bytes {}-{}/{}", start, end, clip_size),
)
.header(header::CONTENT_LENGTH, length)
.header(header::ACCEPT_RANGES, "bytes")
.body(body)
.unwrap();
let tmp_path = tmp.clone();
tokio::spawn(async move {
tokio::time::sleep(std::time::Duration::from_secs(30)).await;
let _ = tokio::fs::remove_file(&tmp_path).await;
});
return Ok(resp);
} else {
let data = tokio::fs::read(&tmp)
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
let _ = tokio::fs::remove_file(&tmp).await;
return Ok(Response::builder()
.header(header::CONTENT_TYPE, "video/mp4")
.header(header::CONTENT_LENGTH, data.len())
.header(header::ACCEPT_RANGES, "bytes")
.body(Body::from(data))
.unwrap());
}
}
// Full file streaming with range request support
@@ -1391,8 +1445,7 @@ async fn get_pose_handler(
use std::collections::HashMap as StdHashMap;
let output_dir = OUTPUT_DIR.as_str();
let pose_path = std::path::Path::new(output_dir)
.join(format!("{}.pose.json", file_uuid));
let pose_path = std::path::Path::new(output_dir).join(format!("{}.pose.json", file_uuid));
if !pose_path.exists() {
tracing::error!("[get_pose] File not found: {}", pose_path.display());
@@ -1409,7 +1462,10 @@ async fn get_pose_handler(
StatusCode::INTERNAL_SERVER_ERROR
})?;
let frames = data.get("frames").and_then(|v| v.as_array()).ok_or(StatusCode::NOT_FOUND)?;
let frames = data
.get("frames")
.and_then(|v| v.as_array())
.ok_or(StatusCode::NOT_FOUND)?;
let frame_data = frames
.iter()
@@ -1440,39 +1496,61 @@ async fn get_pose_handler(
if let Some(existing) = unique_kps.get(name) {
if conf > existing.confidence {
unique_kps.insert(name.to_string(), PoseKeypoint {
unique_kps.insert(
name.to_string(),
PoseKeypoint {
name: name.to_string(),
x,
y,
confidence: conf,
},
);
}
} else {
unique_kps.insert(
name.to_string(),
PoseKeypoint {
name: name.to_string(),
x,
y,
confidence: conf,
});
}
} else {
unique_kps.insert(name.to_string(), PoseKeypoint {
name: name.to_string(),
x,
y,
confidence: conf,
});
},
);
}
}
let coco_names = [
"nose", "left_eye", "right_eye", "left_ear", "right_ear",
"left_shoulder", "right_shoulder", "left_elbow", "right_elbow",
"left_wrist", "right_wrist", "left_hip", "right_hip",
"left_knee", "right_knee", "left_ankle", "right_ankle",
"nose",
"left_eye",
"right_eye",
"left_ear",
"right_ear",
"left_shoulder",
"right_shoulder",
"left_elbow",
"right_elbow",
"left_wrist",
"right_wrist",
"left_hip",
"right_hip",
"left_knee",
"right_knee",
"left_ankle",
"right_ankle",
];
let keypoints: Vec<PoseKeypoint> = coco_names
.iter()
.map(|name| {
unique_kps.get(*name).cloned().unwrap_or_else(|| PoseKeypoint {
name: name.to_string(),
x: 0.0,
y: 0.0,
confidence: 0.0,
})
unique_kps
.get(*name)
.cloned()
.unwrap_or_else(|| PoseKeypoint {
name: name.to_string(),
x: 0.0,
y: 0.0,
confidence: 0.0,
})
})
.collect();
@@ -1492,11 +1570,14 @@ async fn get_appearance_handler(
use crate::core::config::OUTPUT_DIR;
let output_dir = OUTPUT_DIR.as_str();
let appearance_path = std::path::Path::new(output_dir)
.join(format!("{}.appearance.json", file_uuid));
let appearance_path =
std::path::Path::new(output_dir).join(format!("{}.appearance.json", file_uuid));
if !appearance_path.exists() {
tracing::error!("[get_appearance] File not found: {}", appearance_path.display());
tracing::error!(
"[get_appearance] File not found: {}",
appearance_path.display()
);
return Err(StatusCode::NOT_FOUND);
}
@@ -1510,7 +1591,10 @@ async fn get_appearance_handler(
StatusCode::INTERNAL_SERVER_ERROR
})?;
let frames = data.get("frames").and_then(|v| v.as_array()).ok_or(StatusCode::NOT_FOUND)?;
let frames = data
.get("frames")
.and_then(|v| v.as_array())
.ok_or(StatusCode::NOT_FOUND)?;
let frame_data = frames
.iter()
@@ -1523,9 +1607,9 @@ async fn get_appearance_handler(
.map(|arr| {
arr.iter()
.filter_map(|channel| {
channel.as_array().map(|bins| {
bins.iter().filter_map(|v| v.as_f64()).collect()
})
channel
.as_array()
.map(|bins| bins.iter().filter_map(|v| v.as_f64()).collect())
})
.collect()
})
@@ -1541,5 +1625,8 @@ async fn get_appearance_handler(
pub fn pose_appearance_routes() -> Router<crate::api::types::AppState> {
Router::new()
.route("/api/v1/file/:file_uuid/pose", get(get_pose_handler))
.route("/api/v1/file/:file_uuid/appearance", get(get_appearance_handler))
.route(
"/api/v1/file/:file_uuid/appearance",
get(get_appearance_handler),
)
}