From db4b91b7578cf8cc4ce1bce6f7c3f6f4f2421769 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 17 Jan 2026 11:41:14 +0800 Subject: [PATCH] :art: Improve the network serve address list https://github.com/siyuan-note/siyuan/issues/14943 Signed-off-by: Daniel <845765@qq.com> --- app/src/config/about.ts | 28 +++++++++++++--------------- app/src/config/publish.ts | 18 +++++++----------- app/src/mobile/settings/about.ts | 32 ++++++++++++-------------------- app/src/types/config.d.ts | 4 ++-- kernel/model/conf.go | 8 +++----- kernel/server/serve.go | 3 +++ kernel/util/path.go | 14 +++++++------- 7 files changed, 47 insertions(+), 60 deletions(-) diff --git a/app/src/config/about.ts b/app/src/config/about.ts index c19526eb9..ca3ff2058 100644 --- a/app/src/config/about.ts +++ b/app/src/config/about.ts @@ -89,25 +89,20 @@ export const about = { ${window.siyuan.languages.about2}
${window.siyuan.languages.about3.replace("${port}", location.port)}
${(() => { - const ipv4Codes: string[] = []; - const ipv6Codes: string[] = []; - for (const ip of window.siyuan.config.localIPs) { - if (!ip.trim()) { + const serverAddrs: string[] = []; + for (const serverAddr of window.siyuan.config.serverAddrs) { + if (!serverAddr.trim()) { break; } - if (ip.startsWith("[") && ip.endsWith("]")) { - ipv6Codes.push(`${ip}`); - } else { - ipv4Codes.push(`${ip}`); - } + + serverAddrs.push(`${serverAddr}`); } - return `
${ipv4Codes.join(" ")}
-
${ipv6Codes.join(" ")}
`; + return `
${serverAddrs.join(" ")}
`; })()}
${window.siyuan.languages.about18}
- @@ -275,13 +270,16 @@ ${checkUpdateHTML} }); }); about.element.querySelector("#vacuumDataIndex").addEventListener("click", () => { - fetchPost("/api/system/vacuumDataIndex", {}, () => {}); + fetchPost("/api/system/vacuumDataIndex", {}, () => { + }); }); about.element.querySelector("#rebuildDataIndex").addEventListener("click", () => { - fetchPost("/api/system/rebuildDataIndex", {}, () => {}); + fetchPost("/api/system/rebuildDataIndex", {}, () => { + }); }); about.element.querySelector("#clearTempFiles").addEventListener("click", () => { - fetchPost("/api/system/clearTempFiles", {}, () => {}); + fetchPost("/api/system/clearTempFiles", {}, () => { + }); }); about.element.querySelector("#exportLog").addEventListener("click", () => { fetchPost("/api/system/exportLog", {}, (response) => { diff --git a/app/src/config/publish.ts b/app/src/config/publish.ts index 637a75143..88c902d81 100644 --- a/app/src/config/publish.ts +++ b/app/src/config/publish.ts @@ -229,17 +229,13 @@ ${window.siyuan.languages.publishServiceAuthAccounts} if (port === 0) { publishAddresses.innerText = window.siyuan.languages.publishServiceNotStarted; } else { - publishAddresses.innerHTML = ``; + publishAddresses.innerHTML = `
${ + window.siyuan.config.serverAddrs + .map(serverAddr => { + serverAddr = serverAddr.substring(0, serverAddr.lastIndexOf(":")); + return `${serverAddr}:${port}` + }).join(" ") + }
`; } }, }; diff --git a/app/src/mobile/settings/about.ts b/app/src/mobile/settings/about.ts index 68eaa4971..e5f86e0a3 100644 --- a/app/src/mobile/settings/about.ts +++ b/app/src/mobile/settings/about.ts @@ -12,11 +12,6 @@ import {setKey} from "../../sync/syncGuide"; import {isBrowser} from "../../util/functions"; export const initAbout = () => { - if (!window.siyuan.config.localIPs || window.siyuan.config.localIPs.length === 0 || - (window.siyuan.config.localIPs.length === 1 && window.siyuan.config.localIPs[0] === "")) { - window.siyuan.config.localIPs = ["127.0.0.1"]; - } - openModel({ title: window.siyuan.languages.about, icon: "iconInfo", @@ -32,26 +27,20 @@ export const initAbout = () => {
${window.siyuan.languages.about2}
- + ${window.siyuan.languages.about4}
${window.siyuan.languages.about3.replace("${port}", location.port)}
${(() => { - const ipv4Codes: string[] = []; - const ipv6Codes: string[] = []; - for (const ip of window.siyuan.config.localIPs) { - if (!ip.trim()) { + const serverAddrs: string[] = []; + for (const serverAddr of window.siyuan.config.serverAddrs) { + if (!serverAddr.trim()) { break; } - if (ip.startsWith("[") && ip.endsWith("]")) { - ipv6Codes.push(`${ip}`); - } else { - ipv4Codes.push(`${ip}`); - } + serverAddrs.push(`${serverAddr}`); } - return `
${ipv4Codes.join(" ")}
-
${ipv6Codes.join(" ")}
`; + return `
${serverAddrs.join(" ")}
`; })()}
${window.siyuan.languages.about18}
@@ -320,17 +309,20 @@ export const initAbout = () => { event.stopPropagation(); break; } else if (target.id === "vacuumDataIndex") { - fetchPost("/api/system/vacuumDataIndex", {}, () => {}); + fetchPost("/api/system/vacuumDataIndex", {}, () => { + }); event.preventDefault(); event.stopPropagation(); break; } else if (target.id === "rebuildDataIndex") { - fetchPost("/api/system/rebuildDataIndex", {}, () => {}); + fetchPost("/api/system/rebuildDataIndex", {}, () => { + }); event.preventDefault(); event.stopPropagation(); break; } else if (target.id === "clearTempFiles") { - fetchPost("/api/system/clearTempFiles", {}, () => {}); + fetchPost("/api/system/clearTempFiles", {}, () => { + }); event.preventDefault(); event.stopPropagation(); break; diff --git a/app/src/types/config.d.ts b/app/src/types/config.d.ts index 35c44e283..a9c42e90f 100644 --- a/app/src/types/config.d.ts +++ b/app/src/types/config.d.ts @@ -52,9 +52,9 @@ declare namespace Config { */ langs: ILang[]; /** - * A list of the IP addresses of the devices on which the kernel resides + * A list of the kernel server addresses */ - localIPs: string[]; + serverAddrs: string[]; /** * Log level */ diff --git a/kernel/model/conf.go b/kernel/model/conf.go index 571abcb5d..bf76a5367 100644 --- a/kernel/model/conf.go +++ b/kernel/model/conf.go @@ -64,7 +64,7 @@ type AppConf struct { User *conf.User `json:"-"` // 社区用户内存结构,不持久化。不要直接使用,使用 GetUser() 和 SetUser() 方法 Account *conf.Account `json:"account"` // 帐号配置 ReadOnly bool `json:"readonly"` // 是否是以只读模式运行 - LocalIPs []string `json:"localIPs"` // 本地 IP 列表 + ServerAddrs []string `json:"serverAddrs"` // 本地服务器地址列表 AccessAuthCode string `json:"accessAuthCode"` // 访问授权码 System *conf.System `json:"system"` // 系统配置 Keymap *conf.Keymap `json:"keymap"` // 快捷键配置 @@ -582,8 +582,6 @@ func InitConf() { Conf.AccessAuthCode = strings.TrimSpace(Conf.AccessAuthCode) Conf.AccessAuthCode = util.RemoveInvalid(Conf.AccessAuthCode) - Conf.LocalIPs = util.GetLocalIPs() - if 1 == Conf.DataIndexState { // 上次未正常完成数据索引 go func() { @@ -1045,13 +1043,13 @@ func GetMaskedConf() (ret *AppConf, err error) { return } -// REF: https://github.com/siyuan-note/siyuan/issues/11364 // HideConfSecret 隐藏设置中的秘密信息 +// REF: https://github.com/siyuan-note/siyuan/issues/11364 func HideConfSecret(c *AppConf) { c.AI = &conf.AI{} c.Api = &conf.API{} c.Flashcard = &conf.Flashcard{} - c.LocalIPs = []string{} + c.ServerAddrs = []string{} c.Publish = &conf.Publish{} c.Repo = &conf.Repo{} c.Sync = &conf.Sync{} diff --git a/kernel/server/serve.go b/kernel/server/serve.go index 49530e2ad..40fb560af 100644 --- a/kernel/server/serve.go +++ b/kernel/server/serve.go @@ -198,6 +198,9 @@ func Serve(fastMode bool, cookieKey string) { } util.ServerPort = port + model.Conf.ServerAddrs = util.GetServerAddrs() + model.Conf.Save() + util.ServerURL, err = url.Parse("http://127.0.0.1:" + port) if err != nil { logging.LogErrorf("parse server url failed: %s", err) diff --git a/kernel/util/path.go b/kernel/util/path.go index ed89fed8d..e6587fcea 100644 --- a/kernel/util/path.go +++ b/kernel/util/path.go @@ -64,18 +64,18 @@ func ShortPathForBootingDisplay(p string) string { var LocalIPs []string -func GetLocalIPs() (ret []string) { - if ContainerAndroid == Container || ContainerHarmony == Container { +func GetServerAddrs() (ret []string) { + if ContainerAndroid != Container && ContainerHarmony != Container { // Android 上用不了 net.InterfaceAddrs() https://github.com/golang/go/issues/40569,所以前面使用启动内核传入的参数 localIPs - LocalIPs = append(LocalIPs, LocalHost) - LocalIPs = gulu.Str.RemoveDuplicatedElem(LocalIPs) - return LocalIPs + ret = GetPrivateIPv4s() } - ret = []string{} - ret = append(ret, GetPrivateIPv4s()...) ret = append(ret, LocalHost) ret = gulu.Str.RemoveDuplicatedElem(ret) + + for i, _ := range ret { + ret[i] = "http://" + ret[i] + ":" + ServerPort + } return }