initial attachment support for usenet

- can read a few attachments posted by PCs
- can not yet attach from WebTV Plus
This commit is contained in:
zefie
2022-10-13 00:26:05 -04:00
parent b9c067af15
commit 0b56f02ec4
5 changed files with 216 additions and 19 deletions

View File

@@ -0,0 +1,70 @@
var minisrv_service_file = true;
var request_is_async = true;
var errpage = null;
var group = request_headers.query.group;
var article = request_headers.query.article;
var attachment_id = parseInt(request_headers.query.attachment_id);
if ((!attachment_id && attachment_id != 0) || !group || !article) {
errpage = wtvshared.doErrorPage(400, "Attachment ID required.");
sendToClient(socket, errpage[0], errpage[1]);
} else {
const wtvnews = new WTVNews(minisrv_config, service_name);
var service_config = minisrv_config.services[service_name];
if (service_config.local_nntp_port && wtvnewsserver) {
var tls_path = this.wtvshared.getAbsolutePath(this.minisrv_config.config.ServiceDeps + '/wtv-news');
var tls_options = {
ca: this.fs.readFileSync(tls_path + '/localserver_ca.pem'),
key: this.fs.readFileSync(tls_path + '/localserver_key.pem'),
cert: this.fs.readFileSync(tls_path + '/localserver_cert.pem'),
checkServerIdentity: () => { return null; }
}
if (wtvnewsserver.username)
wtvnews.initializeUsenet("127.0.0.1", service_config.local_nntp_port, tls_options, wtvnewsserver.username, wtvnewsserver.password);
else
wtvnews.initializeUsenet("127.0.0.1", service_config.local_nntp_port, tls_options);
} else {
if (service_config.upstream_auth)
wtvnews.initializeUsenet(service_config.upstream_address, service_config.upstream_port, service_config.upstream_tls || null, service_config.upstream_auth.username || null, service_config.upstream_auth.password || null);
else
wtvnews.initializeUsenet(service_config.upstream_address, service_config.upstream_port, service_config.upstream_tls || null);
}
var article = parseInt(article);
wtvnews.connectUsenet().then(() => {
wtvnews.selectGroup(group).then((response) => {
wtvnews.getArticle(article).then((response) => {
wtvnews.quitUsenet();
if (response.code == 220) {
var message_data = wtvnews.parseAttachments(response);
if (message_data.attachments) {
if (attachment_id < message_data.attachments.length) {
var attachment = message_data.attachments[attachment_id];
console.log(attachment);
var encoding = attachment.content_encoding.toLowerCase()
if (encoding == 'base64') {
data = Buffer.from(attachment.data, encoding);
headers = "200 OK\n"
headers += "Content-Type: " + attachment.content_type + "\n";
if (attachment.filename) headers += "Content-Disposition: attachment; filename=\"" + attachment.filename + "\"\n";
sendToClient(socket, headers, data);
} else {
errpage = wtvshared.doErrorPage(400, "Unimplemented encoding type:", encoding);
sendToClient(socket, errpage[0], errpage[1]);
}
} else {
errpage = wtvshared.doErrorPage(400, "Attachment ID exceeds available attachments");
sendToClient(socket, errpage[0], errpage[1]);
}
} else {
errpage = wtvshared.doErrorPage(400, "Article does not contain attachments.");
sendToClient(socket, errpage[0], errpage[1]);
}
} else {
errpage = wtvshared.doErrorPage(400);
sendToClient(socket, errpage[0], errpage[1]);
}
});
});
});
}

View File

@@ -544,25 +544,33 @@ ${(response.article.headers.SUBJECT) ? wtvshared.htmlEntitize(response.article.h
<td abswidth=20 rowspan=99>
<tr>
<td>
`;
var message_body = response.article.body.join("\n");
`;
var message = wtvnews.parseAttachments(response);
var message_body = message.text;
var attachments = null;
if (message.attachments) attachments = message.attachments;
data += `
${wtvshared.htmlEntitize(message_body, true)}
<br>
<br>`;
data += "<p>";
/*
if (message.attachments) {
message.attachments.forEach((v, k) => {
if (attachments) {
attachments.forEach((v, k) => {
if (v) {
console.log("*****************", v['Content-Type']);
switch (v['Content-Type']) {
switch (v.content_type) {
case "image/jpeg":
data += `<img border=2 src="wtv-news:/get-attachment?message_id=${messageid}&attachment_id=${k}&group=${(message.to_group)}&wtv-title=Video%20Snapshot" width="380" height="290"><br><br>`;
case "image/png":
case "image/gif":
data += `<img border=2 src="wtv-news:/get-attachment?group=${group}&article=${article}&attachment_id=${k}wtv-title=Video%20Snapshot" width="380" height="290"><br><br>`;
break;
case "audio/wav":
data += `<table href="wtv-news:/get-attachment?message_id=${messageid}&attachment_id=${k}&group=${(message.to_group)}&wtv-title=Voice%20Mail" width=386 cellspacing=0 cellpadding=0>
<td align=left valign=middle><img src="wtv-mail:/ROMCache/FileSound.gif" align=absmiddle><font color="#189CD6">&nbsp;&nbsp;recording.wav (wav attachment)</font>
case "audio/mp2":
case "audio/mp3":
case "audio/mid":
case "audio/midi":
data += `<table href="wtv-news:/get-attachment?group=${group}&article=${article}&attachment_id=${k}&wtv-title=Audio%20file" width=386 cellspacing=0 cellpadding=0>
<td align=left valign=middle><img src="wtv-news:/ROMCache/FileSound.gif" align=absmiddle><font color="#189CD6">&nbsp;&nbsp;${(v.filename) ? (v.filename) : "Audio file"} (${v.content_type.split('/')[1]} attachment)</font>
<td align=right valign=middle>
</table><br><br>
`;
@@ -571,6 +579,7 @@ ${wtvshared.htmlEntitize(message_body, true)}
}
});
}
/*
if (message.url) {
data += `Included Page: <a href="${(message.url)}">${wtvshared.htmlEntitize(message.url_title).replace(/&apos;/gi, "'")}`;
}