优化替换角色添加音频

This commit is contained in:
Azmat@qq.com
2026-09-01 17:55:57 +08:00
parent a520b230c5
commit 0603a85d83
10 changed files with 322 additions and 111 deletions
+36
View File
@@ -2917,6 +2917,42 @@ def _asset_preview_url(asset) -> str:
return ""
def asset_stable_url(asset) -> tuple[str, str]:
"""资产的「长期可打开」直链 (主文件, 封面图)。历史记录这类隔天还要点开的场景必须用这个:
预签名链只活 1 小时,存进 payload 快照的话第二天就播不了 —— 公读直链不过期还能被缓存。
顺序:落库 preview_url → TOS 公读直链 → 兜底预签名。"""
if asset is None:
return "", ""
files = list(asset.files.all())
if not files:
return "", ""
primary = next((f for f in files if f.is_primary), None) or files[0]
# 封面只对视频/音频有意义:图片资产的第二张文件是它自己的兄弟图,不是封面。
poster = None
if "image" not in (primary.content_type or ""):
poster = next(
(f for f in files if f is not primary and "image" in (f.content_type or "")), None
)
def _url(f) -> str:
if f is None:
return ""
if f.preview_url:
return f.preview_url
if not f.object_key:
return ""
try:
return TosStorage().public_url(object_key=f.object_key, bucket=f.bucket or None)
except Exception: # noqa: BLE001
pass
try:
return TosStorage().presigned_get_url(object_key=f.object_key)
except Exception: # noqa: BLE001
return ""
return _url(primary), _url(poster)
def _seedance_ref_url(raw_url: str, review_status: str = "", review_remote_id: str = "") -> str:
"""Seedance 参考图 URL:只要资产已进素材库(有 remote_id)就用 asset:// 素材库引用 —— 火山认的是
「在不在素材库」,与审核态无关(实测 processing 也能引用);未进库才回落原始直链。