fixes and optimizations
This commit is contained in:
@@ -232,7 +232,7 @@ const runScriptInVM = function (script_data, user_contextObj = {}, privileged =
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create global context object
|
// create global context object
|
||||||
const contextObj = {
|
let contextObj = {
|
||||||
// node core variables and functions
|
// node core variables and functions
|
||||||
"console": console, // needed for per-script debugging
|
"console": console, // needed for per-script debugging
|
||||||
"__dirname": __dirname, // needed by services such as wtv-flashrom and wtv-disk
|
"__dirname": __dirname, // needed by services such as wtv-flashrom and wtv-disk
|
||||||
@@ -1478,9 +1478,9 @@ async function sendToClient(socket, headers_obj, data = null) {
|
|||||||
if (socket_sessions[socket.id].request_headers) {
|
if (socket_sessions[socket.id].request_headers) {
|
||||||
if (socket_sessions[socket.id].request_headers.service_file_path) {
|
if (socket_sessions[socket.id].request_headers.service_file_path) {
|
||||||
// Don't change Last-modified header if provided already
|
// Don't change Last-modified header if provided already
|
||||||
if (!headers['Last-Modified']) {
|
if (!headers['Last-Modified'] && !headers['minisrv-no-last-modified']) {
|
||||||
// Only add the header if not a js, php, or cgi file
|
// Only add the header if not a js, php, or cgi file
|
||||||
if (wtvshared.getFileExt(socket_sessions[socket.id].request_headers.service_file_path).toLowerCase() !== "js" ||
|
if (wtvshared.getFileExt(socket_sessions[socket.id].request_headers.service_file_path).toLowerCase() !== "js" ||
|
||||||
wtvshared.getFileExt(socket_sessions[socket.id].request_headers.service_file_path).toLowerCase() !== "php" ||
|
wtvshared.getFileExt(socket_sessions[socket.id].request_headers.service_file_path).toLowerCase() !== "php" ||
|
||||||
wtvshared.getFileExt(socket_sessions[socket.id].request_headers.service_file_path).toLowerCase() !== "cgi" ||
|
wtvshared.getFileExt(socket_sessions[socket.id].request_headers.service_file_path).toLowerCase() !== "cgi" ||
|
||||||
socket_sessions[socket.id].request_headers.raw_file === true) {
|
socket_sessions[socket.id].request_headers.raw_file === true) {
|
||||||
@@ -1500,6 +1500,14 @@ async function sendToClient(socket, headers_obj, data = null) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (headers_obj['minisrv-no-last-modified']) {
|
||||||
|
if (headers_obj['Last-Modified']) {
|
||||||
|
delete headers_obj['Last-Modified'];
|
||||||
|
}
|
||||||
|
delete headers_obj['minisrv-no-last-modified'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// if client can do compression, see if its worth enabling
|
// if client can do compression, see if its worth enabling
|
||||||
// small files actually get larger, so don't compress them
|
// small files actually get larger, so don't compress them
|
||||||
@@ -1667,7 +1675,7 @@ async function sendToClient(socket, headers_obj, data = null) {
|
|||||||
|
|
||||||
// Delete any other stray minisrv headers (we process them all before this)
|
// Delete any other stray minisrv headers (we process them all before this)
|
||||||
Object.keys(headers_obj).forEach(function (k) {
|
Object.keys(headers_obj).forEach(function (k) {
|
||||||
if (k.indexOf("minisrv-") == 0) {
|
if (k.startsWith("minisrv-")) {
|
||||||
delete headers_obj[k];
|
delete headers_obj[k];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1042,7 +1042,7 @@ class WebTVClientSimulator {
|
|||||||
this.followVisit(headers['wtv-visit'])
|
this.followVisit(headers['wtv-visit'])
|
||||||
.then(resolve)
|
.then(resolve)
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
}, this.requestDelay);
|
}, this.requestDelay);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
this.debugLog(`Skipping wtv-visit redirect: ${headers['wtv-visit']}`);
|
this.debugLog(`Skipping wtv-visit redirect: ${headers['wtv-visit']}`);
|
||||||
@@ -1252,7 +1252,7 @@ class WebTVClientSimulator {
|
|||||||
} else {
|
} else {
|
||||||
// Detect text content for CLI output
|
// Detect text content for CLI output
|
||||||
const contentType = result.headers['content-type'] || '';
|
const contentType = result.headers['content-type'] || '';
|
||||||
if (/^text\//.test(contentType) || /json|xml|javascript|download-list/.test(contentType)) {
|
if (/^text\//.test(contentType) || /json|xml|javascript||download-list/.test(contentType) || contentType === "x-wtv-addresses") {
|
||||||
console.log(result.body.toString('utf8'));
|
console.log(result.body.toString('utf8'));
|
||||||
} else if (result.body.length === 0) {
|
} else if (result.body.length === 0) {
|
||||||
console.log('<empty response>');
|
console.log('<empty response>');
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
var minisrv_service_file = true;
|
var minisrv_service_file = true;
|
||||||
|
|
||||||
headers = `200 OK
|
headers = `200 OK
|
||||||
Content-Type: x-wtv-addresses`;
|
Content-Type: x-wtv-addresses
|
||||||
|
wtv-transition: light
|
||||||
|
minisrv-no-last-modified: true
|
||||||
|
minisrv-no-mail-count: true`;
|
||||||
|
|
||||||
const address_book = session_data.getSessionData("address_book")
|
const address_book = session_data.getSessionData("address_book")
|
||||||
|
|
||||||
@@ -9,7 +12,7 @@ if (session_data.getSessionData("address_book") != null) {
|
|||||||
data = ``
|
data = ``
|
||||||
for (let i = 0; i < address_book.length; i++) {
|
for (let i = 0; i < address_book.length; i++) {
|
||||||
data += address_book[i].name + '\0' + address_book[i].address + '\0'
|
data += address_book[i].name + '\0' + address_book[i].address + '\0'
|
||||||
}
|
};
|
||||||
} else {
|
} else {
|
||||||
session_data.setSessionData("address_book", [])
|
session_data.setSessionData("address_book", [])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,14 +41,11 @@ Location: wtv-mail:/listmail`;
|
|||||||
Content-type: text/html`;
|
Content-type: text/html`;
|
||||||
|
|
||||||
|
|
||||||
var message_colors = null;
|
let message_colors = session_data.mailstore.defaultColors;
|
||||||
if (message.body) {
|
if (message.body) {
|
||||||
if (message.body.indexOf("<body")) {
|
if (message.body.indexOf("<body")) {
|
||||||
var default_colors = session_data.mailstore.defaultColors;
|
message_colors = session_data.mailstore.getSignatureColors(message.body);
|
||||||
var message_colors = session_data.mailstore.getSignatureColors(message.body);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
message_colors = session_data.mailstore.defaultColors;
|
|
||||||
}
|
}
|
||||||
if (message.signature) message_colors = session_data.mailstore.getSignatureColors(message.signature);
|
if (message.signature) message_colors = session_data.mailstore.getSignatureColors(message.signature);
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ class WTVFavorites {
|
|||||||
constructor(minisrv_config, wtvclient) {
|
constructor(minisrv_config, wtvclient) {
|
||||||
if (!minisrv_config) throw ("minisrv_config required");
|
if (!minisrv_config) throw ("minisrv_config required");
|
||||||
if (!wtvclient) throw ("WTVClientSessionData required");
|
if (!wtvclient) throw ("WTVClientSessionData required");
|
||||||
var WTVShared = require("./WTVShared.js")['WTVShared'];
|
const WTVShared = require("./WTVShared.js")['WTVShared'];
|
||||||
var WTVMime = require("./WTVMime.js");
|
const WTVMime = require("./WTVMime.js");
|
||||||
this.WTVClientSessionData = require("./WTVClientSessionData.js");
|
this.WTVClientSessionData = require("./WTVClientSessionData.js");
|
||||||
this.minisrv_config = minisrv_config;
|
this.minisrv_config = minisrv_config;
|
||||||
this.wtvshared = new WTVShared(minisrv_config);
|
this.wtvshared = new WTVShared(minisrv_config);
|
||||||
@@ -42,10 +42,10 @@ class WTVFavorites {
|
|||||||
if (!this.isguest) {
|
if (!this.isguest) {
|
||||||
if (this.favstore_dir === null) {
|
if (this.favstore_dir === null) {
|
||||||
// set favstore directory local var so we don't call the function every time
|
// set favstore directory local var so we don't call the function every time
|
||||||
var userstore_dir = this.wtvclient.getUserStoreDirectory();
|
const userstore_dir = this.wtvclient.getUserStoreDirectory();
|
||||||
|
|
||||||
// FavStore
|
// FavStore
|
||||||
var store_dir = "FavStore" + this.path.sep;
|
const store_dir = "FavStore" + this.path.sep;
|
||||||
this.favstore_dir = userstore_dir + store_dir;
|
this.favstore_dir = userstore_dir + store_dir;
|
||||||
}
|
}
|
||||||
return this.fs.existsSync(this.favstore_dir);
|
return this.fs.existsSync(this.favstore_dir);
|
||||||
@@ -54,12 +54,12 @@ class WTVFavorites {
|
|||||||
}
|
}
|
||||||
|
|
||||||
folderExists(foldername) {
|
folderExists(foldername) {
|
||||||
var folder_dir = null;
|
let folder_dir, store_dir = null;
|
||||||
if (this.favstoreExists()) {
|
if (this.favstoreExists()) {
|
||||||
if (!foldername) return null;
|
if (!foldername) return null;
|
||||||
|
|
||||||
var folder_dir = foldername + this.path.sep;
|
folder_dir = foldername + this.path.sep;
|
||||||
var store_dir = this.favstore_dir + folder_dir;
|
store_dir = this.favstore_dir + folder_dir;
|
||||||
}
|
}
|
||||||
if (store_dir) {
|
if (store_dir) {
|
||||||
if (this.fs.existsSync(store_dir)) {
|
if (this.fs.existsSync(store_dir)) {
|
||||||
@@ -72,12 +72,12 @@ class WTVFavorites {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getFolderDir(foldername) {
|
getFolderDir(foldername) {
|
||||||
var folder_dir = null;
|
let folder_dir, store_dir = null;
|
||||||
if (this.favstoreExists()) {
|
if (this.favstoreExists()) {
|
||||||
if (!foldername) return null;
|
if (!foldername) return null;
|
||||||
|
|
||||||
var folder_dir = foldername + this.path.sep;
|
folder_dir = foldername + this.path.sep;
|
||||||
var store_dir = this.favstore_dir + folder_dir;
|
store_dir = this.favstore_dir + folder_dir;
|
||||||
}
|
}
|
||||||
return store_dir;
|
return store_dir;
|
||||||
}
|
}
|
||||||
@@ -85,9 +85,9 @@ class WTVFavorites {
|
|||||||
createTemplateFolder(folder) {
|
createTemplateFolder(folder) {
|
||||||
// create emply folder
|
// create emply folder
|
||||||
this.createFolder(folder)
|
this.createFolder(folder)
|
||||||
var folder_templates = this.minisrv_config.favorites.folder_templates;
|
const folder_templates = this.minisrv_config.favorites.folder_templates;
|
||||||
// populate it if a template exists
|
// populate it if a template exists
|
||||||
var self = this;
|
const self = this;
|
||||||
if (folder_templates[folder]) {
|
if (folder_templates[folder]) {
|
||||||
Object.keys(folder_templates[folder]).forEach(function (k) {
|
Object.keys(folder_templates[folder]).forEach(function (k) {
|
||||||
self.createFavorite(folder_templates[folder][k].title, folder_templates[folder][k].url, folder, (folder_templates[folder][k].image_type == "image/wtv-bitmap") ? atob(folder_templates[folder][k].image) : folder_templates[folder][k].image, folder_templates[folder][k].image_type);
|
self.createFavorite(folder_templates[folder][k].title, folder_templates[folder][k].url, folder, (folder_templates[folder][k].image_type == "image/wtv-bitmap") ? atob(folder_templates[folder][k].image) : folder_templates[folder][k].image, folder_templates[folder][k].image_type);
|
||||||
@@ -96,7 +96,7 @@ class WTVFavorites {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createDefaultFolders() {
|
createDefaultFolders() {
|
||||||
var brandId = this.ssid.charAt(8);
|
const brandId = this.ssid.charAt(8);
|
||||||
this.createTemplateFolder("Recommended");
|
this.createTemplateFolder("Recommended");
|
||||||
if (brandId == 7)
|
if (brandId == 7)
|
||||||
this.createTemplateFolder("Personal (Samsung)");
|
this.createTemplateFolder("Personal (Samsung)");
|
||||||
@@ -118,10 +118,10 @@ class WTVFavorites {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createFolder(foldername) {
|
createFolder(foldername) {
|
||||||
var folder_exists = this.folderExists(foldername);
|
const folder_exists = this.folderExists(foldername);
|
||||||
if (folder_exists === false) {
|
if (folder_exists === false) {
|
||||||
var folderdir = foldername + this.path.sep;
|
const folderdir = foldername + this.path.sep;
|
||||||
var store_dir = this.favstore_dir + folderdir;
|
const store_dir = this.favstore_dir + folderdir;
|
||||||
if (!this.fs.existsSync(store_dir)) this.fs.mkdirSync(store_dir, { recursive: true });
|
if (!this.fs.existsSync(store_dir)) this.fs.mkdirSync(store_dir, { recursive: true });
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -129,8 +129,8 @@ class WTVFavorites {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getFolders() {
|
getFolders() {
|
||||||
var path = this.favstore_dir;
|
const path = this.favstore_dir;
|
||||||
var self = this;
|
const self = this;
|
||||||
return this.fs.readdirSync(path).filter(function (file) {
|
return this.fs.readdirSync(path).filter(function (file) {
|
||||||
if (self.folderExists(file)) {
|
if (self.folderExists(file)) {
|
||||||
self.folderArr.push(file);
|
self.folderArr.push(file);
|
||||||
@@ -144,16 +144,16 @@ class WTVFavorites {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createFavorite(title, url, folder, image, imagetype) {
|
createFavorite(title, url, folder, image, imagetype) {
|
||||||
var folderpath = this.getFolderDir(folder);
|
const folderpath = this.getFolderDir(folder);
|
||||||
var favoriteid = this.createFavoriteID();
|
const favoriteid = this.createFavoriteID();
|
||||||
var favoritefile = favoriteid + this.favFileExt;
|
const favoritefile = favoriteid + this.favFileExt;
|
||||||
var favoritefileout = folderpath + favoritefile;
|
const favoritefileout = folderpath + favoritefile;
|
||||||
if (imagetype != "url")
|
if (imagetype != "url")
|
||||||
image = btoa(image);
|
image = btoa(image);
|
||||||
|
|
||||||
title = decodeURIComponent(title).replaceAll("+", " ");
|
title = decodeURIComponent(title).replaceAll("+", " ");
|
||||||
url = decodeURIComponent(url)
|
url = decodeURIComponent(url)
|
||||||
var favoritedata = {
|
const favoritedata = {
|
||||||
"title": title,
|
"title": title,
|
||||||
"url": url,
|
"url": url,
|
||||||
"folder": folder,
|
"folder": folder,
|
||||||
@@ -168,7 +168,7 @@ class WTVFavorites {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// encode favorite into json
|
// encode favorite into json
|
||||||
var result = this.fs.writeFileSync(favoritefileout, JSON.stringify(favoritedata));
|
const result = this.fs.writeFileSync(favoritefileout, JSON.stringify(favoritedata));
|
||||||
if (!result) return false;
|
if (!result) return false;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -178,8 +178,8 @@ class WTVFavorites {
|
|||||||
}
|
}
|
||||||
|
|
||||||
listFavorites(folder) {
|
listFavorites(folder) {
|
||||||
var folderpath = this.getFolderDir(folder);
|
const folderpath = this.getFolderDir(folder);
|
||||||
var self = this;
|
const self = this;
|
||||||
self.messageArr = [];
|
self.messageArr = [];
|
||||||
this.fs.readdirSync(folderpath)
|
this.fs.readdirSync(folderpath)
|
||||||
.map(function (v) {
|
.map(function (v) {
|
||||||
@@ -211,16 +211,16 @@ class WTVFavorites {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getFavorite(folder, favoriteid) {
|
getFavorite(folder, favoriteid) {
|
||||||
var folder_path = this.getFolderDir(folder);
|
const folder_path = this.getFolderDir(folder);
|
||||||
var folder_file = favoriteid + this.favFileExt;
|
const folder_file = favoriteid + this.favFileExt;
|
||||||
var folder_file_in = folder_path + this.path.sep + folder_file;
|
const folder_file_in = folder_path + this.path.sep + folder_file;
|
||||||
var folder_data_raw = null;
|
let folder_data_raw = null;
|
||||||
|
|
||||||
if (this.fs.existsSync(folder_file_in)) folder_data_raw = this.fs.readFileSync(folder_file_in);
|
if (this.fs.existsSync(folder_file_in)) folder_data_raw = this.fs.readFileSync(folder_file_in);
|
||||||
else console.error(" # FavErr: could not find ", folder_file_in);
|
else console.error(" # FavErr: could not find ", folder_file_in);
|
||||||
|
|
||||||
if (folder_data_raw) {
|
if (folder_data_raw) {
|
||||||
var folder_data = JSON.parse(folder_data_raw);
|
const folder_data = JSON.parse(folder_data_raw);
|
||||||
folder_data.folder_path = folder_path;
|
folder_data.folder_path = folder_path;
|
||||||
folder_data.folder_file = folder_file;
|
folder_data.folder_file = folder_file;
|
||||||
if (folder_data) {
|
if (folder_data) {
|
||||||
@@ -234,7 +234,7 @@ class WTVFavorites {
|
|||||||
}
|
}
|
||||||
|
|
||||||
deleteFolder(folder){
|
deleteFolder(folder){
|
||||||
var dir = this.getFolderDir(folder);
|
const dir = this.getFolderDir(folder);
|
||||||
if (dir) {
|
if (dir) {
|
||||||
try {
|
try {
|
||||||
this.fs.rm(dir, { recursive: true });
|
this.fs.rm(dir, { recursive: true });
|
||||||
@@ -251,29 +251,29 @@ class WTVFavorites {
|
|||||||
}
|
}
|
||||||
|
|
||||||
deleteFavorite(favoriteid, folder) {
|
deleteFavorite(favoriteid, folder) {
|
||||||
var folderdir = this.getFolderDir(folder);
|
const folderdir = this.getFolderDir(folder);
|
||||||
this.fs.unlinkSync(folderdir + favoriteid + ".zfav", { recursive: true });
|
this.fs.unlinkSync(folderdir + favoriteid + ".zfav", { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
clearFolder(folder) {
|
clearFolder(folder) {
|
||||||
const { readdirSync, rmSync } = require('fs');
|
const { readdirSync, rmSync } = require('fs');
|
||||||
var dir = this.getFolderDir(folder);
|
const dir = this.getFolderDir(folder);
|
||||||
readdirSync(dir).forEach(f => rmSync(`${dir}${f}`));
|
readdirSync(dir).forEach(f => rmSync(`${dir}${f}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
updateFavorite(favoritedata, folder) {
|
updateFavorite(favoritedata, folder) {
|
||||||
// encode message into json
|
// encode message into json
|
||||||
var favoriteout = new Object();
|
const favoriteout = new Object();
|
||||||
var folderpath = this.getFolderDir(folder);
|
const folderpath = this.getFolderDir(folder);
|
||||||
Object.assign(favoriteout, favoritedata);
|
Object.assign(favoriteout, favoritedata);
|
||||||
delete favoriteout.folderpath;
|
delete favoriteout.folderpath;
|
||||||
delete favoriteout.favoritefile;
|
delete favoriteout.favoritefile;
|
||||||
var result = this.fs.writeFileSync(folderpath + favoritedata.id + ".zfav", JSON.stringify(favoriteout));
|
const result = this.fs.writeFileSync(folderpath + favoritedata.id + ".zfav", JSON.stringify(favoriteout));
|
||||||
if (!result) return false;
|
if (!result) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
changeFavoriteName(favoriteid, folder, name) {
|
changeFavoriteName(favoriteid, folder, name) {
|
||||||
var favorite = this.getFavorite(folder, favoriteid);
|
const favorite = this.getFavorite(folder, favoriteid);
|
||||||
if (!favorite) return false;
|
if (!favorite) return false;
|
||||||
|
|
||||||
favorite.title = name;
|
favorite.title = name;
|
||||||
@@ -282,19 +282,19 @@ class WTVFavorites {
|
|||||||
}
|
}
|
||||||
|
|
||||||
moveFavorite(oldfolder, newfolder, favoriteid) {
|
moveFavorite(oldfolder, newfolder, favoriteid) {
|
||||||
var favorite = this.getFavorite(oldfolder, favoriteid);
|
const favorite = this.getFavorite(oldfolder, favoriteid);
|
||||||
if (!favorite) return false;
|
if (!favorite) return false;
|
||||||
|
|
||||||
var newfolderdata = this.listFavorites(newfolder);
|
const newfolderdata = this.listFavorites(newfolder);
|
||||||
var newfoldernum = newfolderdata.length
|
const newfoldernum = newfolderdata.length
|
||||||
|
|
||||||
if (newfoldernum > 17)
|
if (newfoldernum > 17)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
favorite.folder = newfolder;
|
favorite.folder = newfolder;
|
||||||
this.updateFavorite(favorite, oldfolder);
|
this.updateFavorite(favorite, oldfolder);
|
||||||
var favoriteout = new Object();
|
const favoriteout = new Object();
|
||||||
var folderpath = this.getFolderDir(newfolder);
|
const folderpath = this.getFolderDir(newfolder);
|
||||||
Object.assign(favoriteout, favorite);
|
Object.assign(favoriteout, favorite);
|
||||||
delete favoriteout.folderpath;
|
delete favoriteout.folderpath;
|
||||||
delete favoriteout.favoritefile;
|
delete favoriteout.favoritefile;
|
||||||
@@ -305,14 +305,13 @@ class WTVFavorites {
|
|||||||
|
|
||||||
|
|
||||||
isFavoriteAShortcut(favoriteid) {
|
isFavoriteAShortcut(favoriteid) {
|
||||||
var favoritefileout = this.favstore_dir + "KeyStore.zfav";
|
const favoritefileout = this.favstore_dir + "KeyStore.zfav";
|
||||||
if (!this.fs.existsSync(favoritefileout)) {
|
if (!this.fs.existsSync(favoritefileout)) {
|
||||||
this.createShortcutKey();
|
this.createShortcutKey();
|
||||||
}
|
}
|
||||||
var keydata = {};
|
const keydata = JSON.parse(this.fs.readFileSync(favoritefileout));
|
||||||
keydata = JSON.parse(this.fs.readFileSync(favoritefileout));
|
const keys = Object.keys(keydata);
|
||||||
var keys = Object.keys(keydata);
|
for (let i = 0; i < keys.length; i++) {
|
||||||
for (var i = 0; i < keys.length; i++) {
|
|
||||||
if (keydata[keys[i]].id == favoriteid) {
|
if (keydata[keys[i]].id == favoriteid) {
|
||||||
return { key: keys[i], folder: keydata[keys[i]].folder };
|
return { key: keys[i], folder: keydata[keys[i]].folder };
|
||||||
}
|
}
|
||||||
@@ -321,20 +320,19 @@ class WTVFavorites {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getShortcutKey(key) {
|
getShortcutKey(key) {
|
||||||
var favoritefileout = this.favstore_dir + "KeyStore.zfav";
|
const favoritefileout = this.favstore_dir + "KeyStore.zfav";
|
||||||
if (!this.fs.existsSync(favoritefileout)) {
|
if (!this.fs.existsSync(favoritefileout)) {
|
||||||
this.createShortcutKey();
|
this.createShortcutKey();
|
||||||
}
|
}
|
||||||
var keydata = {};
|
const keydata = JSON.parse(this.fs.readFileSync(favoritefileout));
|
||||||
keydata = JSON.parse(this.fs.readFileSync(favoritefileout));
|
|
||||||
if (key && keydata[key]) {
|
if (key && keydata[key]) {
|
||||||
return { folder: keydata[key].folder, id: keydata[key].id };
|
return { folder: keydata[key].folder, id: keydata[key].id };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
createShortcutKey() {
|
createShortcutKey() {
|
||||||
var favoritefileout = this.favstore_dir + "KeyStore.zfav";
|
const favoritefileout = this.favstore_dir + "KeyStore.zfav";
|
||||||
var keydata = {};
|
const keydata = {};
|
||||||
|
|
||||||
keydata.F1 = {
|
keydata.F1 = {
|
||||||
folder: "none",
|
folder: "none",
|
||||||
@@ -367,7 +365,7 @@ class WTVFavorites {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// encode favorite into json
|
// encode favorite into json
|
||||||
var result = this.fs.writeFileSync(favoritefileout, JSON.stringify(keydata));
|
const result = this.fs.writeFileSync(favoritefileout, JSON.stringify(keydata));
|
||||||
if (!result) return false;
|
if (!result) return false;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -377,13 +375,11 @@ class WTVFavorites {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateShortcutKey(oldkey, newkey, folder, id) {
|
updateShortcutKey(oldkey, newkey, folder, id) {
|
||||||
var favoritefileout = this.favstore_dir + "KeyStore.zfav";
|
const favoritefileout = this.favstore_dir + "KeyStore.zfav";
|
||||||
if (!this.fs.existsSync(favoritefileout)) {
|
if (!this.fs.existsSync(favoritefileout)) {
|
||||||
this.createShortcutKey();
|
this.createShortcutKey();
|
||||||
}
|
}
|
||||||
var keydata = {};
|
const keydata = JSON.parse(this.fs.readFileSync(favoritefileout));
|
||||||
|
|
||||||
keydata = JSON.parse(this.fs.readFileSync(favoritefileout))
|
|
||||||
switch(newkey) {
|
switch(newkey) {
|
||||||
case "F1":
|
case "F1":
|
||||||
keydata.F1 = {
|
keydata.F1 = {
|
||||||
@@ -435,7 +431,7 @@ class WTVFavorites {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// encode favorite into json
|
// encode favorite into json
|
||||||
var result = this.fs.writeFileSync(favoritefileout, JSON.stringify(keydata));
|
const result = this.fs.writeFileSync(favoritefileout, JSON.stringify(keydata));
|
||||||
if (!result) return false;
|
if (!result) return false;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class WTVFlashrom {
|
|||||||
|
|
||||||
|
|
||||||
constructor(minisrv_config, service_vaults, service_name, use_zefie_server = true, bf0app_update = false, no_debug = false) {
|
constructor(minisrv_config, service_vaults, service_name, use_zefie_server = true, bf0app_update = false, no_debug = false) {
|
||||||
var { WTVShared } = require("./WTVShared.js");
|
const { WTVShared } = require("./WTVShared.js");
|
||||||
this.service_vaults = service_vaults;
|
this.service_vaults = service_vaults;
|
||||||
this.service_name = service_name;
|
this.service_name = service_name;
|
||||||
this.use_zefie_server = use_zefie_server;
|
this.use_zefie_server = use_zefie_server;
|
||||||
@@ -24,14 +24,12 @@ class WTVFlashrom {
|
|||||||
|
|
||||||
async doLocalFlashROM(flashrom_file_path, request_path, callback, info_only = false) {
|
async doLocalFlashROM(flashrom_file_path, request_path, callback, info_only = false) {
|
||||||
// use local flashrom files;
|
// use local flashrom files;
|
||||||
var self = this;
|
const self = this;
|
||||||
try {
|
try {
|
||||||
this.fs.readFile(flashrom_file_path, null, function (err, data) {
|
this.fs.readFile(flashrom_file_path, null, function (err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
errpage = wtvshared.doErrorPage(400)
|
const errpage = self.wtvshared.doErrorPage(400);
|
||||||
var headers = errpage[0];
|
callback(err.toString(), errpage[0]);
|
||||||
data = err.toString();
|
|
||||||
callback(data, headers);
|
|
||||||
} else {
|
} else {
|
||||||
if (info_only) {
|
if (info_only) {
|
||||||
callback(self.getFlashromInfo(data, request_path));
|
callback(self.getFlashromInfo(data, request_path));
|
||||||
@@ -41,10 +39,8 @@ class WTVFlashrom {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
var errpage = this.wtvshared.doErrorPage(404, "The service could not find the requested ROM.")
|
const errpage = this.wtvshared.doErrorPage(404, "The service could not find the requested ROM.")
|
||||||
var headers = errpage[0];
|
callback(errpage[1], errpage[0]);
|
||||||
var data = errpage[1];
|
|
||||||
callback(data, headers);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,16 +52,16 @@ class WTVFlashrom {
|
|||||||
|
|
||||||
|
|
||||||
getFlashromInfo(data, path) {
|
getFlashromInfo(data, path) {
|
||||||
var flashrom_info = new Array();
|
const flashrom_info = new Array();
|
||||||
var flashrom_magic = "96031889";
|
const flashrom_magic = "96031889";
|
||||||
var part_header = new Buffer.alloc(32);
|
let part_header = new Buffer.alloc(32);
|
||||||
data.copy(part_header, 0, 0, 32);
|
data.copy(part_header, 0, 0, 32);
|
||||||
flashrom_info.header_length = data.readUInt16BE(26);
|
flashrom_info.header_length = data.readUInt16BE(26);
|
||||||
|
|
||||||
flashrom_info.is_bootrom = (/\.brom$/).test(path);
|
flashrom_info.is_bootrom = (/\.brom$/).test(path);
|
||||||
|
|
||||||
// re-read entire header
|
// re-read entire header
|
||||||
var part_header = new Buffer.alloc(flashrom_info.header_length);
|
part_header = new Buffer.alloc(flashrom_info.header_length);
|
||||||
data.copy(part_header, 0, 0, flashrom_info.header_length);
|
data.copy(part_header, 0, 0, flashrom_info.header_length);
|
||||||
|
|
||||||
flashrom_info.magic = part_header.toString('hex', 0, 4);
|
flashrom_info.magic = part_header.toString('hex', 0, 4);
|
||||||
@@ -118,8 +114,8 @@ class WTVFlashrom {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async sendToClient(data, request_path, callback) {
|
async sendToClient(data, request_path, callback) {
|
||||||
var headers = "200 OK\n";
|
let headers = "200 OK\n";
|
||||||
var flashrom_info = this.getFlashromInfo(data, request_path)
|
const flashrom_info = this.getFlashromInfo(data, request_path)
|
||||||
if (flashrom_info.is_bootrom) headers += "Content-Type: binary/x-wtv-bootrom"; // maybe?
|
if (flashrom_info.is_bootrom) headers += "Content-Type: binary/x-wtv-bootrom"; // maybe?
|
||||||
else headers += "Content-Type: binary/x-wtv-flashblock";
|
else headers += "Content-Type: binary/x-wtv-flashblock";
|
||||||
if (flashrom_info.next_rompath != null && this.bf0app_update) headers += "\nwtv-visit: " + flashrom_info.next_rompath;
|
if (flashrom_info.next_rompath != null && this.bf0app_update) headers += "\nwtv-visit: " + flashrom_info.next_rompath;
|
||||||
@@ -134,8 +130,8 @@ class WTVFlashrom {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getFlashRom(request_path, callback, length = 0) {
|
async getFlashRom(request_path, callback, length = 0) {
|
||||||
var headers, flashrom_file_path = null;
|
let headers, data, flashrom_file_path = null;
|
||||||
var self = this;
|
const self = this;
|
||||||
Object.keys(self.service_vaults).forEach(function (g) {
|
Object.keys(self.service_vaults).forEach(function (g) {
|
||||||
if (flashrom_file_path != null) return;
|
if (flashrom_file_path != null) return;
|
||||||
flashrom_file_path = self.service_vaults[g] + "/" + self.service_name + "/" + request_path;
|
flashrom_file_path = self.service_vaults[g] + "/" + self.service_name + "/" + request_path;
|
||||||
@@ -143,7 +139,7 @@ class WTVFlashrom {
|
|||||||
});
|
});
|
||||||
if (this.use_zefie_server && !flashrom_file_path) {
|
if (this.use_zefie_server && !flashrom_file_path) {
|
||||||
// get flashrom files from flashrom.webtv.onl
|
// get flashrom files from flashrom.webtv.onl
|
||||||
var options = {
|
const options = {
|
||||||
host: "flashrom.webtv.onl",
|
host: "flashrom.webtv.onl",
|
||||||
path: "/" + request_path,
|
path: "/" + request_path,
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
@@ -156,7 +152,7 @@ class WTVFlashrom {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const req = this.https.request(options, function (res) {
|
const req = this.https.request(options, function (res) {
|
||||||
var data_hex = '';
|
let data_hex = '';
|
||||||
res.setEncoding('hex');
|
res.setEncoding('hex');
|
||||||
|
|
||||||
res.on('data', d => {
|
res.on('data', d => {
|
||||||
@@ -166,17 +162,17 @@ class WTVFlashrom {
|
|||||||
res.on('end', function () {
|
res.on('end', function () {
|
||||||
if (self.minisrv_config.config.debug_flags.debug) console.log(` * minisrv FlashROM Server HTTP Status: ${res.statusCode} ${res.statusMessage}`)
|
if (self.minisrv_config.config.debug_flags.debug) console.log(` * minisrv FlashROM Server HTTP Status: ${res.statusCode} ${res.statusMessage}`)
|
||||||
if (res.statusCode == 200) {
|
if (res.statusCode == 200) {
|
||||||
var data = Buffer.from(data_hex, 'hex');
|
data = Buffer.from(data_hex, 'hex');
|
||||||
} else if (res.statusCode == 206) {
|
} else if (res.statusCode == 206) {
|
||||||
var data = self.getFlashromInfo(Buffer.from(data_hex, 'hex'), request_path);
|
data = self.getFlashromInfo(Buffer.from(data_hex, 'hex'), request_path);
|
||||||
} else if (res.statusCode == 404) {
|
} else if (res.statusCode == 404) {
|
||||||
var errpage = self.wtvshared.doErrorPage(404, "The service could not find the requested ROM on the minisrv FlashROM server.")
|
const errpage = self.wtvshared.doErrorPage(404, "The service could not find the requested ROM on the minisrv FlashROM server.")
|
||||||
headers = errpage[0];
|
headers = errpage[0];
|
||||||
var data = errpage[1];
|
data = errpage[1];
|
||||||
} else {
|
} else {
|
||||||
var errpage = self.wtvshared.doErrorPage(400)
|
const errpage = self.wtvshared.doErrorPage(400)
|
||||||
headers = errpage[0];
|
headers = errpage[0];
|
||||||
var data = errpage[1];
|
data = errpage[1];
|
||||||
}
|
}
|
||||||
if (!headers && res.statusCode != 206) {
|
if (!headers && res.statusCode != 206) {
|
||||||
self.sendToClient(data, request_path, callback);
|
self.sendToClient(data, request_path, callback);
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ class WTVMail {
|
|||||||
|
|
||||||
constructor(minisrv_config, wtvclient) {
|
constructor(minisrv_config, wtvclient) {
|
||||||
if (!minisrv_config) throw ("minisrv_config required");
|
if (!minisrv_config) throw ("minisrv_config required");
|
||||||
var WTVShared = require("./WTVShared.js")['WTVShared'];
|
const WTVShared = require("./WTVShared.js")['WTVShared'];
|
||||||
var WTVMime = require("./WTVMime.js");
|
const WTVMime = require("./WTVMime.js");
|
||||||
this.WTVClientSessionData = require("./WTVClientSessionData.js");
|
this.WTVClientSessionData = require("./WTVClientSessionData.js");
|
||||||
this.minisrv_config = minisrv_config;
|
this.minisrv_config = minisrv_config;
|
||||||
this.wtvshared = new WTVShared(minisrv_config);
|
this.wtvshared = new WTVShared(minisrv_config);
|
||||||
@@ -39,7 +39,7 @@ class WTVMail {
|
|||||||
this.trashMailboxName
|
this.trashMailboxName
|
||||||
];
|
];
|
||||||
this.defaultColors = {
|
this.defaultColors = {
|
||||||
bgcolor: "#191919",
|
bgcolor: "#1F2033",
|
||||||
text: "#82A9D9",
|
text: "#82A9D9",
|
||||||
link: "#BDA73A",
|
link: "#BDA73A",
|
||||||
vlink: "#62B362"
|
vlink: "#62B362"
|
||||||
@@ -59,9 +59,9 @@ class WTVMail {
|
|||||||
if (!this.isguest) {
|
if (!this.isguest) {
|
||||||
if (this.mailstore_dir === null) {
|
if (this.mailstore_dir === null) {
|
||||||
// set mailstore directory local var so we don't call the function every time
|
// set mailstore directory local var so we don't call the function every time
|
||||||
var userstore_dir = this.wtvclient.getUserStoreDirectory();
|
const userstore_dir = this.wtvclient.getUserStoreDirectory();
|
||||||
// MailStore
|
// MailStore
|
||||||
var store_dir = "MailStore" + this.path.sep;
|
const store_dir = "MailStore" + this.path.sep;
|
||||||
this.mailstore_dir = userstore_dir + store_dir;
|
this.mailstore_dir = userstore_dir + store_dir;
|
||||||
}
|
}
|
||||||
return this.fs.existsSync(this.mailstore_dir);
|
return this.fs.existsSync(this.mailstore_dir);
|
||||||
@@ -70,7 +70,7 @@ class WTVMail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getSignatureColors(signature = null, sendmail = true) {
|
getSignatureColors(signature = null, sendmail = true) {
|
||||||
var colors = Object.assign({}, this.defaultColors); // start with default colors
|
const colors = Object.assign({}, this.defaultColors); // start with default colors
|
||||||
if (sendmail) colors.bgcolor = this.sendmailDefaultBGColor;
|
if (sendmail) colors.bgcolor = this.sendmailDefaultBGColor;
|
||||||
|
|
||||||
if (signature) {
|
if (signature) {
|
||||||
@@ -95,14 +95,13 @@ class WTVMail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mailboxExists(mailboxid) {
|
mailboxExists(mailboxid) {
|
||||||
|
let store_dir;
|
||||||
if (mailboxid >= this.mailboxes.length) return null;
|
if (mailboxid >= this.mailboxes.length) return null;
|
||||||
var mailbox_dir = null;
|
|
||||||
var store_dir = null;
|
|
||||||
if (this.mailstoreExists()) {
|
if (this.mailstoreExists()) {
|
||||||
var mailbox_name = this.getMailboxById(mailboxid);
|
const mailbox_name = this.getMailboxById(mailboxid);
|
||||||
if (!mailbox_name) return null;
|
if (!mailbox_name) return null;
|
||||||
|
|
||||||
mailbox_dir = mailbox_name + this.path.sep;
|
const mailbox_dir = mailbox_name + this.path.sep;
|
||||||
store_dir = this.mailstore_dir + mailbox_dir;
|
store_dir = this.mailstore_dir + mailbox_dir;
|
||||||
}
|
}
|
||||||
return (store_dir !== null) ? this.fs.existsSync(store_dir) : false;
|
return (store_dir !== null) ? this.fs.existsSync(store_dir) : false;
|
||||||
@@ -121,7 +120,7 @@ class WTVMail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getMailboxByName(mailbox_name) {
|
getMailboxByName(mailbox_name) {
|
||||||
var mailbox_id = false;
|
let mailbox_id = false;
|
||||||
this.mailboxes.every(function (v, k) {
|
this.mailboxes.every(function (v, k) {
|
||||||
if (v.toLowerCase() == mailbox_name.toLowerCase()) {
|
if (v.toLowerCase() == mailbox_name.toLowerCase()) {
|
||||||
mailbox_id = k;
|
mailbox_id = k;
|
||||||
@@ -134,18 +133,18 @@ class WTVMail {
|
|||||||
|
|
||||||
getMailboxStoreDir(mailboxid) {
|
getMailboxStoreDir(mailboxid) {
|
||||||
if (this.mailboxExists(mailboxid)) {
|
if (this.mailboxExists(mailboxid)) {
|
||||||
var mailbox_name = this.getMailboxById(mailboxid);
|
const mailbox_name = this.getMailboxById(mailboxid);
|
||||||
return this.mailstore_dir + mailbox_name + this.path.sep;
|
return this.mailstore_dir + mailbox_name + this.path.sep;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
createMailbox(mailboxid) {
|
createMailbox(mailboxid) {
|
||||||
var mailbox_exists = this.mailboxExists(mailboxid);
|
const mailbox_exists = this.mailboxExists(mailboxid);
|
||||||
if (mailbox_exists === false) {
|
if (mailbox_exists === false) {
|
||||||
var mailbox_name = this.getMailboxById(mailboxid);
|
const mailbox_name = this.getMailboxById(mailboxid);
|
||||||
var mailbox_dir = mailbox_name + this.path.sep;
|
const mailbox_dir = mailbox_name + this.path.sep;
|
||||||
var store_dir = this.mailstore_dir + mailbox_dir;
|
const store_dir = this.mailstore_dir + mailbox_dir;
|
||||||
if (!this.fs.existsSync(store_dir)) this.fs.mkdirSync(store_dir, { recursive: true });
|
if (!this.fs.existsSync(store_dir)) this.fs.mkdirSync(store_dir, { recursive: true });
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -160,11 +159,11 @@ class WTVMail {
|
|||||||
if (this.createMailbox(mailboxid)) {
|
if (this.createMailbox(mailboxid)) {
|
||||||
if (!date) date = Math.floor(Date.now() / 1000);
|
if (!date) date = Math.floor(Date.now() / 1000);
|
||||||
|
|
||||||
var mailbox_path = this.getMailboxStoreDir(mailboxid);
|
const mailbox_path = this.getMailboxStoreDir(mailboxid);
|
||||||
var message_id = this.createMessageID();
|
const message_id = this.createMessageID();
|
||||||
var message_file = message_id + this.msgFileExt;
|
const message_file = message_id + this.msgFileExt;
|
||||||
var message_file_out = mailbox_path + message_file;
|
const message_file_out = mailbox_path + message_file;
|
||||||
var message_data = {
|
const message_data = {
|
||||||
"from_addr": from_addr,
|
"from_addr": from_addr,
|
||||||
"from_name": from_name,
|
"from_name": from_name,
|
||||||
"to_addr": to_addr,
|
"to_addr": to_addr,
|
||||||
@@ -206,31 +205,31 @@ class WTVMail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createWelcomeMessage() {
|
createWelcomeMessage() {
|
||||||
var welcomeTemplate = this.wtvshared.getTemplate("wtv-mail", "welcomeMail.txt").toString('ascii');
|
const welcomeTemplate = this.wtvshared.getTemplate("wtv-mail", "welcomeMail.txt").toString('ascii');
|
||||||
var end_of_headers = false;
|
let end_of_headers = false;
|
||||||
var msg = "";
|
let msg = "";
|
||||||
var self = this;
|
const self = this;
|
||||||
var to_addr = this.wtvclient.getSessionData("subscriber_username") + "@" + this.minisrv_config.config.service_name;
|
const to_addr = this.wtvclient.getSessionData("subscriber_username") + "@" + this.minisrv_config.config.service_name;
|
||||||
var to_name = this.wtvclient.getSessionData("subscriber_name");
|
const to_name = this.wtvclient.getSessionData("subscriber_name");
|
||||||
var available_tags = {
|
const available_tags = {
|
||||||
...this.minisrv_config.config,
|
...this.minisrv_config.config,
|
||||||
"user_address": to_addr,
|
"user_address": to_addr,
|
||||||
"user_name": to_name
|
"user_name": to_name
|
||||||
}
|
}
|
||||||
var from_name, from_addr, subj = null;
|
let from_name, from_addr, subj = null;
|
||||||
var lines = welcomeTemplate.replace(/\r/g, '').split("\n");
|
const lines = welcomeTemplate.replace(/\r/g, '').split("\n");
|
||||||
lines.forEach((line) => {
|
lines.forEach((line) => {
|
||||||
if (line.indexOf(": ") > 1 && !end_of_headers) {
|
if (line.indexOf(": ") > 1 && !end_of_headers) {
|
||||||
var header = [line.slice(0, line.indexOf(':')), line.slice(line.indexOf(':') + 2).trim()];
|
const header = [line.slice(0, line.indexOf(':')), line.slice(line.indexOf(':') + 2).trim()];
|
||||||
switch (header[0].toLowerCase()) {
|
switch (header[0].toLowerCase()) {
|
||||||
case "from":
|
case "from":
|
||||||
if (header[1].indexOf("<") >= 0) {
|
if (header[1].indexOf("<") >= 0) {
|
||||||
var email = header[1].match(/(.+) \<(.+)\>/);
|
let email = header[1].match(/(.+) \<(.+)\>/);
|
||||||
if (email) {
|
if (email) {
|
||||||
from_name = email[1];
|
from_name = email[1];
|
||||||
from_addr = email[2];
|
from_addr = email[2];
|
||||||
} else {
|
} else {
|
||||||
var email = header[1].match(/\<(.+)\>/);
|
const email = header[1].match(/\<(.+)\>/);
|
||||||
from_addr = email[1];
|
from_addr = email[1];
|
||||||
}
|
}
|
||||||
} else if (header[1].indexOf('@') >= 0) {
|
} else if (header[1].indexOf('@') >= 0) {
|
||||||
@@ -245,8 +244,8 @@ class WTVMail {
|
|||||||
} else if (line == '') end_of_headers = true;
|
} else if (line == '') end_of_headers = true;
|
||||||
else {
|
else {
|
||||||
msg += line.replace(/\$\{(\w{1,})\}/g, function (x) {
|
msg += line.replace(/\$\{(\w{1,})\}/g, function (x) {
|
||||||
var out = '';
|
let out = '';
|
||||||
var tag = x.replace("${", '').replace('}', '');
|
const tag = x.replace("${", '').replace('}', '');
|
||||||
if (available_tags[tag]) out = available_tags[tag];
|
if (available_tags[tag]) out = available_tags[tag];
|
||||||
return out
|
return out
|
||||||
}) + "\n";
|
}) + "\n";
|
||||||
@@ -257,16 +256,16 @@ class WTVMail {
|
|||||||
|
|
||||||
getMessage(mailboxid, messageid) {
|
getMessage(mailboxid, messageid) {
|
||||||
if (this.createMailbox(mailboxid)) {
|
if (this.createMailbox(mailboxid)) {
|
||||||
var mailbox_path = this.getMailboxStoreDir(mailboxid);
|
const mailbox_path = this.getMailboxStoreDir(mailboxid);
|
||||||
var message_file = messageid + this.msgFileExt;
|
const message_file = messageid + this.msgFileExt;
|
||||||
var message_file_in = mailbox_path + this.path.sep + message_file;
|
const message_file_in = mailbox_path + this.path.sep + message_file;
|
||||||
var message_data_raw = null;
|
let message_data_raw = null;
|
||||||
|
|
||||||
if (this.fs.existsSync(message_file_in)) message_data_raw = this.fs.readFileSync(message_file_in);
|
if (this.fs.existsSync(message_file_in)) message_data_raw = this.fs.readFileSync(message_file_in);
|
||||||
else console.error(" # MailErr: could not find ", message_file_in);
|
else console.error(" # MailErr: could not find ", message_file_in);
|
||||||
|
|
||||||
if (message_data_raw) {
|
if (message_data_raw) {
|
||||||
var message_data = JSON.parse(message_data_raw);
|
const message_data = JSON.parse(message_data_raw);
|
||||||
message_data.mailbox_path = mailbox_path;
|
message_data.mailbox_path = mailbox_path;
|
||||||
message_data.message_file = message_file;
|
message_data.message_file = message_file;
|
||||||
if (message_data) {
|
if (message_data) {
|
||||||
@@ -284,15 +283,15 @@ class WTVMail {
|
|||||||
|
|
||||||
updateMessage(message_data) {
|
updateMessage(message_data) {
|
||||||
// encode message into json
|
// encode message into json
|
||||||
var message_out = new Object();
|
const message_out = {};
|
||||||
Object.assign(message_out, message_data);
|
Object.assign(message_out, message_data);
|
||||||
delete message_out.mailbox_path;
|
delete message_out.mailbox_path;
|
||||||
delete message_out.message_file;
|
delete message_out.message_file;
|
||||||
var result = this.fs.writeFileSync(message_data.mailbox_path + this.path.sep + message_data.message_file, JSON.stringify(message_out));
|
const result = this.fs.writeFileSync(message_data.mailbox_path + this.path.sep + message_data.message_file, JSON.stringify(message_out));
|
||||||
if (!result) return false;
|
if (!result) return false;
|
||||||
|
|
||||||
// rely on filesystem times for sorting as it is quicker then reading every file
|
// rely on filesystem times for sorting as it is quicker then reading every file
|
||||||
var file_timestamp = new Date(message_data.date * 1000);
|
const file_timestamp = new Date(message_data.date * 1000);
|
||||||
fs.utimesSync(message_file, Date.now(), file_timestamp);
|
fs.utimesSync(message_file, Date.now(), file_timestamp);
|
||||||
if (!result) console.error(" WARNING: Setting timestamp on " + message_file + " failed, mail dates will be inaccurate.");
|
if (!result) console.error(" WARNING: Setting timestamp on " + message_file + " failed, mail dates will be inaccurate.");
|
||||||
}
|
}
|
||||||
@@ -304,19 +303,19 @@ class WTVMail {
|
|||||||
|
|
||||||
listMessages(mailboxid, limit, reverse_sort = false, offset = 0) {
|
listMessages(mailboxid, limit, reverse_sort = false, offset = 0) {
|
||||||
if (this.createMailbox(mailboxid)) {
|
if (this.createMailbox(mailboxid)) {
|
||||||
var mailbox_path = this.getMailboxStoreDir(mailboxid);
|
const mailbox_path = this.getMailboxStoreDir(mailboxid);
|
||||||
var self = this;
|
const self = this;
|
||||||
var files = this.fs.readdirSync(mailbox_path)
|
const files = this.fs.readdirSync(mailbox_path)
|
||||||
.map(function (v) {
|
.map(function (v) {
|
||||||
var message_data_raw = null;
|
let message_data_raw = null;
|
||||||
var message_date = null;
|
let message_date = null;
|
||||||
var message_path = mailbox_path + self.path.sep + v;
|
const message_path = mailbox_path + self.path.sep + v;
|
||||||
if (self.fs.existsSync(message_path)) message_data_raw = self.fs.readFileSync(message_path);
|
if (self.fs.existsSync(message_path)) message_data_raw = self.fs.readFileSync(message_path);
|
||||||
if (message_data_raw) {
|
if (message_data_raw) {
|
||||||
var message_data = JSON.parse(message_data_raw);
|
const message_data = JSON.parse(message_data_raw);
|
||||||
if (message_data) message_date = message_data.date;
|
if (message_data) message_date = message_data.date;
|
||||||
}
|
}
|
||||||
var message_date_ret = (message_date) ? message_date : self.fs.statSync(mailbox_path + self.path.sep + v).mtime.getTime();
|
const message_date_ret = (message_date) ? message_date : self.fs.statSync(mailbox_path + self.path.sep + v).mtime.getTime();
|
||||||
self.fs.statSync(mailbox_path + self.path.sep + v).mtime.getTime()
|
self.fs.statSync(mailbox_path + self.path.sep + v).mtime.getTime()
|
||||||
return {
|
return {
|
||||||
name: v,
|
name: v,
|
||||||
@@ -334,9 +333,9 @@ class WTVMail {
|
|||||||
if (files.length == 0) return false; // no messages
|
if (files.length == 0) return false; // no messages
|
||||||
else {
|
else {
|
||||||
// todo filter previous results when offset
|
// todo filter previous results when offset
|
||||||
var messagelist_out = new Array();
|
const messagelist_out = new Array();
|
||||||
Object.keys(files).forEach(function (k) {
|
Object.keys(files).forEach(function (k) {
|
||||||
var message = self.getMessage(mailboxid, files[k]);
|
const message = self.getMessage(mailboxid, files[k]);
|
||||||
if (message) messagelist_out.push(mailboxid, message);
|
if (message) messagelist_out.push(mailboxid, message);
|
||||||
else console.error(" # MailErr: reading message ID: ", files[k]);
|
else console.error(" # MailErr: reading message ID: ", files[k]);
|
||||||
})
|
})
|
||||||
@@ -347,14 +346,14 @@ class WTVMail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
countMessages(mailboxid) {
|
countMessages(mailboxid) {
|
||||||
var messages = this.listMessages(mailboxid, 100, false);
|
const messages = this.listMessages(mailboxid, 100, false);
|
||||||
var message_count = Object.keys(messages).length;
|
const message_count = Object.keys(messages).length;
|
||||||
return (message_count) ? message_count : 0;
|
return (message_count) ? message_count : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
countUnreadMessages(mailboxid) {
|
countUnreadMessages(mailboxid) {
|
||||||
var messages = this.listMessages(mailboxid, 100, false);
|
const messages = this.listMessages(mailboxid, 100, false);
|
||||||
var unread = 0;
|
let unread = 0;
|
||||||
Object.keys(messages).forEach(function (k) {
|
Object.keys(messages).forEach(function (k) {
|
||||||
if (messages[k].unread) unread++;
|
if (messages[k].unread) unread++;
|
||||||
});
|
});
|
||||||
@@ -362,7 +361,7 @@ class WTVMail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getMailboxIcon() {
|
getMailboxIcon() {
|
||||||
var icon_image = null;
|
let icon_image = null;
|
||||||
switch (this.countMessages(0)) {
|
switch (this.countMessages(0)) {
|
||||||
case 0:
|
case 0:
|
||||||
icon_image = "OpenMailbox0.gif";
|
icon_image = "OpenMailbox0.gif";
|
||||||
@@ -379,9 +378,9 @@ class WTVMail {
|
|||||||
|
|
||||||
checkUserExists(username, directory = null) {
|
checkUserExists(username, directory = null) {
|
||||||
// returns the user's ssid, and user_id and userid in an array if true, false if not
|
// returns the user's ssid, and user_id and userid in an array if true, false if not
|
||||||
var search_dir = this.wtvshared.getAbsolutePath(this.minisrv_config.config.SessionStore + this.path.sep + "accounts");
|
let search_dir = this.wtvshared.getAbsolutePath(this.minisrv_config.config.SessionStore + this.path.sep + "accounts");
|
||||||
var return_val = false;
|
let return_val = false;
|
||||||
var self = this;
|
const self = this;
|
||||||
if (directory) search_dir = directory;
|
if (directory) search_dir = directory;
|
||||||
this.fs.readdirSync(search_dir).forEach(file => {
|
this.fs.readdirSync(search_dir).forEach(file => {
|
||||||
if (self.fs.lstatSync(search_dir + self.path.sep + file).isDirectory() && !return_val) {
|
if (self.fs.lstatSync(search_dir + self.path.sep + file).isDirectory() && !return_val) {
|
||||||
@@ -389,22 +388,22 @@ class WTVMail {
|
|||||||
}
|
}
|
||||||
if (!file.match(/.*\.json/ig)) return;
|
if (!file.match(/.*\.json/ig)) return;
|
||||||
try {
|
try {
|
||||||
var temp_session_data_file = self.fs.readFileSync(search_dir + self.path.sep + file, 'Utf8');
|
const temp_session_data_file = self.fs.readFileSync(search_dir + self.path.sep + file, 'Utf8');
|
||||||
var temp_session_data = JSON.parse(temp_session_data_file);
|
const temp_session_data = JSON.parse(temp_session_data_file);
|
||||||
if (temp_session_data.subscriber_username) {
|
if (temp_session_data.subscriber_username) {
|
||||||
if (temp_session_data.subscriber_username.toLowerCase() == username.toLowerCase()) {
|
if (temp_session_data.subscriber_username.toLowerCase() == username.toLowerCase()) {
|
||||||
// Use the absolute path for replacement since search_dir is now absolute
|
// Use the absolute path for replacement since search_dir is now absolute
|
||||||
var accounts_dir = self.wtvshared.getAbsolutePath(self.minisrv_config.config.SessionStore + self.path.sep + "accounts" + self.path.sep);
|
const accounts_dir = self.wtvshared.getAbsolutePath(self.minisrv_config.config.SessionStore + self.path.sep + "accounts" + self.path.sep);
|
||||||
var path_after_replace = search_dir.replace(accounts_dir, '');
|
let path_after_replace = search_dir.replace(accounts_dir, '');
|
||||||
// Remove leading path separator if present
|
// Remove leading path separator if present
|
||||||
if (path_after_replace.startsWith(self.path.sep)) {
|
if (path_after_replace.startsWith(self.path.sep)) {
|
||||||
path_after_replace = path_after_replace.slice(1);
|
path_after_replace = path_after_replace.slice(1);
|
||||||
}
|
}
|
||||||
var path_split = path_after_replace.split(self.path.sep);
|
const path_split = path_after_replace.split(self.path.sep);
|
||||||
// The path should be like "ssid/user0", so extract ssid and user_id
|
// The path should be like "ssid/user0", so extract ssid and user_id
|
||||||
var ssid = path_split[0];
|
const ssid = path_split[0];
|
||||||
var user_part = path_split[1] || '';
|
const user_part = path_split[1] || '';
|
||||||
var user_id = user_part.replace('user', '');
|
const user_id = user_part.replace('user', '');
|
||||||
return_val = [ssid, user_id, temp_session_data.subscriber_name];
|
return_val = [ssid, user_id, temp_session_data.subscriber_name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -416,11 +415,11 @@ class WTVMail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getUserMailstore(username) {
|
getUserMailstore(username) {
|
||||||
var user_data = this.checkUserExists(username);
|
const user_data = this.checkUserExists(username);
|
||||||
if (user_data) {
|
if (user_data) {
|
||||||
var user_wtvsession = new this.WTVClientSessionData(this.minisrv_config, user_data[0]);
|
const user_wtvsession = new this.WTVClientSessionData(this.minisrv_config, user_data[0]);
|
||||||
user_wtvsession.user_id = user_data[1];
|
user_wtvsession.user_id = user_data[1];
|
||||||
var user_mailstore = new WTVMail(this.minisrv_config, user_wtvsession)
|
const user_mailstore = new WTVMail(this.minisrv_config, user_wtvsession)
|
||||||
return user_mailstore;
|
return user_mailstore;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -431,8 +430,8 @@ class WTVMail {
|
|||||||
|
|
||||||
|
|
||||||
if (to_addr.indexOf('@') === -1) to_addr += "@"+this.minisrv_config.config.service_name;
|
if (to_addr.indexOf('@') === -1) to_addr += "@"+this.minisrv_config.config.service_name;
|
||||||
var username = to_addr.split("@")[0];
|
const username = to_addr.split("@")[0];
|
||||||
var dest_minisrv = to_addr.split("@")[1] || this.minisrv_config.config.service_name;
|
const dest_minisrv = to_addr.split("@")[1] || this.minisrv_config.config.service_name;
|
||||||
|
|
||||||
// local only for now
|
// local only for now
|
||||||
if (dest_minisrv.toLowerCase() !== this.minisrv_config.config.service_name.toLowerCase()) {
|
if (dest_minisrv.toLowerCase() !== this.minisrv_config.config.service_name.toLowerCase()) {
|
||||||
@@ -441,25 +440,25 @@ class WTVMail {
|
|||||||
|
|
||||||
// find user if local
|
// find user if local
|
||||||
if (dest_minisrv.toLowerCase() === this.minisrv_config.config.service_name.toLowerCase()) {
|
if (dest_minisrv.toLowerCase() === this.minisrv_config.config.service_name.toLowerCase()) {
|
||||||
var dest_user_mailstore = this.getUserMailstore(username);
|
const dest_user_mailstore = this.getUserMailstore(username);
|
||||||
// user does not exist
|
// user does not exist
|
||||||
if (!dest_user_mailstore) return "The user <strong>" + username + "</strong> does not exist on MiniSrv <strong>" + dest_minisrv + "</strong>";
|
if (!dest_user_mailstore) return "The user <strong>" + username + "</strong> does not exist on MiniSrv <strong>" + dest_minisrv + "</strong>";
|
||||||
|
|
||||||
if (!to_name) {
|
if (!to_name) {
|
||||||
var userExistsData = this.checkUserExists(username);
|
const userExistsData = this.checkUserExists(username);
|
||||||
to_name = userExistsData[2];
|
to_name = userExistsData[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the destination user's Inbox exists yet
|
// check if the destination user's Inbox exists yet
|
||||||
if (!dest_user_mailstore.mailboxExists(0)) {
|
if (!dest_user_mailstore.mailboxExists(0)) {
|
||||||
// mailbox does not yet exist, create it
|
// mailbox does not yet exist, create it
|
||||||
var mailbox_exists = dest_user_mailstore.createMailbox(0);
|
const mailbox_exists = dest_user_mailstore.createMailbox(0);
|
||||||
// Just created Inbox for the first time, so create the welcome message
|
// Just created Inbox for the first time, so create the welcome message
|
||||||
if (mailbox_exists) dest_user_mailstore.createWelcomeMessage();
|
if (mailbox_exists) dest_user_mailstore.createWelcomeMessage();
|
||||||
}
|
}
|
||||||
// if the mailbox exists, deliver the message
|
// if the mailbox exists, deliver the message
|
||||||
if (dest_user_mailstore.mailboxExists(0)) {
|
if (dest_user_mailstore.mailboxExists(0)) {
|
||||||
var createResult = dest_user_mailstore.createMessage(0, from_addr, to_addr, msgbody, subject, from_name, to_name, signature, null, this.isInUserAddressBook(to_addr, from_addr), attachments, url, url_title);
|
const createResult = dest_user_mailstore.createMessage(0, from_addr, to_addr, msgbody, subject, from_name, to_name, signature, null, this.isInUserAddressBook(to_addr, from_addr), attachments, url, url_title);
|
||||||
if (!createResult) {
|
if (!createResult) {
|
||||||
return "There was an error creating the message in the recipient's mailbox.";
|
return "There was an error creating the message in the recipient's mailbox.";
|
||||||
}
|
}
|
||||||
@@ -467,7 +466,6 @@ class WTVMail {
|
|||||||
else return "There was an internal error sending the message to <strong>" + to_addr + "</strong>. Please try again later";
|
else return "There was an internal error sending the message to <strong>" + to_addr + "</strong>. Please try again later";
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
dest_user_mailstore = null;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return "Unknown error";
|
return "Unknown error";
|
||||||
@@ -480,8 +478,8 @@ class WTVMail {
|
|||||||
|
|
||||||
getMessageMailboxName(messageid) {
|
getMessageMailboxName(messageid) {
|
||||||
// returns the mailbox id of which the message was found for the current user
|
// returns the mailbox id of which the message was found for the current user
|
||||||
var self = this;
|
const self = this;
|
||||||
var mailbox_name = false;
|
let mailbox_name = false;
|
||||||
if (this.checkMessageIdSanity(messageid)) {
|
if (this.checkMessageIdSanity(messageid)) {
|
||||||
if (this.mailstoreExists()) {
|
if (this.mailstoreExists()) {
|
||||||
this.fs.readdirSync(this.mailstore_dir).every(mailbox => {
|
this.fs.readdirSync(this.mailstore_dir).every(mailbox => {
|
||||||
@@ -501,16 +499,16 @@ class WTVMail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getMessageMailboxID(messageid) {
|
getMessageMailboxID(messageid) {
|
||||||
var mailbox_name = this.getMessageMailboxName(messageid);
|
const mailbox_name = this.getMessageMailboxName(messageid);
|
||||||
if (!mailbox_name) return false;
|
if (!mailbox_name) return false;
|
||||||
return this.getMailboxByName(mailbox_name);
|
return this.getMailboxByName(mailbox_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
getMessageByID(messageid) {
|
getMessageByID(messageid) {
|
||||||
var mailbox_name = this.getMessageMailboxName(messageid);
|
const mailbox_name = this.getMessageMailboxName(messageid);
|
||||||
if (!mailbox_name) return false;
|
if (!mailbox_name) return false;
|
||||||
|
|
||||||
var mailboxid = this.mailboxes.findIndex((value) => value == mailbox_name);
|
const mailboxid = this.mailboxes.findIndex((value) => value == mailbox_name);
|
||||||
|
|
||||||
if (mailboxid !== false) return this.getMessage(mailboxid, messageid);
|
if (mailboxid !== false) return this.getMessage(mailboxid, messageid);
|
||||||
return null;
|
return null;
|
||||||
@@ -518,7 +516,7 @@ class WTVMail {
|
|||||||
|
|
||||||
moveMailMessage(messageid, dest_mailbox_id) {
|
moveMailMessage(messageid, dest_mailbox_id) {
|
||||||
// returns true if successful, false if failed.
|
// returns true if successful, false if failed.
|
||||||
var currentMailbox = this.getMessageMailboxID(messageid);
|
const currentMailbox = this.getMessageMailboxID(messageid);
|
||||||
// Same mailbox
|
// Same mailbox
|
||||||
if (dest_mailbox_id == currentMailbox) return false;
|
if (dest_mailbox_id == currentMailbox) return false;
|
||||||
|
|
||||||
@@ -527,14 +525,14 @@ class WTVMail {
|
|||||||
|
|
||||||
if (!this.mailboxExists(dest_mailbox_id)) this.createMailbox(dest_mailbox_id);
|
if (!this.mailboxExists(dest_mailbox_id)) this.createMailbox(dest_mailbox_id);
|
||||||
|
|
||||||
var currentMailStoreDir = this.getMailboxStoreDir(currentMailbox);
|
const currentMailStoreDir = this.getMailboxStoreDir(currentMailbox);
|
||||||
if (!currentMailStoreDir) return false;
|
if (!currentMailStoreDir) return false;
|
||||||
|
|
||||||
var destMailStoreDir = this.getMailboxStoreDir(dest_mailbox_id);
|
const destMailStoreDir = this.getMailboxStoreDir(dest_mailbox_id);
|
||||||
if (!destMailStoreDir) return false;
|
if (!destMailStoreDir) return false;
|
||||||
|
|
||||||
var currentMailFile = currentMailStoreDir + this.path.sep + messageid + this.msgFileExt;
|
const currentMailFile = currentMailStoreDir + this.path.sep + messageid + this.msgFileExt;
|
||||||
var destMailFile = destMailStoreDir + this.path.sep + messageid + this.msgFileExt;
|
const destMailFile = destMailStoreDir + this.path.sep + messageid + this.msgFileExt;
|
||||||
|
|
||||||
// File exists
|
// File exists
|
||||||
if (this.fs.existsSync(destMailFile)) return false;
|
if (this.fs.existsSync(destMailFile)) return false;
|
||||||
@@ -543,14 +541,14 @@ class WTVMail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
deleteMessage(messageid) {
|
deleteMessage(messageid) {
|
||||||
var currentMailbox = this.getMessageMailboxName(messageid);
|
const currentMailbox = this.getMessageMailboxName(messageid);
|
||||||
var trashMailbox = this.getMailboxByName(this.trashMailboxName);
|
const trashMailbox = this.getMailboxByName(this.trashMailboxName);
|
||||||
if (currentMailbox != trashMailbox) {
|
if (currentMailbox != trashMailbox) {
|
||||||
// if not in the trash, move it to trash
|
// if not in the trash, move it to trash
|
||||||
return this.moveMailMessage(messageid, trashMailbox);
|
return this.moveMailMessage(messageid, trashMailbox);
|
||||||
} else {
|
} else {
|
||||||
// if its already in the trash, delete it forever
|
// if its already in the trash, delete it forever
|
||||||
var currentMailFile = this.getMailboxStoreDir(trashMailbox) + this.path.sep + messageid + this.msgFileExt;
|
const currentMailFile = this.getMailboxStoreDir(trashMailbox) + this.path.sep + messageid + this.msgFileExt;
|
||||||
if (this.fs.fileExistsSync(currentMailFile))
|
if (this.fs.fileExistsSync(currentMailFile))
|
||||||
return this.fs.unlink(currentMailFile);
|
return this.fs.unlink(currentMailFile);
|
||||||
else
|
else
|
||||||
@@ -559,7 +557,7 @@ class WTVMail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setMessageReadStatus(messageid, read = true) {
|
setMessageReadStatus(messageid, read = true) {
|
||||||
var message = this.getMessageByID(messageid);
|
const message = this.getMessageByID(messageid);
|
||||||
if (!message) return false;
|
if (!message) return false;
|
||||||
|
|
||||||
message.unread = !read;
|
message.unread = !read;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class WTVNews {
|
|||||||
|
|
||||||
initializeUsenet(host, port = 119, tls_options = null, username = null, password = null) {
|
initializeUsenet(host, port = 119, tls_options = null, username = null, password = null) {
|
||||||
// use local self-signed cert for local server
|
// use local self-signed cert for local server
|
||||||
var newsie_options = {
|
const newsie_options = {
|
||||||
host: host,
|
host: host,
|
||||||
port: port,
|
port: port,
|
||||||
tlsPort: (tls_options !== null) ? true : false,
|
tlsPort: (tls_options !== null) ? true : false,
|
||||||
@@ -69,10 +69,11 @@ class WTVNews {
|
|||||||
|
|
||||||
listGroup(group, page = 0, limit = 100, raw_range = null) {
|
listGroup(group, page = 0, limit = 100, raw_range = null) {
|
||||||
// list of articles from group
|
// list of articles from group
|
||||||
|
let range = {};
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.selectGroup(group).then((res) => {
|
this.selectGroup(group).then((res) => {
|
||||||
if (!raw_range) {
|
if (!raw_range) {
|
||||||
var range = {
|
range = {
|
||||||
start: (limit * page) + res.group.low,
|
start: (limit * page) + res.group.low,
|
||||||
}
|
}
|
||||||
range.end = range.start + limit;
|
range.end = range.start + limit;
|
||||||
@@ -133,9 +134,9 @@ class WTVNews {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getArticle(articleID, get_next_last = true) {
|
getArticle(articleID, get_next_last = true) {
|
||||||
var articleID = parseInt(articleID);
|
articleID = parseInt(articleID);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var promises = [];
|
const promises = [];
|
||||||
this.client.article(articleID).then((data) => {
|
this.client.article(articleID).then((data) => {
|
||||||
if (get_next_last) {
|
if (get_next_last) {
|
||||||
// ask server for next article
|
// ask server for next article
|
||||||
@@ -177,14 +178,14 @@ class WTVNews {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
Promise.all(promises).then(() => {
|
Promise.all(promises).then(() => {
|
||||||
var self = this;
|
const self = this;
|
||||||
if (data.article.headers) Object.keys(data.article.headers).forEach((k) => {
|
if (data.article.headers) Object.keys(data.article.headers).forEach((k) => {
|
||||||
data.article.headers[k] = self.decodeCharset(data.article.headers[k])
|
data.article.headers[k] = self.decodeCharset(data.article.headers[k])
|
||||||
});
|
});
|
||||||
resolve(data);
|
resolve(data);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var self = this;
|
const self = this;
|
||||||
if (data.article.headers) Object.keys(data.article.headers).forEach((k) => {
|
if (data.article.headers) Object.keys(data.article.headers).forEach((k) => {
|
||||||
data.article.headers[k] = self.decodeCharset(data.article.headers[k])
|
data.article.headers[k] = self.decodeCharset(data.article.headers[k])
|
||||||
});
|
});
|
||||||
@@ -198,17 +199,17 @@ class WTVNews {
|
|||||||
}
|
}
|
||||||
|
|
||||||
decodeCharset(string) {
|
decodeCharset(string) {
|
||||||
var regex = /=\?{1}(.+)\?{1}([B|Q])\?{1}(.+)\?{1}=/;
|
const regex = /=\?{1}(.+)\?{1}([B|Q])\?{1}(.+)\?{1}=/;
|
||||||
var decoded = null;
|
let decoded = null;
|
||||||
var check = string.match(regex);
|
const check = string.match(regex);
|
||||||
if (check) {
|
if (check) {
|
||||||
var match = check[0];
|
const match = check[0];
|
||||||
var charset = check[1];
|
const charset = check[1];
|
||||||
var encoding = check[2];
|
const encoding = check[2];
|
||||||
var encoded_text = check[3];
|
const encoded_text = check[3];
|
||||||
switch (encoding) {
|
switch (encoding) {
|
||||||
case "B":
|
case "B":
|
||||||
var buffer = new Buffer.from(encoded_text, 'base64')
|
const buffer = new Buffer.from(encoded_text, 'base64')
|
||||||
decoded = buffer.toString(charset).replace(/[^\x00-\x7F]/g, "");;
|
decoded = buffer.toString(charset).replace(/[^\x00-\x7F]/g, "");;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -224,7 +225,7 @@ class WTVNews {
|
|||||||
getHeader(articleID) {
|
getHeader(articleID) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.client.head(articleID).then((data) => {
|
this.client.head(articleID).then((data) => {
|
||||||
var self = this;
|
const self = this;
|
||||||
if (data.article.headers) Object.keys(data.article.headers).forEach((k) => {
|
if (data.article.headers) Object.keys(data.article.headers).forEach((k) => {
|
||||||
data.article.headers[k] = self.decodeCharset(data.article.headers[k])
|
data.article.headers[k] = self.decodeCharset(data.article.headers[k])
|
||||||
});
|
});
|
||||||
@@ -237,7 +238,7 @@ class WTVNews {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getHeaderFromMessage(message, header) {
|
getHeaderFromMessage(message, header) {
|
||||||
var response = null;
|
const response = null;
|
||||||
if (message.article.headers) {
|
if (message.article.headers) {
|
||||||
Object.keys(message.article.headers).forEach((k) => {
|
Object.keys(message.article.headers).forEach((k) => {
|
||||||
if (k.toLowerCase() == header.toLowerCase()) {
|
if (k.toLowerCase() == header.toLowerCase()) {
|
||||||
@@ -266,8 +267,8 @@ class WTVNews {
|
|||||||
|
|
||||||
postToGroup(group, from_addr, msg_subject, msg_body, article = null, headers = null) {
|
postToGroup(group, from_addr, msg_subject, msg_body, article = null, headers = null) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var promises = [];
|
const promises = [];
|
||||||
var messageid = null;
|
let messageid = null;
|
||||||
this.connectUsenet()
|
this.connectUsenet()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (article) {
|
if (article) {
|
||||||
@@ -352,9 +353,9 @@ class WTVNews {
|
|||||||
|
|
||||||
getHeaderObj(NGArticles) {
|
getHeaderObj(NGArticles) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var messages = [];
|
const messages = [];
|
||||||
var promises = [];
|
const promises = [];
|
||||||
for (var article in NGArticles) {
|
for (const article in NGArticles) {
|
||||||
if (article == "getCaseInsensitiveKey" || isNaN(article)) continue;
|
if (article == "getCaseInsensitiveKey" || isNaN(article)) continue;
|
||||||
promises.push(new Promise((resolve, reject) => {
|
promises.push(new Promise((resolve, reject) => {
|
||||||
this.getHeader(NGArticles[article]).then((data) => {
|
this.getHeader(NGArticles[article]).then((data) => {
|
||||||
@@ -379,26 +380,26 @@ class WTVNews {
|
|||||||
|
|
||||||
|
|
||||||
parseAttachments(message) {
|
parseAttachments(message) {
|
||||||
var contype = this.getHeaderFromMessage(message, 'Content-Type');
|
const contype = this.getHeaderFromMessage(message, 'Content-Type');
|
||||||
if (contype) {
|
if (contype) {
|
||||||
var regex = /multipart\/mixed\; boundary=\"(.+)\"/i;
|
const regex = /multipart\/mixed\; boundary=\"(.+)\"/i;
|
||||||
var match = contype.match(regex);
|
const match = contype.match(regex);
|
||||||
if (match) {
|
if (match) {
|
||||||
var boundary = "--" + match[1];
|
const boundary = "--" + match[1];
|
||||||
var body = message.article.body.join("\n").split(boundary);
|
const body = message.article.body.join("\n").split(boundary);
|
||||||
var attachments = [];
|
const attachments = [];
|
||||||
var i = 0;
|
let i = 0;
|
||||||
var message_body = '';
|
let message_body = '';
|
||||||
var message_type = 'text/plain';
|
let message_type = 'text/plain';
|
||||||
body.forEach((element) => {
|
body.forEach((element) => {
|
||||||
var section_type = null;
|
let section_type = null;
|
||||||
var section = element.split("\n");
|
let section = element.split("\n");
|
||||||
attachments[i] = {};
|
attachments[i] = {};
|
||||||
section.forEach((line) => {
|
section.forEach((line) => {
|
||||||
this.debug('section_type', section_type, 'line', line);
|
this.debug('section_type', section_type, 'line', line);
|
||||||
var section_header_match = line.match(/^Content\-/i)
|
const section_header_match = line.match(/^Content\-/i)
|
||||||
if (section_header_match) {
|
if (section_header_match) {
|
||||||
var section_match = line.match(/^Content\-Type\: (.+)\;/i)
|
const section_match = line.match(/^Content\-Type\: (.+)\;/i)
|
||||||
if (section_match) {
|
if (section_match) {
|
||||||
this.debug('section_match', section_match)
|
this.debug('section_match', section_match)
|
||||||
section_type = section_match[1];
|
section_type = section_match[1];
|
||||||
@@ -436,13 +437,13 @@ class WTVNews {
|
|||||||
attachments: attachments
|
attachments: attachments
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var message_body = '';
|
let message_body = '';
|
||||||
if (message.article.body) message_body = message.article.body.join("\n")
|
if (message.article.body) message_body = message.article.body.join("\n")
|
||||||
|
|
||||||
return { text: message_body }
|
return { text: message_body }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var message_body = '';
|
let message_body = '';
|
||||||
if (message.article.body) message_body = message.article.body.join("\n")
|
if (message.article.body) message_body = message.article.body.join("\n")
|
||||||
|
|
||||||
return { text: message_body }
|
return { text: message_body }
|
||||||
@@ -451,21 +452,21 @@ class WTVNews {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sortByResponse(messages) {
|
sortByResponse(messages) {
|
||||||
var sorted = [];
|
const sorted = [];
|
||||||
var message_id_roots = [];
|
const message_id_roots = [];
|
||||||
var message_relations = [];
|
const message_relations = [];
|
||||||
Object.keys(messages).forEach((k) => {
|
Object.keys(messages).forEach((k) => {
|
||||||
var messageId = messages[k].messageId;
|
const messageId = messages[k].messageId;
|
||||||
var ref = messages[k].headers.REFERENCES;
|
const ref = messages[k].headers.REFERENCES;
|
||||||
if (ref) {
|
if (ref) {
|
||||||
var res = message_id_roots.find(e => e.messageId == ref);
|
const res = message_id_roots.find(e => e.messageId == ref);
|
||||||
if (res) {
|
if (res) {
|
||||||
// see if its attached to a root post
|
// see if its attached to a root post
|
||||||
if (message_relations[res.messageId]) message_relations[res.messageId].push({ "messageId": messageId, "index": k });
|
if (message_relations[res.messageId]) message_relations[res.messageId].push({ "messageId": messageId, "index": k });
|
||||||
else message_relations[res.messageId] = [{ "messageId": messageId, "index": k }];
|
else message_relations[res.messageId] = [{ "messageId": messageId, "index": k }];
|
||||||
} else {
|
} else {
|
||||||
// see if its related to a relation
|
// see if its related to a relation
|
||||||
var found = false;
|
let found = false;
|
||||||
if (Object.keys(message_relations).length > 0) {
|
if (Object.keys(message_relations).length > 0) {
|
||||||
Object.keys(message_relations).forEach((j) => {
|
Object.keys(message_relations).forEach((j) => {
|
||||||
if (found) return;
|
if (found) return;
|
||||||
@@ -494,7 +495,7 @@ class WTVNews {
|
|||||||
|
|
||||||
// If not found in relations, add as root (but check for duplicates first)
|
// If not found in relations, add as root (but check for duplicates first)
|
||||||
if (!found) {
|
if (!found) {
|
||||||
var existingRoot = message_id_roots.find(e => e.messageId == messageId);
|
const existingRoot = message_id_roots.find(e => e.messageId == messageId);
|
||||||
if (!existingRoot) {
|
if (!existingRoot) {
|
||||||
message_id_roots.push({ "messageId": messageId, "index": k });
|
message_id_roots.push({ "messageId": messageId, "index": k });
|
||||||
}
|
}
|
||||||
@@ -503,7 +504,7 @@ class WTVNews {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Check for duplicates before adding as root
|
// Check for duplicates before adding as root
|
||||||
var existingRoot = message_id_roots.find(e => e.messageId == messageId);
|
const existingRoot = message_id_roots.find(e => e.messageId == messageId);
|
||||||
if (!existingRoot) {
|
if (!existingRoot) {
|
||||||
message_id_roots.push({ "messageId": messageId, "index": k });
|
message_id_roots.push({ "messageId": messageId, "index": k });
|
||||||
}
|
}
|
||||||
@@ -511,11 +512,11 @@ class WTVNews {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// sort the relations, putting root articles first, followed by their relations
|
// sort the relations, putting root articles first, followed by their relations
|
||||||
var message_roots_sorted = [];
|
const message_roots_sorted = [];
|
||||||
Object.keys(message_id_roots).forEach((k) => {
|
Object.keys(message_id_roots).forEach((k) => {
|
||||||
// sort relations by date
|
// sort relations by date
|
||||||
var article = messages[message_id_roots[k].index];
|
const article = messages[message_id_roots[k].index];
|
||||||
var article_date = Date.parse(article.headers.DATE);
|
const article_date = Date.parse(article.headers.DATE);
|
||||||
message_roots_sorted.push({ "article": article, "relation": null, "date": article_date });
|
message_roots_sorted.push({ "article": article, "relation": null, "date": article_date });
|
||||||
});
|
});
|
||||||
// Sort root articles newest to oldest
|
// Sort root articles newest to oldest
|
||||||
@@ -524,13 +525,13 @@ class WTVNews {
|
|||||||
sorted.push(message_roots_sorted[k]);
|
sorted.push(message_roots_sorted[k]);
|
||||||
|
|
||||||
// Use the correct messageId from the sorted root article
|
// Use the correct messageId from the sorted root article
|
||||||
var rootMessageId = message_roots_sorted[k].article.messageId;
|
const rootMessageId = message_roots_sorted[k].article.messageId;
|
||||||
if (message_relations[rootMessageId]) {
|
if (message_relations[rootMessageId]) {
|
||||||
var relations = [];
|
const relations = [];
|
||||||
Object.keys(message_relations[rootMessageId]).forEach((j) => {
|
Object.keys(message_relations[rootMessageId]).forEach((j) => {
|
||||||
// sort relations by date
|
// sort relations by date
|
||||||
var article = messages[message_relations[rootMessageId][j].index];
|
const article = messages[message_relations[rootMessageId][j].index];
|
||||||
var article_date = Date.parse(article.headers.DATE);
|
const article_date = Date.parse(article.headers.DATE);
|
||||||
relations.push({ "article": article, "relation": rootMessageId || null, "date": article_date })
|
relations.push({ "article": article, "relation": rootMessageId || null, "date": article_date })
|
||||||
});
|
});
|
||||||
relations.sort((a, b) => { return (a.date - b.date) });
|
relations.sort((a, b) => { return (a.date - b.date) });
|
||||||
|
|||||||
@@ -1074,7 +1074,7 @@ class WTVTellyScript {
|
|||||||
* It handles directives like #ifdef, #ifndef, #if, #else, #endif.
|
* It handles directives like #ifdef, #ifndef, #if, #else, #endif.
|
||||||
*/
|
*/
|
||||||
preprocess() {
|
preprocess() {
|
||||||
var definitions = this.preprocessor_definitions || {};
|
const definitions = this.preprocessor_definitions || {};
|
||||||
// Split input into lines (handling CRLF and LF)
|
// Split input into lines (handling CRLF and LF)
|
||||||
const lines = this.raw_data.split(/\r?\n/);
|
const lines = this.raw_data.split(/\r?\n/);
|
||||||
const output = [];
|
const output = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user