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

@ -142,20 +142,16 @@ func GetLogFolder() string {
}
var settingGroupAliases = map[string][]string{
"dbType": {"databaseConnection", "other"},
"dbHost": {"databaseConnection", "other"},
"dbPort": {"databaseConnection", "other"},
"dbUser": {"databaseConnection", "other"},
"dbPassword": {"databaseConnection", "other"},
"dbName": {"databaseConnection", "other"},
"nodeRole": {"other"},
"nodeId": {"other"},
"syncInterval": {
"other",
},
"trafficFlushInterval": {
"other",
},
"dbType": {"databaseConnection", "other"},
"dbHost": {"databaseConnection", "other"},
"dbPort": {"databaseConnection", "other"},
"dbUser": {"databaseConnection", "other"},
"dbPassword": {"databaseConnection", "other"},
"dbName": {"databaseConnection", "other"},
"nodeRole": {"node", "other"},
"nodeId": {"node", "other"},
"syncInterval": {"node", "other"},
"trafficFlushInterval": {"node", "other"},
}
func readGroupedString(settings map[string]any, key string) string {
@ -214,10 +210,10 @@ func settingsLayoutMeta() 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 {
group = make(map[string]any)
settings["other"] = group
settings["node"] = group
}
defaults := map[string]string{
@ -228,6 +224,13 @@ func ensureDefaultNodeSettings(settings map[string]any) {
}
for key, value := range defaults {
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
}
}

View file

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

View file

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