fix/optimize wtv-admin

This commit is contained in:
zefie
2025-08-12 18:28:56 -04:00
parent b9d64de79e
commit d5c04688e9
14 changed files with 159 additions and 148 deletions

View File

@@ -1,23 +1,23 @@
var minisrv_service_file = true;
const minisrv_service_file = true;
var WTVAdmin = require(classPath + "/WTVAdmin.js");
var wtva = new WTVAdmin(minisrv_config, session_data, service_name);
var auth = wtva.isAuthorized();
const WTVAdmin = require(classPath + "/WTVAdmin.js");
const wtva = new WTVAdmin(minisrv_config, session_data, service_name);
const auth = wtva.isAuthorized();
if (auth === true) {
var password = null;
let password = null;
if (request_headers.Authorization) {
var authheader = request_headers.Authorization.split(' ');
const authheader = request_headers.Authorization.split(' ');
if (authheader[0] == "Basic") {
password = Buffer.from(authheader[1], 'base64').toString();
if (password) password = password.split(':')[1];
}
}
if (wtva.checkPassword(password)) {
var user_config = wtvshared.getUserConfig();
const user_config = wtvshared.getUserConfig();
Object.keys(request_headers.query).forEach((k) => {
if (k === "autosubmit") return;
var v = request_headers.query[k];
let v = request_headers.query[k];
// enable_multi_query may send ["false", "on"] for checkboxes due to webtvism
if (util.isArray(v)) v = v[(v.length - 1)];
@@ -30,20 +30,20 @@ if (auth === true) {
if (k.indexOf("-") > 0) {
// handle sub-config items
var s = k.split("-");
const s = k.split("-");
if (!user_config.config[s[0]]) user_config.config[s[0]] = {}
user_config.config[s[0]][s[1]] = v;
} else {
user_config.config[k] = v;
}
});
var res = wtvshared.writeToUserConfig(user_config);
const res = wtvshared.writeToUserConfig(user_config);
if (res) {
console.log(" * Configuration updated from wtv-admin, reloading")
reloadConfig();
headers = "200 OK\nwtv-expire-all: wtv-admin:/operatortweaks\nContent-Type: text/html";
} else {
err = wtvshared.doErrorPage(400, "Error writing userconfig");
const err = wtvshared.doErrorPage(400, "Error writing userconfig");
headers = err[0];
data = err[1];
}
@@ -51,7 +51,7 @@ if (auth === true) {
}
if (!headers) {
err = wtvshared.doErrorPage();
const err = wtvshared.doErrorPage();
headers = err[0];
data = err[1];
}