升级帖子编辑与 Feed 体验:TipTap 富文本、修订历史、排序与编辑时限。
将 Markdown 编辑器替换为 TipTap WYSIWYG,新增帖子修订记录与 diff 展示;首页支持最新/回复排序与本地缓存;后台可配置编辑时限与锁定帖子;侧边栏整合板块导航并优化 Feed 布局。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
70
service/settings.go
Normal file
70
service/settings.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"git.iioio.com/freefire/jiang13-forum/model"
|
||||
)
|
||||
|
||||
const (
|
||||
SettingPostEditWindowHours = "post_edit_window_hours"
|
||||
defaultEditWindowHours = 24
|
||||
)
|
||||
|
||||
// ForumSettingsService 论坛全局设置
|
||||
type ForumSettingsService struct {
|
||||
mu sync.RWMutex
|
||||
}
|
||||
|
||||
func NewForumSettingsService() *ForumSettingsService {
|
||||
s := &ForumSettingsService{}
|
||||
s.ensureDefaults()
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *ForumSettingsService) ensureDefaults() {
|
||||
var count int64
|
||||
model.DB.Model(&model.ForumSetting{}).Where("`key` = ?", SettingPostEditWindowHours).Count(&count)
|
||||
if count == 0 {
|
||||
model.DB.Create(&model.ForumSetting{
|
||||
Key: SettingPostEditWindowHours,
|
||||
Value: strconv.Itoa(defaultEditWindowHours),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// PostEditWindowHours 返回用户可编辑帖子的时限(小时),0 表示不限
|
||||
func (s *ForumSettingsService) PostEditWindowHours() int {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
var setting model.ForumSetting
|
||||
if err := model.DB.First(&setting, "`key` = ?", SettingPostEditWindowHours).Error; err != nil {
|
||||
return defaultEditWindowHours
|
||||
}
|
||||
h, err := strconv.Atoi(setting.Value)
|
||||
if err != nil || h < 0 {
|
||||
return defaultEditWindowHours
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
// SetPostEditWindowHours 设置编辑时限(小时),0 表示不限
|
||||
func (s *ForumSettingsService) SetPostEditWindowHours(hours int) error {
|
||||
if hours < 0 {
|
||||
return ErrInvalidSetting
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return model.DB.Save(&model.ForumSetting{
|
||||
Key: SettingPostEditWindowHours,
|
||||
Value: strconv.Itoa(hours),
|
||||
}).Error
|
||||
}
|
||||
|
||||
// ForumSettings 返回所有可配置的论坛设置
|
||||
func (s *ForumSettingsService) ForumSettings() map[string]int {
|
||||
return map[string]int{
|
||||
"post_edit_window_hours": s.PostEditWindowHours(),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user