diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-10-17 07:29:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-17 07:29:26 +0800 |
commit | f860a6d2e4177ed4f4c2a58a07882bd00a1a52ad (patch) | |
tree | 93abb2f354576e50c87d70b0b4bb46369fb3a1f1 /modules/setting | |
parent | 5d3dbffa150d832d2f9aedd9f90ca91178a95f9c (diff) | |
download | gitea-f860a6d2e4177ed4f4c2a58a07882bd00a1a52ad.tar.gz gitea-f860a6d2e4177ed4f4c2a58a07882bd00a1a52ad.zip |
Add system setting table with cache and also add cache supports for user setting (#18058)
Diffstat (limited to 'modules/setting')
-rw-r--r-- | modules/setting/picture.go | 60 | ||||
-rw-r--r-- | modules/setting/setting.go | 7 |
2 files changed, 28 insertions, 39 deletions
diff --git a/modules/setting/picture.go b/modules/setting/picture.go index a6d3447dcc..af9041ade3 100644 --- a/modules/setting/picture.go +++ b/modules/setting/picture.go @@ -4,14 +4,6 @@ package setting -import ( - "net/url" - - "code.gitea.io/gitea/modules/log" - - "strk.kbt.io/projects/go/libravatar" -) - // settings var ( // Picture settings @@ -30,10 +22,8 @@ var ( } GravatarSource string - GravatarSourceURL *url.URL - DisableGravatar bool - EnableFederatedAvatar bool - LibravatarService *libravatar.Libravatar + DisableGravatar bool // Depreciated: migrated to database + EnableFederatedAvatar bool // Depreciated: migrated to database RepoAvatar = struct { Storage @@ -69,38 +59,30 @@ func newPictureService() { default: GravatarSource = source } - DisableGravatar = sec.Key("DISABLE_GRAVATAR").MustBool() - EnableFederatedAvatar = sec.Key("ENABLE_FEDERATED_AVATAR").MustBool(!InstallLock) - if OfflineMode { - DisableGravatar = true - EnableFederatedAvatar = false - } - if DisableGravatar { - EnableFederatedAvatar = false - } - if EnableFederatedAvatar || !DisableGravatar { - var err error - GravatarSourceURL, err = url.Parse(GravatarSource) - if err != nil { - log.Fatal("Failed to parse Gravatar URL(%s): %v", - GravatarSource, err) - } - } - if EnableFederatedAvatar { - LibravatarService = libravatar.New() - if GravatarSourceURL.Scheme == "https" { - LibravatarService.SetUseHTTPS(true) - LibravatarService.SetSecureFallbackHost(GravatarSourceURL.Host) - } else { - LibravatarService.SetUseHTTPS(false) - LibravatarService.SetFallbackHost(GravatarSourceURL.Host) - } - } + DisableGravatar = sec.Key("DISABLE_GRAVATAR").MustBool(GetDefaultDisableGravatar()) + deprecatedSettingDB("", "DISABLE_GRAVATAR") + EnableFederatedAvatar = sec.Key("ENABLE_FEDERATED_AVATAR").MustBool(GetDefaultEnableFederatedAvatar(DisableGravatar)) + deprecatedSettingDB("", "ENABLE_FEDERATED_AVATAR") newRepoAvatarService() } +func GetDefaultDisableGravatar() bool { + return !OfflineMode +} + +func GetDefaultEnableFederatedAvatar(disableGravatar bool) bool { + v := !InstallLock + if OfflineMode { + v = false + } + if disableGravatar { + v = false + } + return v +} + func newRepoAvatarService() { sec := Cfg.Section("picture") diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 007e3ef61f..f93be2fbd1 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -606,6 +606,13 @@ func deprecatedSetting(oldSection, oldKey, newSection, newKey string) { } } +// deprecatedSettingDB add a hint that the configuration has been moved to database but still kept in app.ini +func deprecatedSettingDB(oldSection, oldKey string) { + if Cfg.Section(oldSection).HasKey(oldKey) { + log.Error("Deprecated `[%s]` `%s` present which has been copied to database table sys_setting", oldSection, oldKey) + } +} + // loadFromConf initializes configuration context. // NOTE: do not print any log except error. func loadFromConf(allowEmpty bool, extraConfig string) { |