This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
@ -73,15 +74,19 @@ func (s *SiteSettings) GetBool(key string, defaultVal bool) bool {
|
||||
// Set 写入设置(同步写 DB + 更新内存,使用 UPSERT 兼容首次保存)
|
||||
func (s *SiteSettings) Set(key, value string) error {
|
||||
entry := model.SiteSetting{Key: key, Value: value}
|
||||
if err := s.db.Clauses(clause.OnConflict{
|
||||
result := s.db.Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "key"}},
|
||||
DoUpdates: clause.AssignmentColumns([]string{"value"}),
|
||||
}).Create(&entry).Error; err != nil {
|
||||
return err
|
||||
}).Create(&entry)
|
||||
if result.Error != nil {
|
||||
log.Printf("[SiteSettings] Set FAIL key=%s value=%s err=%v", key, value, result.Error)
|
||||
return result.Error
|
||||
}
|
||||
s.mu.Lock()
|
||||
oldVal, existed := s.data[key]
|
||||
s.data[key] = value
|
||||
s.mu.Unlock()
|
||||
log.Printf("[SiteSettings] Set OK key=%s old=%q new=%q existed=%v rows=%d", key, oldVal, value, existed, result.RowsAffected)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@ -87,6 +88,10 @@ func (sc *SiteSettingController) ThemePage(c *gin.Context) {
|
||||
func (sc *SiteSettingController) GetSettings(c *gin.Context) {
|
||||
all := sc.settingService.GetSettings()
|
||||
audit := sc.settingService.GetAuditSettings(sc.defaults)
|
||||
log.Printf("[GetSettings] all=%d keys audit=%+v", len(all), audit)
|
||||
if v, ok := all["registration.enabled"]; ok {
|
||||
log.Printf("[GetSettings] registration.enabled=%q", v)
|
||||
}
|
||||
common.Ok(c, gin.H{
|
||||
"all": all,
|
||||
"audit": audit,
|
||||
|
||||
Reference in New Issue
Block a user