fix: add node settings to defaultValueMap and settingGroups

Node settings (nodeRole, nodeId, syncInterval, trafficFlushInterval)
now have defaults in the settings system. On fresh install, they are
automatically created in x-ui.json under the 'node' group. The
settingGroupAliases now look in 'node' first, then 'other' for
backward compatibility.
This commit is contained in:
root 2026-04-24 20:57:12 +08:00
parent d5bf2858ce
commit d733ff2af1
3 changed files with 32 additions and 17 deletions

View file

@ -148,14 +148,10 @@ var settingGroupAliases = map[string][]string{
"dbUser": {"databaseConnection", "other"}, "dbUser": {"databaseConnection", "other"},
"dbPassword": {"databaseConnection", "other"}, "dbPassword": {"databaseConnection", "other"},
"dbName": {"databaseConnection", "other"}, "dbName": {"databaseConnection", "other"},
"nodeRole": {"other"}, "nodeRole": {"node", "other"},
"nodeId": {"other"}, "nodeId": {"node", "other"},
"syncInterval": { "syncInterval": {"node", "other"},
"other", "trafficFlushInterval": {"node", "other"},
},
"trafficFlushInterval": {
"other",
},
} }
func readGroupedString(settings map[string]any, key string) string { func readGroupedString(settings map[string]any, key string) string {
@ -214,10 +210,10 @@ func settingsLayoutMeta() map[string]any {
} }
func ensureDefaultNodeSettings(settings map[string]any) { func ensureDefaultNodeSettings(settings map[string]any) {
group, ok := settings["other"].(map[string]any) group, ok := settings["node"].(map[string]any)
if !ok { if !ok {
group = make(map[string]any) group = make(map[string]any)
settings["other"] = group settings["node"] = group
} }
defaults := map[string]string{ defaults := map[string]string{
@ -228,6 +224,13 @@ func ensureDefaultNodeSettings(settings map[string]any) {
} }
for key, value := range defaults { for key, value := range defaults {
if existing, exists := group[key]; !exists || existing == nil { if existing, exists := group[key]; !exists || existing == nil {
// Also check "other" group for backward compatibility
if otherGroup, ok := settings["other"].(map[string]any); ok {
if val, ok := otherGroup[key].(string); ok && val != "" {
group[key] = val
continue
}
}
group[key] = value group[key] = value
} }
} }

View file

@ -1 +1 @@
v1.6.2 v1.6.3

View file

@ -140,6 +140,12 @@ rules:
"dbUser": "", "dbUser": "",
"dbPassword": "", "dbPassword": "",
"dbName": "3xui", "dbName": "3xui",
// Node settings
"nodeRole": "master",
"nodeId": "",
"syncInterval": "30",
"trafficFlushInterval": "10",
} }
// settingGroups defines the nested JSON structure for on-disk settings. // settingGroups defines the nested JSON structure for on-disk settings.
@ -251,6 +257,12 @@ var settingGroups = map[string]map[string]string{
"dbPassword": "dbPassword", "dbPassword": "dbPassword",
"dbName": "dbName", "dbName": "dbName",
}, },
"node": {
"nodeRole": "nodeRole",
"nodeId": "nodeId",
"syncInterval": "syncInterval",
"trafficFlushInterval": "trafficFlushInterval",
},
} }
var legacySettingGroups = map[string]map[string]string{ var legacySettingGroups = map[string]map[string]string{