fix: 预览分辨率自动从模板mode推断(Fix3补充) #1230
Reference in New Issue
Block a user
Delete Branch "fix/preview-resolution-auto-infer"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
问题
PR #1229 的 Fix3 修复了 worker 端的渲染分辨率逻辑(尊重传入的 resolution 参数),但 API 层创建预览任务时,
_calc_preview_resolution(request.video_ratio)在前端未传video_ratio时默认返回854x480(横屏),导致竖屏模板(mode=pip)仍被渲染为横屏。修复
_infer_video_ratio_from_template()函数:当前端未传video_ratio时,从模板mode字段推断视频比例pip→9:16→480x854standard→16:9→854x480square→1:1→480x480db: Session依赖,用于查询模板测试
TestInferVideoRatioFromTemplate: 6 个测试(pip/standard/unknown/不存在/空ID/DB异常)TestPreviewRouteAutoInfersVideoRatio: 集成测试验证路由自动推断🚀 预览环境已部署
【阻塞级判定】
📊 审查概览
🔴 阻塞级问题(必须修复)
无
💡 改进建议(不阻塞合并)
[apps/api/app/api/routes/generation_preview.py: 28] 依赖注入解耦
SQLAlchemyTemplateRepository(from packages.adapters...) 增加了 API 层与具体数据库适配器的耦合度。建议在app.dependencies中创建get_template_repository依赖工厂函数,遵循依赖倒置原则,便于后续测试或替换存储实现。[apps/api/app/api/routes/generation_preview.py: 76] 异常捕获范围
_infer_video_ratio_from_template函数中使用了裸except Exception:。虽然这里作为辅助函数且返回空字符串作为降级处理是合理的,但捕获过于宽泛。建议捕获具体的数据库异常(如SQLAlchemyError),避免掩盖非预期的系统级错误(如内存错误等),虽然在此处概率极低,但更严谨的做法是只捕获预期的异常。✅ 良好实践
video_ratio时(如模板不存在或查询异常),代码优雅地降级为空字符串,交由后续逻辑使用默认分辨率,保证了核心流程不中断。UserPendingLimitExceeded的错误信息从笼统的提示改为包含具体数量({e.pending_count - 1}/{e.limit}),提升了用户体验。✅ 格式检查通过 | ✅ 逻辑审查通过 | ✅ 性能无需关注
🤖 由 AI 代码审查机器人自动生成 | 2026-08-03 17:03:49 | 模型:
🗑️ 预览环境已清理
PR #1230 已关闭或合并,对应的预览环境已被清理。