@@ -114,13 +114,17 @@ func GetSettingWithCache(ctx context.Context, key, defaultVal string) (string, e
114
114
115
115
// GetSettingBool return bool value of setting,
116
116
// none existing keys and errors are ignored and result in false
117
- func GetSettingBool (ctx context.Context , key string ) bool {
118
- s , _ := GetSetting (ctx , key )
119
- if s == nil {
120
- return false
117
+ func GetSettingBool (ctx context.Context , key string , defaultVal bool ) (bool , error ) {
118
+ s , err := GetSetting (ctx , key )
119
+ switch {
120
+ case err == nil :
121
+ v , _ := strconv .ParseBool (s .SettingValue )
122
+ return v , nil
123
+ case IsErrSettingIsNotExist (err ):
124
+ return defaultVal , nil
125
+ default :
126
+ return false , err
121
127
}
122
- v , _ := strconv .ParseBool (s .SettingValue )
123
- return v
124
128
}
125
129
126
130
func GetSettingWithCacheBool (ctx context.Context , key string , defaultVal bool ) bool {
@@ -265,38 +269,27 @@ var (
265
269
)
266
270
267
271
func Init (ctx context.Context ) error {
268
- var disableGravatar bool
269
- disableGravatarSetting , err := GetSetting (ctx , KeyPictureDisableGravatar )
270
- if IsErrSettingIsNotExist (err ) {
271
- disableGravatar = setting_module .GetDefaultDisableGravatar ()
272
- disableGravatarSetting = & Setting {SettingValue : strconv .FormatBool (disableGravatar )}
273
- } else if err != nil {
272
+ disableGravatar , err := GetSettingBool (ctx , KeyPictureDisableGravatar , false )
273
+ if err != nil {
274
274
return err
275
- } else {
276
- disableGravatar = disableGravatarSetting .GetValueBool ()
277
275
}
278
276
279
- var enableFederatedAvatar bool
280
- enableFederatedAvatarSetting , err := GetSetting (ctx , KeyPictureEnableFederatedAvatar )
281
- if IsErrSettingIsNotExist (err ) {
282
- enableFederatedAvatar = setting_module .GetDefaultEnableFederatedAvatar (disableGravatar )
283
- } else if err != nil {
277
+ enableFederatedAvatar , err := GetSettingBool (ctx , KeyPictureEnableFederatedAvatar , setting_module .GetDefaultEnableFederatedAvatar (disableGravatar ))
278
+ if err != nil {
284
279
return err
285
- } else {
286
- enableFederatedAvatar = enableFederatedAvatarSetting .GetValueBool ()
287
280
}
288
281
289
282
if setting_module .OfflineMode {
290
- disableGravatar = true
291
- enableFederatedAvatar = false
292
- if ! GetSettingBool (ctx , KeyPictureDisableGravatar ) {
283
+ if ! disableGravatar {
293
284
if err := SetSettingNoVersion (ctx , KeyPictureDisableGravatar , "true" ); err != nil {
294
- return fmt .Errorf ("Failed to set setting %q: %w" , KeyPictureDisableGravatar , err )
285
+ return fmt .Errorf ("failed to set setting %q: %w" , KeyPictureDisableGravatar , err )
295
286
}
296
287
}
297
- if GetSettingBool (ctx , KeyPictureEnableFederatedAvatar ) {
288
+ disableGravatar = true
289
+
290
+ if enableFederatedAvatar {
298
291
if err := SetSettingNoVersion (ctx , KeyPictureEnableFederatedAvatar , "false" ); err != nil {
299
- return fmt .Errorf ("Failed to set setting %q: %w" , KeyPictureEnableFederatedAvatar , err )
292
+ return fmt .Errorf ("failed to set setting %q: %w" , KeyPictureEnableFederatedAvatar , err )
300
293
}
301
294
}
302
295
}
@@ -305,7 +298,7 @@ func Init(ctx context.Context) error {
305
298
var err error
306
299
GravatarSourceURL , err = url .Parse (setting_module .GravatarSource )
307
300
if err != nil {
308
- return fmt .Errorf ("Failed to parse Gravatar URL(%s): %w" , setting_module .GravatarSource , err )
301
+ return fmt .Errorf ("failed to parse Gravatar URL(%s): %w" , setting_module .GravatarSource , err )
309
302
}
310
303
}
311
304
0 commit comments