fix: 修复换火山账号导致素材库操作失败问题

This commit is contained in:
hh
2026-07-09 17:54:05 +08:00
parent 8c50096888
commit 3e52942547
5 changed files with 247 additions and 15 deletions
+18
View File
@@ -20,9 +20,15 @@ _ASSETS_ERROR_MESSAGES = {
"RequestError": "素材审核服务暂时不可用,请稍后重试",
"InvalidParameter": "素材参数无效",
"NotFound": "素材不存在或已被删除",
"NotFound.asset_id": "素材不存在或已被删除",
"NotFound.group_id": "素材组不存在或已被删除",
"Forbidden": "没有权限操作该素材(检查 AK/SK)",
}
_NOT_FOUND_CODES = frozenset({"NotFound", "NotFound.asset_id", "NotFound.group_id"})
_ASSET_NOT_FOUND_CODES = frozenset({"NotFound", "NotFound.asset_id"})
_GROUP_NOT_FOUND_CODES = frozenset({"NotFound", "NotFound.group_id"})
class AssetsAPIError(Exception):
def __init__(self, code, message, status_code=400):
@@ -33,6 +39,18 @@ class AssetsAPIError(Exception):
super().__init__(f"[{code}] {message}")
def is_not_found_code(code: str | None) -> bool:
return code in _NOT_FOUND_CODES
def is_asset_not_found_code(code: str | None) -> bool:
return code in _ASSET_NOT_FOUND_CODES
def is_group_not_found_code(code: str | None) -> bool:
return code in _GROUP_NOT_FOUND_CODES
def is_enabled() -> bool:
cfg = getattr(settings, "ASSETS_API", {}) or {}
return bool(cfg.get("enabled") and cfg.get("access_key") and cfg.get("secret_key"))