feat(compose): 正文内嵌隐藏块并升级 Markdown 编辑器
去掉整帖可见性表单,改为 :::hide 按块脱敏;工具栏补齐代码块、链接/图片对话框与粘贴拖拽上传。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/freefire/jiang13-bbs/markdown"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
@@ -45,6 +46,11 @@ func InitDB(dsn string) error {
|
||||
return fmt.Errorf("自动迁移失败: %w", err)
|
||||
}
|
||||
|
||||
// 旧帖整帖可见性 → 正文 :::hide 块(幂等)
|
||||
if err := migratePostContentAccessToHideBlocks(db); err != nil {
|
||||
return fmt.Errorf("正文隐藏块迁移失败: %w", err)
|
||||
}
|
||||
|
||||
// 一次性:用签到累计回填 User.Points(仅余额仍为 0 且有签到积分的用户)
|
||||
if err := backfillPointsFromCheckin(db); err != nil {
|
||||
return fmt.Errorf("积分余额回填失败: %w", err)
|
||||
@@ -365,3 +371,39 @@ func ensureDefaultChatMemberships(db *gorm.DB) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// migratePostContentAccessToHideBlocks 将旧帖整帖可见性包进 :::hide 块(幂等)。
|
||||
func migratePostContentAccessToHideBlocks(db *gorm.DB) error {
|
||||
var posts []Post
|
||||
if err := db.Unscoped().
|
||||
Where("content_access IN ? AND deleted_at IS NULL",
|
||||
[]string{ContentAccessLogin, ContentAccessReply, ContentAccessPoints}).
|
||||
Find(&posts).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
n := 0
|
||||
for i := range posts {
|
||||
p := &posts[i]
|
||||
if markdown.HasHideBlocks(p.Content) {
|
||||
continue
|
||||
}
|
||||
kind := NormalizeContentAccess(p.ContentAccess)
|
||||
pts := 0
|
||||
if kind == ContentAccessPoints {
|
||||
pts = p.AccessPoints
|
||||
if pts <= 0 {
|
||||
pts = 1
|
||||
}
|
||||
}
|
||||
wrapped := markdown.WrapContentAsHide(kind, pts, p.Content)
|
||||
if err := db.Model(&Post{}).Where("id = ?", p.ID).
|
||||
Update("content", wrapped).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
n++
|
||||
}
|
||||
if n > 0 {
|
||||
log.Printf("[model] 旧帖可见性已迁入隐藏块:%d 篇", n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user