1、图片生成同步接口超时风险
2、图片返回的 URL 是本地路径 3、视频生成中媒体文件重复下载 4、幂等性检查无数据库唯一约束 5、幂等键冲突返回 409 改为返回已有任务信息 6、虚拟素材库配额校验 TOCTOU 7、项目级联删除与独立素材删除任务并发冲突
This commit is contained in:
@@ -83,15 +83,19 @@ async def create_video(
|
||||
key_context: auth_service.ApiKeyContext = Depends(auth_service.get_api_key_dependency),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> ApiVideoCreateResponse:
|
||||
"""创建视频生成任务(异步)。"""
|
||||
"""创建视频生成任务(异步)。
|
||||
|
||||
幂等性说明:如果 idempotency_key 已存在,直接返回已有任务 ID(不会重复创建)。
|
||||
"""
|
||||
try:
|
||||
# 路由层校验:权限、幂等性
|
||||
existing_task = await _validate_request(db, key_context, req)
|
||||
if existing_task:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_409_CONFLICT,
|
||||
detail=f"幂等键已存在: 任务 {req.idempotency_key} 已创建",
|
||||
logger.info(
|
||||
"Idempotent request: returning existing task %s for key=%s",
|
||||
existing_task.id, req.idempotency_key,
|
||||
)
|
||||
return ApiVideoCreateResponse(id=f"zc-{existing_task.id}")
|
||||
|
||||
# 调用服务层创建任务
|
||||
result = await generation_service.submit_video_generation(
|
||||
|
||||
Reference in New Issue
Block a user