feat: implement template service with builtin and custom templates

- BUILTIN_TEMPLATES: 4 presets (正方形/纵向/横向长方形/左胸小号)
- load_custom_templates(): reads templates.json, skips corrupt entries
  individually so one bad record never blocks the rest
- get_all_templates(): builtin first, then custom
- add_template(): upsert by name, forces type="custom"
- rename_template() / delete_template(): raise ValueError if not found
- _save_custom_templates(): auto-creates config/ dir, logs on failure

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-15 17:01:40 +08:00
co-authored by Claude Sonnet 4.6
parent 2d9121e3e0
commit 519bb9a6d2
2 changed files with 201 additions and 12 deletions
+10 -10
View File
@@ -185,19 +185,19 @@
任务:
- [ ] 先读取 `src/services/template_service.py` 现有内容
- [ ] 完善 `src/services/template_service.py`
- [ ] 定义内置模板
- [ ] 支持读取自定义模板 JSON
- [ ] 支持保存自定义模板 JSON
- [ ] 支持新增、重命名、删除自定义模板
- [ ] 校验模板字段
- [x] 先读取 `src/services/template_service.py` 现有内容
- [x] 完善 `src/services/template_service.py`
- [x] 定义内置模板
- [x] 支持读取自定义模板 JSON
- [x] 支持保存自定义模板 JSON
- [x] 支持新增、重命名、删除自定义模板
- [x] 校验模板字段
验收:
- [ ] 内置模板和自定义模板可区分
- [ ] 单个模板损坏不影响全部模板加载
- [ ] UI 不直接操作模板 JSON 文件
- [x] 内置模板和自定义模板可区分
- [x] 单个模板损坏不影响全部模板加载
- [x] UI 不直接操作模板 JSON 文件
## 5. 图片合成核心