mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-06-05 12:44:22 +00:00
fix(settings): fall back to defaults for empty/NULL setting values
A setting row whose value column is empty or NULL (seen on some migrated databases) was parsed directly, so getInt/getBool and the GetAllSetting reflection path crashed with 'strconv.Atoi: parsing "": invalid syntax'. This made the Inbounds page (/defaultSettings -> GetPageSize) and the Settings page fail to load. Treat an empty stored value the same as a missing row and fall back to the built-in default at the int/bool parse sites. String getters are unchanged, so legitimately-empty string settings stay empty. Closes #4830
This commit is contained in:
parent
a40d85ce53
commit
fcc6787a64
1 changed files with 13 additions and 4 deletions
|
|
@ -166,7 +166,7 @@ func (s *SettingService) GetAllSetting() (*entity.AllSetting, error) {
|
||||||
fieldV := v.FieldByName(field.Name)
|
fieldV := v.FieldByName(field.Name)
|
||||||
switch t := fieldV.Interface().(type) {
|
switch t := fieldV.Interface().(type) {
|
||||||
case int:
|
case int:
|
||||||
n, err := strconv.ParseInt(value, 10, 64)
|
n, err := strconv.ParseInt(effectiveSettingValue(key, value), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -174,7 +174,7 @@ func (s *SettingService) GetAllSetting() (*entity.AllSetting, error) {
|
||||||
case string:
|
case string:
|
||||||
fieldV.SetString(value)
|
fieldV.SetString(value)
|
||||||
case bool:
|
case bool:
|
||||||
fieldV.SetBool(value == "true")
|
fieldV.SetBool(effectiveSettingValue(key, value) == "true")
|
||||||
default:
|
default:
|
||||||
return common.NewErrorf("unknown field %v type %v", key, t)
|
return common.NewErrorf("unknown field %v type %v", key, t)
|
||||||
}
|
}
|
||||||
|
|
@ -286,12 +286,21 @@ func (s *SettingService) setString(key string, value string) error {
|
||||||
return s.saveSetting(key, value)
|
return s.saveSetting(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func effectiveSettingValue(key, stored string) string {
|
||||||
|
if stored == "" {
|
||||||
|
if def, ok := defaultValueMap[key]; ok {
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stored
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SettingService) getBool(key string) (bool, error) {
|
func (s *SettingService) getBool(key string) (bool, error) {
|
||||||
str, err := s.getString(key)
|
str, err := s.getString(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
return strconv.ParseBool(str)
|
return strconv.ParseBool(effectiveSettingValue(key, str))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SettingService) setBool(key string, value bool) error {
|
func (s *SettingService) setBool(key string, value bool) error {
|
||||||
|
|
@ -303,7 +312,7 @@ func (s *SettingService) getInt(key string) (int, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return strconv.Atoi(str)
|
return strconv.Atoi(effectiveSettingValue(key, str))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SettingService) setInt(key string, value int) error {
|
func (s *SettingService) setInt(key string, value int) error {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue