fix(8502): 重生图片自动作废旧视频;记录来源图片签名并提示stale;组图/重生视频路径唯一化

This commit is contained in:
Tony Zhang
2025-12-17 22:54:22 +08:00
parent 1e210ffccf
commit c6436da17e
3 changed files with 113 additions and 2 deletions

View File

@@ -308,6 +308,59 @@ class DBManager:
finally:
session.close()
def clear_asset(self, project_id: str, scene_id: int, asset_type: str, *, status: str = "pending") -> None:
"""
Clear an asset record (keep the row, but remove paths/task/metadata).
Used to invalidate stale videos after images are regenerated.
"""
session = self._get_session()
try:
asset = session.query(SceneAsset).filter_by(
project_id=project_id,
scene_id=scene_id,
asset_type=asset_type,
).first()
if not asset:
return
asset.status = status
asset.local_path = None
asset.remote_url = None
asset.task_id = None
asset.metadata_json = "{}"
asset.updated_at = time.time()
session.commit()
except Exception as e:
session.rollback()
logger.error(f"Error clearing asset: {e}")
finally:
session.close()
def clear_assets(self, project_id: str, asset_type: str, *, status: str = "pending") -> int:
"""
Clear all assets of a type for a project. Returns number of rows affected.
"""
session = self._get_session()
try:
q = session.query(SceneAsset).filter_by(project_id=project_id, asset_type=asset_type)
rows = q.all()
if not rows:
return 0
for asset in rows:
asset.status = status
asset.local_path = None
asset.remote_url = None
asset.task_id = None
asset.metadata_json = "{}"
asset.updated_at = time.time()
session.commit()
return len(rows)
except Exception as e:
session.rollback()
logger.error(f"Error clearing assets: {e}")
return 0
finally:
session.close()
# --- Config/Prompt Operations ---
def get_config(self, key: str, default: Any = None) -> Any:

View File

@@ -6,6 +6,7 @@ import logging
import time
import requests
import os
from os import stat
from typing import Dict, Any, List, Optional
from pathlib import Path
@@ -56,6 +57,21 @@ class VideoGenerator:
task_id = self._submit_task(image_url, prompt)
if task_id:
try:
st = stat(image_path)
source_sig = {
"source_image_local_path": image_path,
"source_image_size": int(getattr(st, "st_size", 0) or 0),
"source_image_mtime": float(getattr(st, "st_mtime", 0.0) or 0.0),
"source_image_r2_url": image_url,
"submitted_at": time.time(),
}
except Exception:
source_sig = {
"source_image_local_path": image_path,
"source_image_r2_url": image_url,
"submitted_at": time.time(),
}
# 立即保存 task_id 到数据库,状态为 processing
db.save_asset(
project_id=project_id,
@@ -63,7 +79,8 @@ class VideoGenerator:
asset_type="video",
status="processing",
task_id=task_id,
local_path=None
local_path=None,
metadata=source_sig,
)
return task_id