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