refactor: 拆分templates_editor.py巨无霸为16个模块 #806

Merged
xiaoxia merged 1 commits from refactor/split-templates-editor into develop 2026-07-24 10:24:50 +08:00
Owner

背景

templates_editor.py 膨胀到 2560 行,47 个路由端点,维护成本高。

改动

按功能模块拆分巨无霸文件,保持路由路径和行为完全不变:

文件 行数 职责
schemas.py 622 所有 Pydantic model(40+个)
clips.py 318 片段管理(CRUD/分割/合并/重排/批量删除)
generation.py 250 生成(触发/进度/记录)
cover.py 209 封面管理 + AI 生成封面
effects.py 195 转场 + 滤镜
subtitles.py 173 字幕管理
adjustments.py 166 片段调整(速度/音量/裁剪)
draft.py 164 草稿管理(详情/更新/发布/版本/回滚)
_fallback.py 163 自动兜底逻辑(生成前4步自动修复)
dependencies.py 141 依赖注入
bgm.py 133 BGM 管理
ai_features.py 121 AI 推荐
_utils.py 109 工具函数
export.py 106 导出配置
__init__.py 67 主入口,聚合所有子路由
timeline.py 61 时间线

向后兼容

  • 路由路径、请求/响应格式完全不变
  • __init__.py re-export 了 routerget_current_userget_db_sessionget_draft_plan_idget_editor_services,外部引用无需修改
  • router.py 中的 from app.api.routes.templates_editor import router 继续工作

测试

  • 37 个模板编辑器 API 测试:全绿
  • 107 个 edit_plan / edit_template 服务测试:全绿
## 背景 templates_editor.py 膨胀到 2560 行,47 个路由端点,维护成本高。 ## 改动 按功能模块拆分巨无霸文件,保持路由路径和行为完全不变: | 文件 | 行数 | 职责 | |------|------|------| | schemas.py | 622 | 所有 Pydantic model(40+个) | | clips.py | 318 | 片段管理(CRUD/分割/合并/重排/批量删除) | | generation.py | 250 | 生成(触发/进度/记录) | | cover.py | 209 | 封面管理 + AI 生成封面 | | effects.py | 195 | 转场 + 滤镜 | | subtitles.py | 173 | 字幕管理 | | adjustments.py | 166 | 片段调整(速度/音量/裁剪) | | draft.py | 164 | 草稿管理(详情/更新/发布/版本/回滚) | | _fallback.py | 163 | 自动兜底逻辑(生成前4步自动修复) | | dependencies.py | 141 | 依赖注入 | | bgm.py | 133 | BGM 管理 | | ai_features.py | 121 | AI 推荐 | | _utils.py | 109 | 工具函数 | | export.py | 106 | 导出配置 | | __init__.py | 67 | 主入口,聚合所有子路由 | | timeline.py | 61 | 时间线 | ## 向后兼容 - 路由路径、请求/响应格式完全不变 - `__init__.py` re-export 了 `router`、`get_current_user`、`get_db_session`、`get_draft_plan_id`、`get_editor_services`,外部引用无需修改 - router.py 中的 `from app.api.routes.templates_editor import router` 继续工作 ## 测试 - 37 个模板编辑器 API 测试:全绿 ✅ - 107 个 edit_plan / edit_template 服务测试:全绿 ✅
xiaoxia added 1 commit 2026-07-24 08:19:56 +08:00
refactor: 拆分templates_editor.py巨无霸为16个模块
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 57s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 55s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m59s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m16s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 2m34s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 53s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m22s
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 35s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m43s
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 6m41s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m11s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 3m26s
AI Code Review / AI Code Review (pull_request) Successful in 9m6s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 10m58s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 19s
c34603125d
将2560行的templates_editor.py按功能拆分为独立模块:
- schemas.py: 所有Pydantic model(40+个)
- dependencies.py: 依赖注入(get_editor_services/get_draft_plan_id)
- _utils.py: 工具函数(时间格式化/片段调整辅助等)
- _fallback.py: 自动兜底逻辑(生成前的4步自动修复)
- draft.py: 草稿管理(详情/更新/发布/版本/回滚)
- clips.py: 片段管理(CRUD/分割/合并/重排/批量删除)
- adjustments.py: 片段调整(速度/音量/裁剪/批量调速)
- bgm.py: BGM管理
- effects.py: 转场+滤镜
- export.py: 导出配置
- cover.py: 封面管理+AI生成封面
- subtitles.py: 字幕管理
- ai_features.py: AI推荐
- generation.py: 生成(触发/进度/记录)
- timeline.py: 时间线

保持所有路由路径和行为完全不变,37个模板编辑器API测试全绿,
107个edit_plan/edit_template服务测试全绿。
xiaoxia merged commit 9652e9e892 into develop 2026-07-24 10:24:50 +08:00
xiaoxia deleted branch refactor/split-templates-editor 2026-07-24 10:24:50 +08:00

🗑️ 预览环境已清理

PR #806 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #806 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Sign in to join this conversation.