43 lines
3.0 KiB
Markdown
43 lines
3.0 KiB
Markdown
# API 化改造 Todo
|
||
|
||
操作接口改为 `/api/` 前缀的 JSON API(POST/PUT/DELETE、码+文案错误响应),页面路由保持不变。
|
||
|
||
## 基建(high)
|
||
|
||
- [x] 1. 新建 `handlers/api.go`:`APIError(c, status, trKey)`、`APIOK(c, redirect, data)`、JSON 绑定/解析 helper
|
||
- [x] 2. `middleware/auth.go`:`AuthRequired`/`AdminRequired` 按 `/api` 路径前缀分支 401/403 JSON(非 API 保持 302)
|
||
- [x] 3. `main.go`:注册 `/api` 分组(auth/article/admin/profile/my 子组)+ gin 静态/参数路由冲突冒烟测试(新增 `TestRegisterRoutesSmoke`,含附件端点搬移,`LoginRateLimiter` 导出)
|
||
- [x] 4. `templates/layouts/base.html`:增加 `blogAPI`/`blogForm`/`blogShowError` 共享 fetch 助手(CSRF 头、`e.submitter` 状态按钮、bool 复选框转换)
|
||
|
||
## 零行为搬移(medium)
|
||
|
||
- [x] 5. 附件三件套(admin/my)+ `/api/profile/avatar` 换注册路径(路由已在基建 commit 搬移)
|
||
- [x] 6. 搬移端点模板更新:`article_create.html` 3 处 fetch URL、`profile.html` 1 处(删除改用 DELETE)
|
||
|
||
## 功能改造(medium)
|
||
|
||
- [x] 7. 认证 API:`auth.go` Login/Register/Logout JSON 化(429 限流、会话轮换保留)
|
||
- [x] 8. 认证模板:`login.html`/`register.html` 改 fetch + 错误 div `id`;base.html logout 改 fetch(logout-form 全局委托)
|
||
- [x] 9. 评论 API:`comment.go` PostComment JSON 化(校验码复用 i18n 键)
|
||
- [x] 10. 评论 API:`admin_comment.go` approve/reject/delete JSON 化
|
||
- [x] 11. 评论模板:`article.html` 评论表单 fetch、`comment_list.html` 操作后 reload
|
||
- [x] 12. 文章 CRUD API:`article.go`/`my_articles.go` 去 renderForm/Redirect 改 JSON(表单字段加 json tag)
|
||
- [x] 13. 文章模板:`article_create.html`/`my_article_form.html`/`article_list.html`/`my_articles.html` 改 fetch(`easyMDE.value()`、`e.submitter`)
|
||
- [x] 14. 用户 API:`admin_user.go` UserCreate/Update/Delete JSON 化(自防/最后管理员拦截改 403)
|
||
- [x] 15. 用户模板:`user_form.html`/`user_list.html` 改 fetch
|
||
- [x] 16. 设置 API:`settings.go` 5 组 save JSON 化;site favicon/logo 拆出 `POST /api/admin/settings/site/favicon|logo`
|
||
- [x] 17. 设置模板:`settings_site`/`settings_navlinks`/`settings_upload`/`settings_download`/`settings_comment` 5 页改 fetch(blogSettingsForm 委托)
|
||
- [x] 18. 个人资料 API:`profile.go` UpdateProfile JSON 化(头像走 `/api/profile/avatar`)
|
||
- [x] 19. 个人资料模板:`profile.html` 文本表单改 fetch
|
||
|
||
## 测试与收尾(high)
|
||
|
||
- [x] 20. 新增 `handlers/api_test.go`:happy path / 校验码 / 401 / 403 / CSRF 头 / 429 / 409
|
||
- [x] 21. 更新 `security_test.go`/`p2_validation_test.go`/`p3_upload_test.go`/`session_upload_security_test.go` 到新 URL 与 JSON 断言
|
||
- [x] 22. `go build/vet/test ./...`(含 -count=1 -race)全绿;README 路由表同步
|
||
|
||
## 执行说明
|
||
|
||
- 每步只改路由/响应层,不动解析校验逻辑(JSON binding 替换 PostForm 读取),单步可编译可测
|
||
- 并发状态:单一编辑者(本会话从第 1 项开始逐步执行)
|