From d733ff2af128d642f3ab6445b2df6ff2cb38aa45 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 24 Apr 2026 20:57:12 +0800 Subject: [PATCH] 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. --- config/config.go | 35 +++++++++++++++++++---------------- config/version | 2 +- web/service/setting.go | 12 ++++++++++++ 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/config/config.go b/config/config.go index 4f994292..9d3c75d8 100644 --- a/config/config.go +++ b/config/config.go @@ -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 } } diff --git a/config/version b/config/version index 98610aa4..9d3ffadc 100644 --- a/config/version +++ b/config/version @@ -1 +1 @@ -v1.6.2 \ No newline at end of file +v1.6.3 \ No newline at end of file diff --git a/web/service/setting.go b/web/service/setting.go index ccd684a6..dcce50c0 100644 --- a/web/service/setting.go +++ b/web/service/setting.go @@ -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{