refactor: ByteMD 迁移至 Tiptap WYSIWYG 编辑器 + Token 刷新优化

- 移除 ByteMD CDN 资源和 goldmark 依赖,替换为 Tiptap ESM 模块
- 编辑器从源码编辑模式改为 WYSIWYG 所见即所得
- 移除 /api/posts/preview 预览接口(Tiptap 直接输出 HTML 无需后端渲染)
- 保留 UploadImage 图片上传接口和 bluemonday HTML 消毒
- 工具栏支持加粗、斜体、删除线、代码、标题、列表、引用、代码块、分割线、撤销/重做
- 支持图片粘贴/拖拽上传,Ctrl+S 快捷提交,F11 全屏,字数统计
- 优化 common.js:自动 401 拦截 Token 刷新,修复刷新死循环
- 草稿 localStorage 键名更新为 draft_post_body_html
This commit is contained in:
2026-05-28 11:21:53 +08:00
parent 22a302315a
commit 69ba2fb01b
11 changed files with 467 additions and 166 deletions

View File

@ -25,7 +25,7 @@ type rateLimiter interface {
Clear(email, ip string)
}
// postUseCase PostController 对 PostService 的最小依赖ISP8 个方法)
// postUseCase PostController 对 PostService 的最小依赖ISP6 个方法)
type postUseCase interface {
Create(userID uint, title, body string) (*model.Post, error)
GetByID(id uint) (*model.Post, error)
@ -33,5 +33,4 @@ type postUseCase interface {
Update(postID uint, title, body string) error
Delete(postID uint) error
SubmitForAudit(postID uint) error
RenderMarkdown(body string) (string, error)
}

View File

@ -306,25 +306,6 @@ func (ctrl *PostController) ShowAPI(c *gin.Context) {
common.Ok(c, post)
}
// PreviewAPI Markdown 预览 API
func (ctrl *PostController) PreviewAPI(c *gin.Context) {
var req struct {
Body string `json:"body" binding:"required"`
}
if err := c.ShouldBindJSON(&req); err != nil {
common.Error(c, http.StatusBadRequest, "正文不能为空")
return
}
html, err := ctrl.postService.RenderMarkdown(req.Body)
if err != nil {
common.Error(c, http.StatusInternalServerError, "渲染失败")
return
}
common.Ok(c, gin.H{"html": html})
}
// allowedImageExt 允许的图片扩展名
var allowedImageExt = map[string]bool{
".jpg": true, ".jpeg": true, ".png": true, ".gif": true, ".webp": true,