评论区改用公共 Markdown 编辑器(不含隐藏内容),并忽略 GORM 未命中日志噪音。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-20 10:36:41 +08:00
parent 803b694659
commit e598782279
6 changed files with 126 additions and 67 deletions

View File

@@ -302,6 +302,9 @@ func (s *CommentService) Create(userID, postID uint, content string, parentID *u
if content == "" {
return nil, nil, errors.New("评论内容不能为空")
}
if err := rejectHideBlocks(content, ErrCommentHideNotAllowed); err != nil {
return nil, nil, err
}
if status != model.ContentStatusPending && status != model.ContentStatusPublished {
status = model.ContentStatusPending
}
@@ -584,6 +587,9 @@ func (s *CommentService) Update(actor *Actor, commentID, userID uint, content st
if content == "" {
return nil, errors.New("评论内容不能为空")
}
if err := rejectHideBlocks(content, ErrCommentHideNotAllowed); err != nil {
return nil, err
}
var comment model.Comment
if err := s.db.Unscoped().First(&comment, commentID).Error; err != nil {
return nil, ErrCommentNotFound

View File

@@ -11,6 +11,8 @@ var (
ErrAnnouncementReplyHideNotAllowed = errors.New("公告不可评论,不能使用回复可见")
// ErrSitePageHideNotAllowed 站点单页正文禁止 [hide](本轮单页仍无评论/解锁)
ErrSitePageHideNotAllowed = errors.New("页面不支持隐藏内容")
// ErrCommentHideNotAllowed 评论无隐藏解锁流程,禁止 [hide]
ErrCommentHideNotAllowed = errors.New("评论不支持隐藏内容")
)
// rejectHideBlocks 若正文含 [hide] 开标记(忽略代码围栏内伪语法)则返回指定错误。