fix parsing of discuss boolean in sendmail

This commit is contained in:
zefie
2022-10-01 22:37:10 -04:00
parent 8f3ba3d49e
commit 1752bfed35
2 changed files with 19 additions and 9 deletions

View File

@@ -16,7 +16,7 @@ if (!intro_seen && !request_headers.query.intro_seen) {
'noback': true, 'noback': true,
}).getURL(); }).getURL();
headers = "200 OK\nwtv-visit: " + clientErrorMsg; return "200 OK\nwtv-visit: " + clientErrorMsg;
} }
if (request_headers.query.clear == "true") { if (request_headers.query.clear == "true") {
@@ -29,7 +29,7 @@ Location: wtv-mail:/sendmail`;
} }
var newsgroup = null; var newsgroup = null;
if (request_headers.query.discuss) { if (parseBool(request_headers.query.discuss)) {
newsgroup = request_headers.query.group || request_headers.query.message_to || null; newsgroup = request_headers.query.group || request_headers.query.message_to || null;
} }
@@ -117,7 +117,7 @@ Content-Type: audio/wav`;
if (newsgroup !== null) { if (newsgroup !== null) {
var request_is_async = true; var request_is_async = true;
if (msg_body === null) { if (msg_body === null) {
doClientError("Please type a message to send to the group."); headers = doClientError("Please type a message to send to the group.");
sendToClient(socket, headers, ''); sendToClient(socket, headers, '');
} else { } else {
const Client = require('newsie').default const Client = require('newsie').default
@@ -150,14 +150,14 @@ Content-Type: audio/wav`;
} }
return response.send(articleData); return response.send(articleData);
} else { } else {
clientErrorMsg("Could not send post. Server returned error " + response.code); headers = doClientError("Could not send post. Server returned error " + response.code);
sendToClient(socket, headers, ''); sendToClient(socket, headers, '');
return client.quit(); return client.quit();
} }
}) })
.then(response => { .then(response => {
if (response.code !== 240) { if (response.code !== 240) {
clientErrorMsg("Could not send post. Server returned error " + response.code); headers = doClientError("Could not send post. Server returned error " + response.code);
sendToClient(socket, headers, ''); sendToClient(socket, headers, '');
} else { } else {
headers = `300 OK headers = `300 OK
@@ -169,7 +169,8 @@ Location: wtv-news:/news?group=${newsgroup}`;
} }
}).catch(e => { }).catch(e => {
console.log('usenet upstream uncaught error', e); console.log('usenet upstream uncaught error', e);
clientErrorMsg("Could not send post. Server returned unknown error"); headers = doClientError("Could not send post. Server returned unknown error");
sendToClient(socket, headers, ''); sendToClient(socket, headers, '');
}); });
} }

View File

@@ -39,6 +39,14 @@ var socket_sessions = new Array();
var ports = []; var ports = [];
// for scripts
function parseBool(val) {
if (typeof val === 'string')
val = val.toLowerCase();
return val === true || val === "true";
}
// add .reverse() feature to all JavaScript Strings in this application // add .reverse() feature to all JavaScript Strings in this application
// works for service vault scripts too. // works for service vault scripts too.
if (!String.prototype.reverse) { if (!String.prototype.reverse) {
@@ -113,7 +121,7 @@ async function processPath(socket, service_vault_file_path, request_headers = ne
// Furthermore, only modifications to variables in `updateFromVM` will be saved. // Furthermore, only modifications to variables in `updateFromVM` will be saved.
// Example: an attempt to change "minisrv_config" from a ServiceVault script would be discarded // Example: an attempt to change "minisrv_config" from a ServiceVault script would be discarded
// node core functions/vars // node core variables and functions
var contextObj = { var contextObj = {
console: console, // needed for per-script debugging console: console, // needed for per-script debugging
require: require, // this is dangerous but needed for some scripts at this time require: require, // this is dangerous but needed for some scripts at this time
@@ -135,7 +143,7 @@ async function processPath(socket, service_vault_file_path, request_headers = ne
fs: fs fs: fs
} }
// Our variables // Our variables and functions
contextObj = { contextObj = {
...contextObj, ...contextObj,
minisrv_config: minisrv_config, minisrv_config: minisrv_config,
@@ -151,7 +159,8 @@ async function processPath(socket, service_vault_file_path, request_headers = ne
headers: headers, headers: headers,
data: data, data: data,
request_is_async: request_is_async, request_is_async: request_is_async,
minisrv_version_string: z_title minisrv_version_string: z_title,
parseBool: parseBool
} }
// Our prototype overrides // Our prototype overrides