This commit is contained in:
+29
-1
@@ -311,7 +311,7 @@ export function renderConfig() {
|
||||
);
|
||||
$("mainSavebar").classList.toggle(
|
||||
"hidden",
|
||||
["bulk_sync", "plugins"].includes(b.dataset.configSection),
|
||||
["bulk_sync", "plugins", "access"].includes(b.dataset.configSection),
|
||||
);
|
||||
if (b.dataset.configSection === "services") loadServices();
|
||||
if (b.dataset.configSection === "processes") loadProcesses();
|
||||
@@ -348,6 +348,7 @@ export function renderConfig() {
|
||||
bindBulkSync();
|
||||
updateConditional();
|
||||
addStorageSettings();
|
||||
installAccessSettings();
|
||||
}
|
||||
export function markChanged() {
|
||||
let n = 0;
|
||||
@@ -365,3 +366,30 @@ export function markChanged() {
|
||||
: tr("尚未修改");
|
||||
$("saveState").className = n ? "" : "muted";
|
||||
}
|
||||
|
||||
function installAccessSettings() {
|
||||
const host = appState.fleetHosts.find(h => h.id === appState.currentConfigHost);
|
||||
if (!host) return;
|
||||
$("configMenu").insertAdjacentHTML("beforeend", `<button data-config-section="access">${pluginText("访问地址", "Access URL")}</button>`);
|
||||
$("configRows").insertAdjacentHTML("beforeend", `<section class="config-page" data-config-page="access"><h2>${pluginText("访问地址", "Access URL")}</h2><p class="muted">${pluginText("设置 Gateway 管理页面地址,首页显示链接按钮;留空隐藏入口。", "Set the Gateway management URL to show a link on the overview. Leave blank to hide it.")}</p><div class="field"><label>${pluginText("访问地址", "Access URL")}<input id="gatewayAccessUrl" type="url" value="${esc(host.connection?.management_url || "")}" placeholder="https://gateway.example.com"></label></div><div class="action-row"><button id="saveGatewayAccess">${pluginText("保存访问地址", "Save access URL")}</button><span id="gatewayAccessMessage" role="status"></span></div></section>`);
|
||||
$("saveGatewayAccess").onclick = async () => {
|
||||
const button = $("saveGatewayAccess"), message = $("gatewayAccessMessage");
|
||||
const value = $("gatewayAccessUrl").value.trim();
|
||||
if (value) {
|
||||
try {
|
||||
const url = new URL(value);
|
||||
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.pathname !== "/" || url.search || url.hash) throw Error();
|
||||
} catch {
|
||||
message.textContent = pluginText("请使用不含路径或账号密码的 HTTP(S) 根地址", "Use an HTTP(S) origin without paths or credentials");
|
||||
message.className = "error"; return;
|
||||
}
|
||||
}
|
||||
button.disabled = true;
|
||||
try {
|
||||
const result = await get("/api/v1/hosts", {method: "PUT", headers: {"Content-Type": "application/json"}, body: JSON.stringify({operation: "save", id: host.id, adapter_id: host.adapter_id, connection: {management_url: value}})});
|
||||
appState.fleetHosts = result.hosts;
|
||||
message.textContent = pluginText("已保存", "Saved"); message.className = "success";
|
||||
} catch (error) { message.textContent = error.message; message.className = "error"; }
|
||||
finally { button.disabled = false; }
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user