mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-18 22:36:10 +01:00
🎨 Improve the network serve address list https://github.com/siyuan-note/siyuan/issues/14943
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
3e6e5fa3a4
commit
db4b91b757
7 changed files with 47 additions and 60 deletions
|
|
@ -89,25 +89,20 @@ export const about = {
|
|||
${window.siyuan.languages.about2}
|
||||
<div class="b3-label__text">${window.siyuan.languages.about3.replace("${port}", location.port)}</div>
|
||||
${(() => {
|
||||
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(`<code class="fn__code">${ip}</code>`);
|
||||
} else {
|
||||
ipv4Codes.push(`<code class="fn__code">${ip}</code>`);
|
||||
}
|
||||
|
||||
serverAddrs.push(`<code class="fn__code">${serverAddr}</code>`);
|
||||
}
|
||||
return `<div class="b3-label__text${ipv4Codes.length ? "" : " fn__none"}">${ipv4Codes.join(" ")}</div>
|
||||
<div class="b3-label__text${ipv6Codes.length ? "" : " fn__none"}">${ipv6Codes.join(" ")}</div>`;
|
||||
return `<div class="b3-label__text">${serverAddrs.join(" ")}</div>`;
|
||||
})()}
|
||||
<div class="b3-label__text">${window.siyuan.languages.about18}</div>
|
||||
</div>
|
||||
<div class="fn__space"></div>
|
||||
<button data-type="open" data-url="http://${window.siyuan.config.system.networkServe ? window.siyuan.config.localIPs[0] : "127.0.0.1"}:${location.port}" class="b3-button b3-button--outline fn__size200 fn__flex-center">
|
||||
<button data-type="open" data-url="${window.siyuan.config.system.networkServe ? window.siyuan.config.serverAddrs[0] : "http://127.0.0.1:"+ location.port}" class="b3-button b3-button--outline fn__size200 fn__flex-center">
|
||||
<svg><use xlink:href="#iconLink"></use></svg>${window.siyuan.languages.about4}
|
||||
</button>
|
||||
</div>
|
||||
|
|
@ -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) => {
|
||||
|
|
|
|||
|
|
@ -229,17 +229,13 @@ ${window.siyuan.languages.publishServiceAuthAccounts}
|
|||
if (port === 0) {
|
||||
publishAddresses.innerText = window.siyuan.languages.publishServiceNotStarted;
|
||||
} else {
|
||||
publishAddresses.innerHTML = `<ul class="b3-list fn__flex-1" style="padding: 2px 0;">${
|
||||
window.siyuan.config.localIPs
|
||||
.filter(ip => !(ip.startsWith("[") && ip.endsWith("]")))
|
||||
.map(ip => `<li><code class="fn__code">${ip}:${port}</code></li>`)
|
||||
.join("")
|
||||
}${
|
||||
window.siyuan.config.localIPs
|
||||
.filter(ip => (ip.startsWith("[") && ip.endsWith("]")))
|
||||
.map(ip => `<li><code class="fn__code">${ip}:${port}</code></li>`)
|
||||
.join("")
|
||||
}</ul>`;
|
||||
publishAddresses.innerHTML = `<div class="b3-label__text">${
|
||||
window.siyuan.config.serverAddrs
|
||||
.map(serverAddr => {
|
||||
serverAddr = serverAddr.substring(0, serverAddr.lastIndexOf(":"));
|
||||
return `<code class="fn__code">${serverAddr}:${port}</code>`
|
||||
}).join(" ")
|
||||
}</div>`;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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 = () => {
|
|||
<div class="b3-label">
|
||||
${window.siyuan.languages.about2}
|
||||
<div class="fn__hr"></div>
|
||||
<a target="_blank" href="http://${window.siyuan.config.system.networkServe ? window.siyuan.config.localIPs[0] : "127.0.0.1"}:${location.port}" class="b3-button b3-button--outline fn__block">
|
||||
<a target="_blank" href="${window.siyuan.config.system.networkServe ? window.siyuan.config.serverAddrs[0] : "http://127.0.0.1:" + location.port}" class="b3-button b3-button--outline fn__block">
|
||||
<svg><use xlink:href="#iconLink"></use></svg>${window.siyuan.languages.about4}
|
||||
</a>
|
||||
<div class="b3-label__text">${window.siyuan.languages.about3.replace("${port}", location.port)}</div>
|
||||
<div class="fn__hr"></div>
|
||||
${(() => {
|
||||
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(`<code class="fn__code">${ip}</code>`);
|
||||
} else {
|
||||
ipv4Codes.push(`<code class="fn__code">${ip}</code>`);
|
||||
}
|
||||
serverAddrs.push(`<code class="fn__code">${serverAddr}</code>`);
|
||||
}
|
||||
return `<div class="b3-label__text${ipv4Codes.length ? "" : " fn__none"}">${ipv4Codes.join(" ")}</div>
|
||||
<div class="b3-label__text${ipv6Codes.length ? "" : " fn__none"}">${ipv6Codes.join(" ")}</div>`;
|
||||
return `<div class="b3-label__text">${serverAddrs.join(" ")}</div>`;
|
||||
})()}
|
||||
<div class="fn__hr"></div>
|
||||
<div class="b3-label__text">${window.siyuan.languages.about18}</div>
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
4
app/src/types/config.d.ts
vendored
4
app/src/types/config.d.ts
vendored
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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{}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue