mirror of
https://github.com/imgfloat/server.git
synced 2026-02-05 11:49:25 +00:00
@@ -14,11 +14,8 @@ const statCanvasSizeElement = document.getElementById("stat-canvas-size");
|
||||
const statPlaybackRangeElement = document.getElementById("stat-playback-range");
|
||||
const statAudioRangeElement = document.getElementById("stat-audio-range");
|
||||
const statVolumeRangeElement = document.getElementById("stat-volume-range");
|
||||
const sysadminListElement = document.getElementById("sysadmin-list");
|
||||
const sysadminInputElement = document.getElementById("new-sysadmin");
|
||||
const addSysadminButtonElement = document.getElementById("add-sysadmin-button");
|
||||
|
||||
let currentSettings = JSON.parse(serverRenderedSettings);
|
||||
const currentSettings = JSON.parse(serverRenderedSettings);
|
||||
let userSettings = { ...currentSettings };
|
||||
|
||||
function jsonEquals(a, b) {
|
||||
@@ -136,100 +133,6 @@ function submitSettingsForm() {
|
||||
});
|
||||
}
|
||||
|
||||
function renderSystemAdministrators(admins) {
|
||||
sysadminListElement.innerHTML = "";
|
||||
if (!admins || admins.length === 0) {
|
||||
const empty = document.createElement("li");
|
||||
empty.classList.add("stacked-list-item");
|
||||
empty.innerHTML = '<p class="muted">No system administrators found.</p>';
|
||||
sysadminListElement.appendChild(empty);
|
||||
return;
|
||||
}
|
||||
|
||||
admins.forEach((admin) => {
|
||||
const listItem = document.createElement("li");
|
||||
listItem.classList.add("stacked-list-item");
|
||||
|
||||
const text = document.createElement("div");
|
||||
text.innerHTML = `<p class="list-title">${admin}</p><p class="muted">System admin access</p>`;
|
||||
|
||||
const button = document.createElement("button");
|
||||
button.classList.add("button", "secondary");
|
||||
button.type = "button";
|
||||
button.textContent = "Remove";
|
||||
button.addEventListener("click", () => removeSystemAdministrator(admin));
|
||||
|
||||
listItem.appendChild(text);
|
||||
listItem.appendChild(button);
|
||||
sysadminListElement.appendChild(listItem);
|
||||
});
|
||||
}
|
||||
|
||||
function loadSystemAdministrators() {
|
||||
return fetch("/api/system-administrators")
|
||||
.then((r) => {
|
||||
if (!r.ok) {
|
||||
throw new Error("Failed to load system admins");
|
||||
}
|
||||
return r.json();
|
||||
})
|
||||
.then((admins) => {
|
||||
renderSystemAdministrators(admins);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
showToast("Unable to load system admins", "error");
|
||||
});
|
||||
}
|
||||
|
||||
function addSystemAdministrator() {
|
||||
const username = sysadminInputElement.value.trim();
|
||||
if (!username) {
|
||||
showToast("Enter a Twitch username", "warning");
|
||||
return;
|
||||
}
|
||||
fetch("/api/system-administrators", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ twitchUsername: username }),
|
||||
})
|
||||
.then((r) => {
|
||||
if (!r.ok) {
|
||||
throw new Error("Failed to add system admin");
|
||||
}
|
||||
return r.json();
|
||||
})
|
||||
.then((admins) => {
|
||||
sysadminInputElement.value = "";
|
||||
renderSystemAdministrators(admins);
|
||||
showToast("System admin added", "success");
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
showToast("Unable to add system admin", "error");
|
||||
});
|
||||
}
|
||||
|
||||
function removeSystemAdministrator(username) {
|
||||
fetch(`/api/system-administrators/${encodeURIComponent(username)}`, { method: "DELETE" })
|
||||
.then((r) => {
|
||||
if (!r.ok) {
|
||||
return r.text().then((text) => {
|
||||
throw new Error(text || "Failed to remove system admin");
|
||||
});
|
||||
}
|
||||
return r.json();
|
||||
})
|
||||
.then((admins) => {
|
||||
renderSystemAdministrators(admins);
|
||||
showToast("System admin removed", "success");
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
showToast("Unable to remove system admin", "error");
|
||||
});
|
||||
}
|
||||
|
||||
formElement.querySelectorAll("input").forEach((input) => {
|
||||
input.addEventListener("input", () => {
|
||||
loadUserSettingsFromDom();
|
||||
@@ -237,14 +140,6 @@ formElement.querySelectorAll("input").forEach((input) => {
|
||||
});
|
||||
});
|
||||
|
||||
addSysadminButtonElement.addEventListener("click", () => addSystemAdministrator());
|
||||
sysadminInputElement.addEventListener("keydown", (event) => {
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
addSystemAdministrator();
|
||||
}
|
||||
});
|
||||
|
||||
formElement.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
submitSettingsForm();
|
||||
@@ -253,4 +148,3 @@ formElement.addEventListener("submit", (event) => {
|
||||
setFormSettings(currentSettings);
|
||||
updateStatCards(currentSettings);
|
||||
updateSubmitButtonDisabledState();
|
||||
loadSystemAdministrators();
|
||||
|
||||
Reference in New Issue
Block a user