优化视频复刻和商品内容大小
This commit is contained in:
@@ -95,6 +95,7 @@ def submit_asset_for_review(asset: Asset, *, force: bool = False) -> bool:
|
||||
if not remote_id:
|
||||
# 火山没回 Id:不要标 processing(否则 remote_id 为空、poll 永远早退、卡死黄),留空可重试
|
||||
logger.warning("create_asset 返回空 id,asset %s 暂不送审(可重试)", asset.id)
|
||||
_record_submit_error(asset, "审核服务未返回素材编号")
|
||||
return False
|
||||
asset.review_remote_id = remote_id
|
||||
asset.review_status = "processing"
|
||||
@@ -103,9 +104,42 @@ def submit_asset_for_review(asset: Asset, *, force: bool = False) -> bool:
|
||||
return True
|
||||
except Exception as exc: # noqa: BLE001
|
||||
logger.warning("submit_asset_for_review failed for asset %s: %s", asset.id, exc)
|
||||
# 只写日志等于把原因埋了:调用方(视频复刻等)只能报「素材提交审核失败」这种没信息量的话,
|
||||
# 用户和排查都无从下手。原因落到 review_error,让上层能带出来。
|
||||
_record_submit_error(asset, str(exc))
|
||||
return False
|
||||
|
||||
|
||||
# 火山素材审核的常见拒因:原文是英文错误码,直接怼给用户看不懂也不知道怎么办。
|
||||
_SUBMIT_ERROR_HINTS = (
|
||||
("WidthTooSmall", "图片太小(宽高需在 300–6000 像素之间),请换一张更大的图"),
|
||||
("HeightTooSmall", "图片太小(宽高需在 300–6000 像素之间),请换一张更大的图"),
|
||||
("WidthTooLarge", "图片太大(宽高需在 300–6000 像素之间),请压缩后重试"),
|
||||
("HeightTooLarge", "图片太大(宽高需在 300–6000 像素之间),请压缩后重试"),
|
||||
("SizeTooLarge", "图片文件太大,请压缩后重试"),
|
||||
("InvalidImageFormat", "图片格式不支持,请改用 JPG / PNG / WebP"),
|
||||
("DownloadFailed", "审核服务拉取不到这张图,请重新上传"),
|
||||
)
|
||||
|
||||
|
||||
def humanize_submit_error(reason: str) -> str:
|
||||
"""把火山的英文错误码换成能照着做的中文。认不出的原样返回。"""
|
||||
text = reason or ""
|
||||
for code, hint in _SUBMIT_ERROR_HINTS:
|
||||
if code in text:
|
||||
return hint
|
||||
return text
|
||||
|
||||
|
||||
def _record_submit_error(asset: Asset, reason: str) -> None:
|
||||
"""把送审失败原因写回资产。写失败不抛 —— 审计不能反过来搞挂主流程。"""
|
||||
try:
|
||||
asset.review_error = humanize_submit_error(reason)[:2000]
|
||||
asset.save(update_fields=["review_error", "updated_at"])
|
||||
except Exception: # noqa: BLE001
|
||||
logger.warning("记录 asset %s 送审失败原因时出错", asset.id, exc_info=True)
|
||||
|
||||
|
||||
# 平台自己生成的资产,提示词与生成链路都在我们手里,视为免审;用户上传的必须真过一遍审核。
|
||||
# 判据是 Asset.source 而不是「在不在某个库里」—— 按库免审等于把审核架空:
|
||||
# 用户上传一张图进资产库,再从自由创作引用出去,就绕过了整套人像审核。
|
||||
|
||||
Reference in New Issue
Block a user