fix: Scene VLM 全流程 per-library 路徑
- job_worker: cut.json 檢查 + output_dir + scenes_path 改用 get_output_dir_for_file - media_api: scene_thumbnail 改用 per-library + global fallback - 確保 test library 的 scenes.json 與 scene jpg 寫到 output/test/ - 已搬移舊 scene jpg 從 demo 到 test
This commit is contained in:
+13
-6
@@ -1102,10 +1102,11 @@ async fn trace_thumbnail(
|
|||||||
/// Path mirrors `thumbnail_url` produced by the VLM scene search API.
|
/// Path mirrors `thumbnail_url` produced by the VLM scene search API.
|
||||||
/// e.g. /api/v1/file/{file_uuid}/scenes/scene_000.jpg
|
/// e.g. /api/v1/file/{file_uuid}/scenes/scene_000.jpg
|
||||||
pub async fn scene_thumbnail(
|
pub async fn scene_thumbnail(
|
||||||
State(_state): State<crate::api::types::AppState>,
|
State(state): State<crate::api::types::AppState>,
|
||||||
Path((file_uuid, filename)): Path<(String, String)>,
|
Path((file_uuid, filename)): Path<(String, String)>,
|
||||||
) -> Result<impl IntoResponse, StatusCode> {
|
) -> Result<impl IntoResponse, StatusCode> {
|
||||||
let output_dir = crate::core::config::OUTPUT_DIR.as_str();
|
// Try per-library output dir first (test files live in output/test)
|
||||||
|
let per_lib = crate::core::config::get_output_dir_for_file(&file_uuid, state.db.pool()).await;
|
||||||
|
|
||||||
// Security: validate file_uuid to prevent path traversal
|
// Security: validate file_uuid to prevent path traversal
|
||||||
if !crate::core::thumbnail::validator::is_valid_file_uuid(&file_uuid) {
|
if !crate::core::thumbnail::validator::is_valid_file_uuid(&file_uuid) {
|
||||||
@@ -1120,10 +1121,16 @@ pub async fn scene_thumbnail(
|
|||||||
.map(|_| filename.clone())
|
.map(|_| filename.clone())
|
||||||
.ok_or(StatusCode::NOT_FOUND)?;
|
.ok_or(StatusCode::NOT_FOUND)?;
|
||||||
|
|
||||||
let file_path = std::path::PathBuf::from(output_dir)
|
let global_dir = crate::core::config::OUTPUT_DIR.as_str();
|
||||||
.join(&file_uuid)
|
let candidate1 = std::path::PathBuf::from(&per_lib)
|
||||||
.join("scenes")
|
.join(&file_uuid).join("scenes").join(&safe_name);
|
||||||
.join(&safe_name);
|
let candidate2 = std::path::PathBuf::from(global_dir)
|
||||||
|
.join(&file_uuid).join("scenes").join(&safe_name);
|
||||||
|
let file_path = if candidate1.exists() {
|
||||||
|
candidate1
|
||||||
|
} else {
|
||||||
|
candidate2
|
||||||
|
};
|
||||||
|
|
||||||
if !file_path.exists() {
|
if !file_path.exists() {
|
||||||
return Err(StatusCode::NOT_FOUND);
|
return Err(StatusCode::NOT_FOUND);
|
||||||
|
|||||||
@@ -3773,13 +3773,13 @@ async fn process_job(&self, job: crate::core::db::MonitorJob) -> Result<()> {
|
|||||||
.all(|p| p == "scene_vlm" || p == "scene");
|
.all(|p| p == "scene_vlm" || p == "scene");
|
||||||
let cut_json_exists = std::path::Path::new(&format!(
|
let cut_json_exists = std::path::Path::new(&format!(
|
||||||
"{}/{}.cut.json",
|
"{}/{}.cut.json",
|
||||||
crate::core::config::OUTPUT_DIR.as_str(),
|
crate::core::config::get_output_dir_for_file(uuid, self.db.pool()).await.trim_end_matches('/'),
|
||||||
uuid
|
uuid
|
||||||
))
|
))
|
||||||
.exists();
|
.exists();
|
||||||
if has_cut || (wants_scene_vlm && cut_json_exists) {
|
if has_cut || (wants_scene_vlm && cut_json_exists) {
|
||||||
let output_dir = crate::core::config::OUTPUT_DIR.clone();
|
let output_dir = crate::core::config::get_output_dir_for_file(uuid, self.db.pool()).await;
|
||||||
let scenes_path = format!("{}/{}.scenes.json", output_dir, uuid);
|
let scenes_path = format!("{}/{}.scenes.json", output_dir.trim_end_matches('/'), uuid);
|
||||||
|
|
||||||
// 重跑條件:scenes.json 不存在 或 未完整完成(vlm completed 數 < total_scenes)
|
// 重跑條件:scenes.json 不存在 或 未完整完成(vlm completed 數 < total_scenes)
|
||||||
let scene_vlm_complete = if std::path::Path::new(&scenes_path).exists() {
|
let scene_vlm_complete = if std::path::Path::new(&scenes_path).exists() {
|
||||||
|
|||||||
Reference in New Issue
Block a user