var minisrv_service_file = true;
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);
}
async function throwError(e) {
console.log(e);
var errpage = wtvshared.doErrorPage(400, null, e.toString());
sendToClient(socket, errpage[0], errpage[1]);
}
function isToday (chkdate) {
const today = new Date()
return chkdate.getDate() == today.getDate() &&
chkdate.getMonth() == today.getMonth() &&
chkdate.getFullYear() == today.getFullYear()
}
async function WebTVListGroup(group) {
var page_limit_default = 100;
wtvnews.connectUsenet().then(() => {
wtvnews.selectGroup(group).then(() => {
var limit_per_page = (request_headers.query.limit) ? parseInt(request_headers.query.limit) : page_limit_default;
var page = (request_headers.query.chunk) ? parseInt(request_headers.query.chunk) : 0;
wtvnews.listGroup(group, page, limit_per_page).then((response) => {
if (response.code == 211) {
NGCount = response.group.number;
NGArticles = response.group.articleNumbers;
page_start = (limit_per_page * page) + 1;
page_end = (page + 1) * limit_per_page;
if (page_end > NGCount) page_end = NGCount;
wtvnews.getHeaderObj(NGArticles).then((messages) => {
messages = wtvnews.sortByResponse(messages);
wtvnews.quitUsenet();
headers = `200 OK
Connection: Keep-Alive
Content-Type: text/html
wtv-expire: wtv-news:/news?group=${request_headers.query.group}`
data = `
${request_headers.query.group}
|
|
|
|
|
Group: ${request_headers.query.group}
|
|
`
if (NGCount == 0) {
data += `This group has no postings`;
} else {
data += NGCount + " posting";
if (NGCount != 1)
data += "s"
}
data += `
`;
if (NGCount > 0) {
data += `
|
${(page > 0) ? ` ` : ` `}
|
|
|
|
${(page_end < NGCount) ? ` ` : ` `}
|
|
|
|
${page_start}-${page_end}
|
|
|
| `;
}
data += ` |
`
if (NGCount > 0) {
Object.keys(messages).forEach(function (k) {
var message = messages[k].article;
var has_relation = (messages[k].relation !== null) ? true : false;
var date_obj = new Date(Date.parse(message.headers.DATE));
var date = (isToday(date_obj)) ? strftime("%I:%M %p", date_obj) : strftime("%b %d", date_obj)
data += `
|
|
${(has_relation) ? `| ` : ''}
|
${(message.headers.SUBJECT) ? message.headers.SUBJECT : "(No Subject)"}
|
${(message.headers.FROM.indexOf(' ') > 0) ? message.headers.FROM.split(' ')[0] : message.headers.FROM}, ${date}
| |
|
| `;
});
}
data += `

|