lots of changes:

- 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:
zefie
2022-10-11 13:51:20 -04:00
parent bf50e6e9e9
commit a887a36104
14 changed files with 314 additions and 271 deletions

View File

@@ -302,7 +302,7 @@ class WTVDownloadList {
<head>
<meta
http-equiv=refresh
content="0;url=client:Fetch?group=${escape(group)}&source=${escape(url)}&message=${escape(message)}"
content="0;url=client:Fetch?group=${encodeURIComponent(group)}&source=${encodeURIComponent(url)}&message=${encodeURIComponent(message)}"
>
<display downloadsuccess="${success_url}" downloadfail="${fail_url}">
<title>${title}</title>
@@ -343,6 +343,8 @@ class WTVDownloadList {
message="Preparing..."
height=40 width=250>
</font>
<br>
</table>
</body>
</html>

View File

@@ -1,5 +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;

View File

@@ -556,9 +556,21 @@ class WTVShared {
});
}
doErrorPage(code, data = null, pc_mode = false) {
doErrorPage(code, data = null, details = null, pc_mode = false) {
var headers = null;
switch (code) {
case 401:
if (data === null) data = "Authorization Required.";
if (pc_mode) headers = "401 Unauthorized\n";
else headers = code + " " + data + "\n";
headers += "Content-Type: text/html\n";
break;
case 403:
if (data === null) data = "The publisher of that page has not authorized you to view it.";
if (pc_mode) headers = "403 Forbidden\n";
else headers = code + " " + data + "\n";
headers += "Content-Type: text/html\n";
break;
case 404:
if (data === null) data = "The service could not find the requested page.";
if (pc_mode) headers = "404 Not Found\n";
@@ -568,16 +580,11 @@ class WTVShared {
case 400:
case 500:
if (data === null) data = this.minisrv_config.config.service_name + " ran into a technical problem.";
if (details) data += "<br>Details:<br>" + details;
if (pc_mode) headers = "500 Internal Server Error\n";
else headers = code + " " + data + "\n";
headers += "Content-Type: text/html\n";
break;
case 401:
if (data === null) data = "Access Denied.";
if (pc_mode) headers = "401 Access Denied\n";
else headers = code + " " + data + "\n";
headers += "Content-Type: text/html\n";
break;
default:
headers = code + " " + data + "\n";
headers += "Content-Type: text/html\n";

View File

@@ -60,7 +60,10 @@
},
"wtv-news": {
"port": 1605,
"disabled": true
"disabled": true,
"modules": [
"WTVNews"
]
},
"wtv-register": {
"port": 1607,
@@ -93,7 +96,10 @@
"flags": "0x00000010",
"passport_service": "wtv-passport",
"connections": 3,
"privileged": true
"privileged": true,
"modules": [
"WTVBGMusic"
]
},
"wtv-music": {
"port": 1656,
@@ -109,7 +115,10 @@
},
"wtv-disk": {
"port": 1635,
"connections": 3
"connections": 3,
"modules": [
"WTVDisk"
]
},
"wtv-guide": {
"port": 1621,