From 6ffdef841b87ea6d9e2fb5565bcbef1e33b1a73f Mon Sep 17 00:00:00 2001 From: CI Bot Date: Sat, 22 Aug 2026 20:40:37 +0800 Subject: [PATCH] fix(cover): add plan.config.cover_candidates fallback in cover generation endpoint Problem: The cover generation endpoint (POST /generation/generate-cover) only checks GenerationTask.cover_url through 3 fallback paths (A: direct task_id, B: source_edit_plan_id, C: user+template). However, the worker writes cover candidate frames to plan.config['cover_candidates'] during preview rendering, and this field was never read by the endpoint. When GenerationTask.cover_url was empty (e.g., due to cover frame extraction key mismatch or old data), the endpoint returned 400 even though cover_candidates existed in plan.config. Fix: Add step D fallback that reads plan.config.cover_candidates[0] before returning 400. This covers cases where: - The worker wrote cover_candidates but GenerationTask.cover_url was not set (historical data, key mismatch) - The cover frames were extracted during rendering but the task-level cover_url write was skipped Also update the 400 warning log to indicate which steps were checked. --- apps/api/app/api/routes/generation_cover.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/api/app/api/routes/generation_cover.py b/apps/api/app/api/routes/generation_cover.py index 56ba38fb7..73130bb73 100644 --- a/apps/api/app/api/routes/generation_cover.py +++ b/apps/api/app/api/routes/generation_cover.py @@ -310,6 +310,22 @@ def generate_cover( exc_info=True, ) + # 步骤 D:从 plan.config.cover_candidates 读取(Worker 渲染时写入) + if not cover_url_from_task: + _candidates = (plan.config or {}).get("cover_candidates") or [] + if isinstance(_candidates, list) and _candidates: + _first = _candidates[0] + if isinstance(_first, dict): + cover_url_from_task = ( + _first.get("image_url") or _first.get("url") or "" + ) + if cover_url_from_task: + logger.info( + "[封面生成] 统一管道封面(步骤D-cover_candidates): plan_id=%s url=%s", + plan_id, + cover_url_from_task[:80], + ) + if cover_url_from_task: # 标题已在预览视频渲染时烧录(ASS字幕),封面帧自然包含标题 cover_data = { @@ -325,7 +341,7 @@ def generate_cover( return GenerateCoverResponse(plan_id=plan_id, cover=cover_data) logger.warning( - "[封面生成] 统一管道未找到 cover_url: plan_id=%s", + "[封面生成] 统一管道未找到 cover_url (A/B/C/D均未命中): plan_id=%s", plan_id, ) # ai_frame/ai_regenerate 类型必须从渲染管道获取,不再回退到 AI 服务