From a570e4c7a06bf11b858864b502401a1f088ed10e Mon Sep 17 00:00:00 2001 From: Noah Hsu Date: Fri, 23 Sep 2022 20:37:49 +0800 Subject: [PATCH] fix: some settings don't take effect at startup --- internal/bootstrap/data/setting.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/bootstrap/data/setting.go b/internal/bootstrap/data/setting.go index 2c9d9b87a86..38b6df498b0 100644 --- a/internal/bootstrap/data/setting.go +++ b/internal/bootstrap/data/setting.go @@ -34,7 +34,7 @@ func initSettings() { // insert new items for i := range initialSettingItems { v := initialSettingItems[i] - _, err := db.GetSettingItemByKey(v.Key) + stored, err := db.GetSettingItemByKey(v.Key) if errors.Is(err, gorm.ErrRecordNotFound) || v.Key == conf.VERSION { err = db.SaveSettingItem(v) if err != nil { @@ -42,6 +42,11 @@ func initSettings() { } } else if err != nil { log.Fatalf("failed get setting: %+v", err) + } else { + err = db.SaveSettingItem(*stored) + if err != nil { + log.Fatalf("failed resave setting: %+v", err) + } } } } @@ -107,7 +112,7 @@ func InitialSettings() []model.SettingItem { // global settings {Key: conf.HideFiles, Value: "/\\/README.md/i", Type: conf.TypeText, Group: model.GLOBAL}, {Key: "package_download", Value: "true", Type: conf.TypeBool, Group: model.GLOBAL}, - {Key: conf.CustomizeHead,Value:``, Type: conf.TypeText, Group: model.GLOBAL, Flag: model.PRIVATE}, + {Key: conf.CustomizeHead, Value: ``, Type: conf.TypeText, Group: model.GLOBAL, Flag: model.PRIVATE}, {Key: conf.CustomizeBody, Type: conf.TypeText, Group: model.GLOBAL, Flag: model.PRIVATE}, {Key: conf.LinkExpiration, Value: "0", Type: conf.TypeNumber, Group: model.GLOBAL, Flag: model.PRIVATE}, {Key: conf.PrivacyRegs, Value: `(?:(?:\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])