setup: show internal and external links on finish

internal generated from host, port and url_base, external is just
jfa_url. Both are shown (if jfa_url is set).
This commit is contained in:
Harvey Tindall
2025-05-15 15:08:32 +01:00
parent eab33d9f6d
commit 16c5420c6f
4 changed files with 46 additions and 11 deletions
+37 -6
View File
@@ -365,6 +365,33 @@ const checkTheme = () => {
settings["ui"]["theme"].onchange = checkTheme;
checkTheme();
const fixFullURL = (v: string): string => {
if (!(v.startsWith("http://")) && !(v.startsWith("https://"))) {
v = "http://" + v;
}
return v;
};
const formatSubpath = (v: string): string => {
if (v == "/") return "";
if (v.charAt(-1) == "/") { v = v.slice(0, -1); }
return v;
}
const constructNewURLs = (): string[] => {
let local = settings["ui"]["host"].value + ":" + settings["ui"]["port"].value;
if (settings["ui"]["url_base"].value != "") {
local += formatSubpath(settings["ui"]["url_base"].value);
}
local = fixFullURL(local);
let remote = settings["ui"]["jfa_url"].value;
if (remote == "") {
return [local];
}
remote = fixFullURL(remote);
return [local, remote];
}
const restartButton = document.getElementById("restart") as HTMLSpanElement;
const serialize = () => {
toggleLoader(restartButton);
@@ -409,12 +436,16 @@ const serialize = () => {
}
restartButton.parentElement.querySelector("span.back").classList.add("unfocused");
restartButton.classList.add("unfocused");
const refresh = document.getElementById("refresh") as HTMLSpanElement;
refresh.classList.remove("unfocused");
refresh.onclick = () => {
let host = window.location.href.split("#")[0].split("?")[0] + settings["ui"]["url_base"].value;
window.location.href = host;
};
const refreshURLs = constructNewURLs();
const refreshButtons = [document.getElementById("refresh-internal") as HTMLAnchorElement, document.getElementById("refresh-external") as HTMLAnchorElement];
["internal", "external"].forEach((urltype, i) => {
const button = refreshButtons[i];
button.classList.remove("unfocused");
button.href = refreshURLs[i];
button.innerHTML = `<span>${urltype.charAt(0).toUpperCase() + urltype.slice(1)}:</span><i class="italic underline">${button.href}</i>`;
// skip external if it isn't set
if (refreshURLs.length == 1) return;
});
}
}, true, (req: XMLHttpRequest) => {
if (req.status == 0) {