fix/optimize wtv-news, wtv-proxy, wtv-register, wtv-search, wtv-setup, wtv-star

This commit is contained in:
zefie
2025-08-12 19:19:23 -04:00
parent d5f41837c0
commit 74ec365ae1
20 changed files with 141 additions and 133 deletions

View File

@@ -1,18 +1,17 @@
var minisrv_service_file = true;
const minisrv_service_file = true;
request_is_async = true;
var request_is_async = true;
var errpage = null;
var group = request_headers.query.group;
var article = request_headers.query.article;
var attachment_id = parseInt(request_headers.query.attachment_id);
if ((!attachment_id && attachment_id != 0) || !group || !article) {
let errpage = null;
const group = request_headers.query.group;
const attachment_id = parseInt(request_headers.query.attachment_id);
if ((!attachment_id && attachment_id != 0) || !group || !request_headers.query.article) {
errpage = wtvshared.doErrorPage(400, "Attachment ID required.");
sendToClient(socket, errpage[0], errpage[1]);
} else {
const wtvnews = new WTVNews(minisrv_config, service_name);
var service_config = minisrv_config.services[service_name];
const service_config = minisrv_config.services[service_name];
if (service_config.local_nntp_port && wtvnewsserver) {
var tls_options = {
const tls_options = {
ca: this.wtvshared.getServiceDep('wtv-news/localserver_ca.pem'),
key: this.wtvshared.getServiceDep('wtv-news/localserver_key.pem'),
cert: this.wtvshared.getServiceDep('wtv-news/localserver_cert.pem'),
@@ -28,17 +27,17 @@ if ((!attachment_id && attachment_id != 0) || !group || !article) {
else
wtvnews.initializeUsenet(service_config.upstream_address, service_config.upstream_port, service_config.upstream_tls || null);
}
var article = parseInt(article);
const article = parseInt(request_headers.query.article);
wtvnews.connectUsenet().then(() => {
wtvnews.selectGroup(group).then((response) => {
wtvnews.getArticle(article).then((response) => {
wtvnews.quitUsenet();
if (response.code == 220) {
var message_data = wtvnews.parseAttachments(response);
const message_data = wtvnews.parseAttachments(response);
if (message_data.attachments) {
if (attachment_id < message_data.attachments.length) {
var attachment = message_data.attachments[attachment_id];
var encoding = attachment.content_encoding.toLowerCase()
const attachment = message_data.attachments[attachment_id];
const encoding = attachment.content_encoding.toLowerCase()
if (encoding == 'base64') {
data = Buffer.from(attachment.data, encoding);
headers = "200 OK\n"

View File

@@ -1,4 +1,4 @@
var minisrv_service_file = true;
const minisrv_service_file = true;
// max of 6, any more will be ignored
@@ -108,8 +108,8 @@ Featured discussions
<td>
<td WIDTH=198 HEIGHT=200 VALIGN=top ALIGN=left>`;
var featuredGroups = minisrv_config.services[service_name].featuredGroups;
var limit = 6;
const featuredGroups = minisrv_config.services[service_name].featuredGroups;
const limit = 6;
while (featuredGroups.length > limit) featuredGroups.pop(); // remove anything passing our limit
function printGroup(group) {

View File

@@ -1,9 +1,9 @@
var minisrv_service_file = true;
const minisrv_service_file = true;
const wtvnews = new WTVNews(minisrv_config, service_name);
var service_config = minisrv_config.services[service_name];
const service_config = minisrv_config.services[service_name];
if (service_config.local_nntp_port && wtvnewsserver) {
var tls_options = {
const tls_options = {
ca: this.wtvshared.getServiceDep('wtv-news/localserver_ca.pem'),
key: this.wtvshared.getServiceDep('wtv-news/localserver_key.pem'),
cert: this.wtvshared.getServiceDep('wtv-news/localserver_cert.pem'),
@@ -22,7 +22,7 @@ if (service_config.local_nntp_port && wtvnewsserver) {
async function throwError(e) {
console.log(e);
var errpage = wtvshared.doErrorPage(400, null, e.toString());
const errpage = wtvshared.doErrorPage(400, null, e.toString());
sendToClient(socket, errpage[0], errpage[1]);
}
@@ -34,22 +34,22 @@ function isToday (chkdate) {
}
async function WebTVListGroup(group) {
var page_limit_default = 100;
const page_limit_default = 100;
wtvnews.connectUsenet().then(() => {
wtvnews.selectGroup(group).then((response) => {
var limit_per_page = (request_headers.query.limit) ? parseInt(request_headers.query.limit) : page_limit_default;
var page = (request_headers.query.chunk) ? parseInt(request_headers.query.chunk) : 0;
let limit_per_page = (request_headers.query.limit) ? parseInt(request_headers.query.limit) : page_limit_default;
const page = (request_headers.query.chunk) ? parseInt(request_headers.query.chunk) : 0;
console.log(response);
var page_start = (limit_per_page * page) + 1;
var page_end = (page + 1) * limit_per_page;
let page_start = (limit_per_page * page) + 1;
let page_end = (page + 1) * limit_per_page;
if (page_end > response.group.high) {
page_end = response.group.high;
limit_per_page = (page_end - (limit_per_page / (page + 1))) + limit_per_page;
}
wtvnews.listGroup(group, page, limit_per_page).then((response) => {
if (response.code == 211) {
NGCount = response.group.number;
NGArticles = response.group.articleNumbers;
const NGCount = response.group.number;
const NGArticles = response.group.articleNumbers;
page_start = (limit_per_page * page) + 1;
page_end = (page + 1) * limit_per_page;
wtvnews.getHeaderObj(NGArticles).then((messages) => {
@@ -251,10 +251,10 @@ ${page_start}-${page_end}
</TABLE>`
if (NGCount > 0) {
Object.keys(messages).forEach(function (k) {
var message = messages[k].article;
var has_relation = (messages[k].relation !== null) ? true : false;
var date_obj = new Date(Date.parse(message.headers.DATE));
var date = (isToday(date_obj)) ? strftime("%I:%M %p", date_obj) : strftime("%b %d '%y", date_obj)
const message = messages[k].article;
const has_relation = (messages[k].relation !== null) ? true : false;
const date_obj = new Date(Date.parse(message.headers.DATE));
const date = (isToday(date_obj)) ? strftime("%I:%M %p", date_obj) : strftime("%b %d '%y", date_obj)
data += `
<table cellspacing=0 cellpadding=0>
<tr>
@@ -317,21 +317,21 @@ ${(message.headers.FROM.indexOf(' ') > 0) ? message.headers.FROM.split(' ')[0] :
}
async function WebTVShowMessage(group, article) {
var article = parseInt(article);
const theArticle = parseInt(article);
wtvnews.connectUsenet().then(() => {
wtvnews.selectGroup(group).then((response) => {
wtvnews.getArticle(article).then((response) => {
wtvnews.getArticle(theArticle).then((response) => {
wtvnews.quitUsenet();
headers = `200 OK
Content-type: text/html
wtv-expire-all: wtv-news:/news?group=${group}&article=`;
var signature = null;
var message_colors = session_data.mailstore.defaultColors;
var display_signature = true; // todo make a toggle
var message = wtvnews.parseAttachments(response);
var message_body = message.text;
var attachments = null;
var signature_index = null;
let signature = null;
let message_colors = session_data.mailstore.defaultColors;
const display_signature = true; // todo make a toggle
const message = wtvnews.parseAttachments(response);
const message_body = message.text;
let attachments = null;
let signature_index = null;
wtvnews.debug(message);
if (message.attachments) attachments = message.attachments;
if (attachments) {
@@ -348,8 +348,8 @@ wtv-expire-all: wtv-news:/news?group=${group}&article=`;
}
if (message_body.indexOf("<body")) {
var default_colors = session_data.mailstore.defaultColors;
var message_colors = session_data.mailstore.getSignatureColors(message_body);
const default_colors = session_data.mailstore.defaultColors;
message_colors = session_data.mailstore.getSignatureColors(message_body);
if ((message_colors == default_colors) && signature) message_colors = null;
}
if (!message_colors && signature) message_colors = session_data.mailstore.getSignatureColors(signature);
@@ -612,10 +612,10 @@ From:
<tr>
<td>
`;
var allow_html = false;
var body_data = '';
var attachment_data = '';
var signature_data = '';
let allow_html = false;
let body_data = '';
let attachment_data = '';
let signature_data = '';
if (message_body) {
if (message_body.indexOf("<html>") >= 0) {
@@ -635,8 +635,8 @@ From:
delete attachments[0];
}
}
var supported_images = /image\/(jpe?g|png|gif|x-wtv-bitmap)/;
var supported_audio = /audio\/(mp[eg|2|3]|midi?|wav|x-wav|mod|x-mod)/;
const supported_images = /image\/(jpe?g|png|gif|x-wtv-bitmap)/;
const supported_audio = /audio\/(mp[eg|2|3]|midi?|wav|x-wav|mod|x-mod)/;
attachments.forEach((v, k) => {
if (v.content_type) {
if (v.content_type.match(supported_images))
@@ -666,7 +666,7 @@ From:
}).catch((e) => {
// no such article
var post_unavailable_file = this.wtvshared.getServiceDep('wtv-news/post-unavailable.html');
const post_unavailable_file = this.wtvshared.getServiceDep('wtv-news/post-unavailable.html');
console.log(e);
if (fs.existsSync(post_unavailable_file)) {
headers = "200 OK\nContent-type: text/html";
@@ -865,11 +865,11 @@ Do you want to look for something else?<br>
if (!wtvnews.client) {
var errpage = doErrorPage();
const errpage = wtvshared.doErrorPage();
headers = errpage[0];
data = errpage[1];
} else {
var request_is_async = true;
request_is_async = true;
if (request_headers.query.search) {
WebTVSearchGroups(request_headers.query.search)
} else if (request_headers.query.group) {

View File

@@ -1,18 +1,20 @@
const minisrv_service_file = true;
headers = `200 OK
Connection: Keep-Alive
wtv-encrypted: true
Expires: Wed, 09 Oct 1991 22:00:00 GMT
Content-Type: text/plain`
var messenger_email = session_data.getSessionData("messenger_email");;
var messenger_password = session_data.getSessionData("messenger_password");
const messenger_email = session_data.getSessionData("messenger_email");;
const messenger_password = session_data.getSessionData("messenger_password");
if (messenger_email && messenger_password) {
var email = messenger_email + "%40" + session_data.getSessionData("messenger_domain");
var password = session_data.decryptPassword(messenger_password);
var challenge = request_headers.request.split('?')[1];
const email = messenger_email + "%40" + session_data.getSessionData("messenger_domain");
const password = session_data.decryptPassword(messenger_password);
const challenge = request_headers.request.split('?')[1];
if (request_headers.request.split('?')[1].substring(0, 3) != "ct=") {
if (request_headers.request.split('?')[1].slice(0, 3) != "ct=") {
console.log(" *** Logging into Messenger via MSNP3")
data = crypto.createHash('md5').update(request_headers.request.split('?')[1] + password).digest("hex");
} else {
@@ -25,9 +27,9 @@ if (messenger_email && messenger_password) {
});
response.on('end', () => {
var passporturls = response.headers['passporturls'].split("DALogin=")[1];
const passporturls = response.headers['passporturls'].split("DALogin=")[1];
request.end();
var options = {
const options = {
method: 'GET',
headers: { "Authorization": "Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=" + email + ",pwd=" + encodeURIComponent(password) + "," + challenge }
}
@@ -38,7 +40,7 @@ if (messenger_email && messenger_password) {
});
response.on('end', () => {
var pp = response.headers['authentication-info'];
let pp = response.headers['authentication-info'];
pp = pp.split("from-PP='")[1];
pp = pp.split("'")[0];
data = pp;

View File

@@ -1,13 +1,13 @@
minisrv_service_file = true;
const minisrv_service_file = true;
request_is_async = true;
const proxyUrl = minisrv_config.services[service_name].wrp_url;
let proxyUrl = minisrv_config.services[service_name].wrp_url;
if (!proxyUrl.endsWith('/')) {
proxyUrl += '/';
}
// Remove 'service_name:/' from the start of request_url
let forwardPath = request_headers.request_url
const forwardPath = request_headers.request_url
.replace(new RegExp(`^${service_name}:\\/`), '');
// Build the full URL to forward to
@@ -24,12 +24,12 @@ lib.get(targetUrl, (res) => {
headers += `Content-Type: ${res.headers['content-type']}\n`;
}
let data = [];
const data = [];
res.on('data', chunk => data.push(chunk));
res.on('end', () => {
sendToClient(socket, headers, Buffer.concat(data));
});
}).on('error', err => {
var errpage = WTVShared.doErrorPage(400, 'Error fetching image', err.message);
const errpage = wtvshared.doErrorPage(400, 'Error fetching image', err.message);
sendToClient(socket, errpage[0], errpage[1]);
});

View File

@@ -1,23 +1,23 @@
minisrv_service_file = true;
const minisrv_service_file = true;
request_is_async = true;
const proxyUrl = minisrv_config.services[service_name].wrp_url;
let proxyUrl = minisrv_config.services[service_name].wrp_url;
if (!proxyUrl.endsWith('/')) {
proxyUrl += '/';
}
// Remove 'service_name:/' from the start of request_url
let forwardPath = request_headers.request_url
const forwardPath = request_headers.request_url
.replace(new RegExp(`^${service_name}:\\/`), '');
// Build the full URL to forward to
var targetUrl = proxyUrl + forwardPath;
let targetUrl = proxyUrl + forwardPath;
// Forward the request using http(s) module
const urlObj = new URL(targetUrl);
const lib = urlObj.protocol === 'https:' ? https : http;
coords = request_headers.request_url.split("?")[1];
let coords = request_headers.request_url.split("?")[1];
if (!coords) {
coords = '0,0'
}
@@ -46,20 +46,20 @@ lib.get(targetUrl, (res) => {
img: imgSrcMatch[1]
});
}
var proxy_id = links[0].href.replace(/\/map\//, '');
let proxy_id = links[0].href.replace(/\/map\//, '');
proxy_id = proxy_id.replace(/\.map/, '');
var imgExt = links[0].img.split('.').pop().split('?')[0].toLowerCase();
const imgExt = links[0].img.split('.').pop().split('?')[0].toLowerCase();
const urlInputMatch = data.match(/<input[^>]+type=["']text["'][^>]+name=["']url["'][^>]+value=["']([^"']+)["']/i);
let pageUrl = '';
if (urlInputMatch) {
pageUrl = urlInputMatch[1];
}
var redirectUrl = `${service_name}:/proxy?id=${proxy_id}&t=${imgExt}&url=${encodeURIComponent(pageUrl)}`;
const redirectUrl = `${service_name}:/proxy?id=${proxy_id}&t=${imgExt}&url=${encodeURIComponent(pageUrl)}`;
sendToClient(socket, {'Status': 302, 'Location': redirectUrl}, '');
} else {
var idx = data.indexOf('<BR>');
data = data.substring(0, idx);
var redirectUrl = `${service_name}:/proxy?err=${encodeURIComponent(data)}`;
const idx = data.indexOf('<BR>');
data = data.slice(0, idx);
const redirectUrl = `${service_name}:/proxy?err=${encodeURIComponent(data)}`;
sendToClient(socket, {'Status': 302, 'Location': redirectUrl}, '');
}
});

View File

@@ -1,7 +1,7 @@
minisrv_service_file = true;
const minisrv_service_file = true;
request_is_async = true;
proxyUrl = minisrv_config.services[service_name].wrp_url;
let proxyUrl = minisrv_config.services[service_name].wrp_url;
if (!proxyUrl) {
headers = `200 OK
Content-Type: text/html
@@ -104,7 +104,7 @@ Location: ${service_name}:/proxy`
} else {
function fetch(options, post_data) {
return new Promise((resolve, reject) => {
req = lib.request(options, (res) => {
const req = lib.request(options, (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => resolve({ text: () => Promise.resolve(data) }));
@@ -146,8 +146,8 @@ function process(content) {
// You can now use the `links` array as needed
} else {
var idx = content.indexOf('<BR>');
content = content.substring(0, idx);
const idx = content.indexOf('<BR>');
content = content.slice(0, idx);
finishPage(content);
}
}

View File

@@ -1,4 +1,4 @@
var minisrv_service_file = true;
const minisrv_service_file = true;
session_data.data_store.wtvsec_login.PrepareTicket();
headers = `300 Moved

View File

@@ -1,13 +1,13 @@
var minisrv_service_file = true;
const minisrv_service_file = true;
if (!request_headers.query.registering) {
var errpage = wtvshared.doErrorPage(400);
const errpage = wtvshared.doErrorPage(400);
headers = errpage[0];
data = errpage[1];
} else {
const WTVRegister = require(classPath + "/WTVRegister.js")
var wtvr = new WTVRegister(minisrv_config, SessionStore);
var errpage = null;
const wtvr = new WTVRegister(minisrv_config, SessionStore);
let errpage = null;
if (!request_headers.query.registering) errpage = wtvshared.doErrorPage(400);
else if (!request_headers.query.subscriber_name) errpage = wtvshared.doErrorPage(400, "Please enter your name. This can be your real name, or your well-known online alias.");
else if (!request_headers.query.subscriber_username) errpage = wtvshared.doErrorPage(400, "Please enter a username.");
@@ -27,9 +27,9 @@ if (!request_headers.query.registering) {
headers = `200 OK
wtv-noback-all: wtv-register:
Content-Type: text/html`;
var title = "Account Review";
var isOldBuild = wtvshared.isOldBuild(session_data);
var main_data = '';
const title = "Account Review";
const isOldBuild = wtvshared.isOldBuild(session_data);
let main_data = '';
if (!isOldBuild) main_data += `<table cellspacing=0 cellpadding=0 border=0 width=560 bgcolor=#171726>
<tr><td>`;
@@ -71,7 +71,7 @@ correct an item, press <b>Back</b>.<p>`;
<td abswidth=20>
</tr>`;
if (isOldBuild) main_data += '</table>';
var form_data = `
const form_data = `
<input value="Edit" name="Change" type=submit borderimage="file://ROM/Borders/ButtonBorder2.bif" text="#dddddd">
<input selected Value="Sign Up" name="Sign Up" width="110" type=submit Value=Continue name="Continue" borderimage="file://ROM/Borders/ButtonBorder2.bif" text="#dddddd">
</shadow>

View File

@@ -1,15 +1,15 @@
var minisrv_service_file = true;
const minisrv_service_file = true;
if (!request_headers.query.registering) {
var errpage = wtvshared.doErrorPage(400);
const errpage = wtvshared.doErrorPage(400);
headers = errpage[0];
data = errpage[1];
} else {
const WTVRegister = require(classPath + "/WTVRegister.js")
var wtvr = new WTVRegister(minisrv_config);
const wtvr = new WTVRegister(minisrv_config);
headers = `200 OK
Content-Type: text/html`;
var main_data = `<form action="ValidateAccountInfo"
const main_data = `<form action="ValidateAccountInfo"
ENCTYPE="x-www-form-encoded" METHOD="POST">
<input type=hidden name=registering value="true">
Please set up your account:<br><br>
@@ -47,7 +47,7 @@ AutoCaps selected value="${request_headers.query.subscriber_contact || ""}">
<option${(request_headers.query.subscriber_contact_method == "Instagram") ? " selected" : ""}>Instagram</option>
</select>
`;
var form_data = `<shadow>
const form_data = `<shadow>
<input type=submit Value=Continue name="Continue" borderimage="file://ROM/Borders/ButtonBorder2.bif" text="#dddddd" width=110>
</shadow>
</font>

View File

@@ -1,4 +1,4 @@
var minisrv_service_file = true;
const minisrv_service_file = true;
if (!request_headers.query.registering ||
@@ -10,20 +10,20 @@ if (!request_headers.query.registering ||
!session_data ||
!socket.ssid
) {
var errpage = wtvshared.doErrorPage(400);
const errpage = wtvshared.doErrorPage(400);
headers = errpage[0];
data = errpage[1];
} else {
if (request_headers.query['Change']) {
var changeUrl = "wtv-register:/ValidateAgreement?registering=" + encodeURIComponent(request_headers.query.registering) + "&subscriber_name=" + encodeURIComponent(request_headers.query.subscriber_name);
let changeUrl = "wtv-register:/ValidateAgreement?registering=" + encodeURIComponent(request_headers.query.registering) + "&subscriber_name=" + encodeURIComponent(request_headers.query.subscriber_name);
changeUrl += "&subscriber_username=" + encodeURIComponent(request_headers.query.subscriber_username) + "&subscriber_contact=" + encodeURIComponent(request_headers.query.subscriber_contact) + "&subscriber_contact_method=" + encodeURIComponent(request_headers.query.subscriber_contact_method);
var errpage = wtvshared.doRedirect(changeUrl);
const errpage = wtvshared.doRedirect(changeUrl);
headers = errpage[0];
data = errpage[1];
} else {
var errpage = null;
let errpage = null;
const WTVRegister = require(classPath + "/WTVRegister.js")
var wtvr = new WTVRegister(minisrv_config, SessionStore);
const wtvr = new WTVRegister(minisrv_config, SessionStore);
if (!request_headers.query.subscriber_username) errpage = wtvshared.doErrorPage(400, "Please enter a username.");
else if (request_headers.query.subscriber_username.length < minisrv_config.config.user_accounts.min_username_length) errpage = wtvshared.doErrorPage(400, "Please choose a username with <b>" + minisrv_config.config.user_accounts.min_username_length + "</b> or more characters.");
else if (request_headers.query.subscriber_username.length > minisrv_config.config.user_accounts.max_username_length) errpage = wtvshared.doErrorPage(400, "Please choose a username with <b>" + minisrv_config.config.user_accounts.max_username_length + "</b> or less characters.");
@@ -39,8 +39,8 @@ if (!request_headers.query.registering ||
session_data.setSessionData("subscriber_contact_method", request_headers.query.subscriber_contact_method);
session_data.setSessionData("subscriber_userid", 0);
session_data.setSessionData("registered", true);
var mailstore_exists = session_data.mailstore.mailstoreExists();
var mailbox_exists = false;
let mailstore_exists = session_data.mailstore.mailstoreExists();
let mailbox_exists = false;
if (!mailstore_exists) mailstore_exists = session_data.mailstore.createMailstore();
if (mailstore_exists) {
if (!session_data.mailstore.mailboxExists(0)) {
@@ -53,7 +53,7 @@ if (!request_headers.query.registering ||
}
}
if (!session_data.saveSessionData(true, true)) {
var errpage = wtvshared.doErrorPage(400);
const errpage = wtvshared.doErrorPage(400);
headers = errpage[0];
data = errpage[1];
} else {

View File

@@ -1,16 +1,16 @@
var minisrv_service_file = true;
const minisrv_service_file = true;
headers = `200 OK
Content-Type: text/html`;
var WTVRegister = require(classPath + "/WTVRegister.js");
var wtvr = new WTVRegister(minisrv_config);
var namerand = Math.floor(Math.random() * 100000);
var nickname = (minisrv_config.config.service_name + '_' + namerand)
var human_name = nickname;
var isOldBuild = wtvshared.isOldBuild(session_data);
var form_data = `<input type=button action="ValidateAgreement?registering=true&subscriber_name=${human_name}&subscriber_username=${nickname}" text="#dddddd" Value="Quick Reg" name="speedyreg" borderimage="file://ROM/Borders/ButtonBorder2.bif" width=130>`;
var main_data = `<form action="ValidateAgreement"
const WTVRegister = require(classPath + "/WTVRegister.js");
const wtvr = new WTVRegister(minisrv_config);
const namerand = Math.floor(Math.random() * 100000);
const nickname = (minisrv_config.config.service_name + '_' + namerand)
const human_name = nickname;
const isOldBuild = wtvshared.isOldBuild(session_data);
let form_data = `<input type=button action="ValidateAgreement?registering=true&subscriber_name=${human_name}&subscriber_username=${nickname}" text="#dddddd" Value="Quick Reg" name="speedyreg" borderimage="file://ROM/Borders/ButtonBorder2.bif" width=130>`;
const main_data = `<form action="ValidateAgreement"
ENCTYPE="x-www-form-encoded" METHOD="POST">
<input type=hidden name=registering value="true">
Welcome to the ${minisrv_config.config.service_name} Mini Service, operated by ${minisrv_config.config.service_owner}.

View File

@@ -1,4 +1,4 @@
var minisrv_service_file = true;
const minisrv_service_file = true;
headers = `200 OK
Connection: Keep-Alive

View File

@@ -1,4 +1,4 @@
minisrv_service_file = true;
const minisrv_service_file = true;
request_is_async = true;
@@ -6,7 +6,7 @@ request_is_async = true;
async function handleRequest(request_headers) {
const imageUrl = request_headers.query.url;
if (!imageUrl) {
var errpage = wtvshared.doErrorPage(400, "Missing url parameter");
const errpage = wtvshared.doErrorPage(400, "Missing url parameter");
sendToClient(socket, errpage[0], errpage[1]);
return;
}
@@ -16,7 +16,7 @@ async function handleRequest(request_headers) {
const lib = urlObj.protocol === 'https:' ? https : http;
const fetch = (lib, options) => new Promise((resolve, reject) => {
const req = lib.request(imageUrl, options, (res) => {
let data = [];
const data = [];
res.on('data', chunk => data.push(chunk));
res.on('end', () => {
res.buffer = async () => Buffer.concat(data);
@@ -29,7 +29,7 @@ async function handleRequest(request_headers) {
});
const imgRes = await fetch(lib, { method: 'GET', headers: { 'User-Agent': 'Mozilla/4.0 WebTV/2.6 (compatible; MSIE 4.0)' } });
if (!imgRes.ok) {
var errpage = wtvshared.doErrorPage(502, "Failed to fetch image");
const errpage = wtvshared.doErrorPage(502, "Failed to fetch image");
sendToClient(socket, errpage[0], errpage[1]);
return;
}
@@ -44,7 +44,7 @@ Content-Type: image/png`;
data = resized;
sendToClient(socket, headers, data);
} catch (err) {
var errpage = wtvshared.doErrorPage(500, "Error processing image: " + err.message);
const errpage = wtvshared.doErrorPage(500, "Error processing image: " + err.message);
sendToClient(socket, errpage[0], errpage[1]);
}
}

View File

@@ -1,7 +1,7 @@
minisrv_service_file = true;
const minisrv_service_file = true;
request_is_async = true;
var searchUrl = minisrv_config.services[service_name].searxng_url;
let searchUrl = minisrv_config.services[service_name].searxng_url;
if (!searchUrl.endsWith('/')) {
searchUrl += '/';
}
@@ -42,7 +42,7 @@ if (!request_headers.query.q) {
params.append('limit', '10');
const urlObj = new URL(searchUrl);
const lib = urlObj.protocol === 'https:' ? https : http;
var post_data = params.toString();
const post_data = params.toString();
const options = {
protocol: urlObj.protocol,
hostname: urlObj.hostname,
@@ -68,7 +68,7 @@ if (!request_headers.query.q) {
function fetch(lib, options, post_data) {
return new Promise((resolve, reject) => {
var req = lib.request(options, (res) => {
const req = lib.request(options, (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => resolve({ text: () => Promise.resolve(data) }));

View File

@@ -49,5 +49,5 @@ Content-Type: text/html`;
data += k + "=" + encodeURIComponent(settings_obj[k]) + "&";
});
data = data.substring(0, (data.length - 1));
data = data.slice(0, (data.length - 1));
}

View File

@@ -108,7 +108,7 @@ Choose the songs that you'd like to include.
let strLenLimit = 16;
if (musicList.length > 14) strLenLimit = 20;
let songTitle = musicList[k]['title'];
if (songTitle.length > strLenLimit) songTitle = musicList[k]['title'].substr(0, strLenLimit - 3) + "...";
if (songTitle.length > strLenLimit) songTitle = musicList[k]['title'].slice(0, strLenLimit - 3) + "...";
if (musicList.length > 14) data += '<font size="-2">';
data += `<a href="${musicList[k]['url']}?wtv-title=${encodeURIComponent(musicList[k]['title'])}" onmouseout="clearTitle()" onmouseover="showTitle('${musicList[k]['title'].replace(/\'/g, "\\'")}')">${songTitle}</a>
</td></tr></tbody></table>`;

View File

@@ -8,7 +8,7 @@ else if (session_data.user_id != 0) errpage = wtvshared.doErrorPage(400, "You ar
const usersToRemove = [];
Object.keys(request_headers.query).forEach(function (k) {
if (k.substr(0, 4) === "user" && request_headers.query[k] === "on") {
if (k.slice(0, 4) === "user" && request_headers.query[k] === "on") {
usersToRemove.push(parseInt(k.replace("user", "")));
}
});
@@ -31,7 +31,7 @@ if (errpage) {
}
let removeurl = request_headers.request_url;
if (removeurl.indexOf('?') >= 0) {
removeurl = removeurl.substring(0, removeurl.indexOf('?'));
removeurl = removeurl.slice(0, removeurl.indexOf('?'));
}
removeurl += "?";

View File

@@ -1,4 +1,4 @@
var minisrv_service_file = true;
const minisrv_service_file = true;
headers = `200 OK
Content-type: text/html

View File

@@ -138,6 +138,13 @@ function checkScopeErrors(file) {
// Check if either service name exists and is privileged
const service = config.services[serviceNameWithPrefix] || config.services[serviceNameWithoutPrefix];
if (serviceName === "wtv-news") {
eslintConfig.globals = {
...eslintConfig.globals,
"wtvnewsserver": "readonly"
};
}
if (service && service.privileged === true) {
// Add additional globals for privileged services
@@ -150,12 +157,12 @@ function checkScopeErrors(file) {
"classPath": "readonly",
"session_data": "readonly",
};
if (service.modules) {
for (const moduleName of service.modules) {
eslintConfig.globals[moduleName] = "readonly";
}
}
}
if (service.modules) {
for (const moduleName of service.modules) {
eslintConfig.globals[moduleName] = "readonly";
}
}
}
} catch (e) {
// If we can't load config, just continue with basic globals