v0.9.33
- numerous bug fixes - wtv-mail system - user account updates - viewergen alpha (experimental webtv viewer patcher on pc_service) - implement wtv-favorites with huge help from @JarHead4 - add wtv-ticket store api - Bump vm2 from 3.9.5 to 3.9.7 in /zefie_wtvp_minisrv - fix bf0app default rom - Add wtv-1800 service to wtv-1800:/noflash - handle webtvism: - allow get/post variables to be the same name multiple times - rather than overwrite, the server will now change the variable from a string to an array. - Rewrite script processing a bit - Instead of using eval() we now use a proper VM Context - As a result, any scripting errors will now give a more useful filename and line number. - However, some things may break, if they are dependant on variables we are not allowing in the context. - BREAKING CHANGES: - `ssid_sessions[socket.ssid]` is now `session_data` - `require` is no longer allowed in user scripts - add star service - change how we handle modules for services in the VM - fixed wtv-disk:/sync always failed the first time - implement production-like wtv-star handling (when a service port becomes unavailable, it requests the url over the wtv-star port to show an error page) - renamed WTVDownloadList.js to WTVDisk.js - a bit more work on WTVNews (created class) - probably more stuff I can't remember
This commit is contained in:
110
zefie_wtvp_minisrv/includes/WTVNews.js
Normal file
110
zefie_wtvp_minisrv/includes/WTVNews.js
Normal file
@@ -0,0 +1,110 @@
|
||||
class WTVNews {
|
||||
|
||||
minisrv_config = null;
|
||||
newsie = require('newsie').default;
|
||||
service_name = null;
|
||||
client = null;
|
||||
|
||||
constructor(minisrv_config, service_name) {
|
||||
this.minisrv_config = minisrv_config;
|
||||
this.service_name = service_name;
|
||||
this.client = new this.newsie({
|
||||
host: this.minisrv_config.services[service_name].upstream_address,
|
||||
port: this.minisrv_config.services[service_name].upstream_port
|
||||
})
|
||||
}
|
||||
|
||||
connectUsenet() {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.client.connect().then((response) => {
|
||||
if (response.code == 200) {
|
||||
resolve(true);
|
||||
}
|
||||
}).catch((e) => {
|
||||
console.error(" * WTVNews Error:", "Command: connect", e);
|
||||
reject("Could not connect to upstream usenet server");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
listGroup(group) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.client.listGroup(group).then((data) => {
|
||||
resolve(data);
|
||||
}).catch((e) => {
|
||||
console.error(" * WTVNews Error:", "Command: listGroup", e);
|
||||
reject(`No such group <b>${group}</b>`);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
selectGroup(group) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.client.group(group).then((response) => {
|
||||
if (response.code == 211) resolve(true);
|
||||
else reject(`No such group <b>${group}</b>`);
|
||||
}).catch((e) => {
|
||||
console.error(" * WTVNews Error:", "Command: selectGroup", e);
|
||||
reject(`Error selecting group <b>${group}</b>`);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getArticle(articleID) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.client.article(articleID).then((data) => {
|
||||
resolve(data)
|
||||
}).catch((e) => {
|
||||
reject(`Error reading article ID ${articleID}`);
|
||||
console.error(" * WTVNews Error:", "Command: article", e);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getHeader(articleID) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.client.head(articleID).then((data) => {
|
||||
resolve(data);
|
||||
}).catch((e) => {
|
||||
reject(`Error getting header for article ID ${articleID}`);
|
||||
console.error(" * WTVNews Error:", "Command: head -", "Article ID: " + articleID, e);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
quitUsenet() {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.client.quit().then((response) => {
|
||||
if (response.code == 205) resolve(true);
|
||||
else {
|
||||
console.error(" * WTVNews Error:", "Command: quit", e);
|
||||
reject(`Unexpected response code ${response.code}`);
|
||||
}
|
||||
}).catch((e) => {
|
||||
console.error(" * WTVNews Error:", "Command: quit", e);
|
||||
reject("Error quitting usenet session");
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
getHeaderObj(NGArticles) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var messages = [];
|
||||
var failed = false;
|
||||
for (var article in NGArticles) {
|
||||
if (failed) continue;
|
||||
if (article == "getCaseInsensitiveKey") continue;
|
||||
this.getHeader(NGArticles[article]).then((data) => {
|
||||
if (data.article) messages.push(data.article)
|
||||
}).catch((e) => {
|
||||
console.log(e, article);
|
||||
failed = e;
|
||||
});
|
||||
}
|
||||
if (!failed) resolve(messages);
|
||||
else reject("Could not read message list", failed);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = WTVNews;
|
||||
Reference in New Issue
Block a user