mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-17 03:07:52 -05:00
Update index.js
This commit is contained in:
@@ -4,7 +4,7 @@ const express = require("express");
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
const secrets = require("./config/secrets");
|
const secrets = require("./config/secrets");
|
||||||
const configureExpress = require("./config/express");
|
const configureExpress = require("./config/express");
|
||||||
const { Podcast,Item,FeedOptions } = require('podcast');
|
const { Podcast, Item, FeedOptions } = require('podcast');
|
||||||
|
|
||||||
// -------------------------------------------
|
// -------------------------------------------
|
||||||
|
|
||||||
@@ -53,8 +53,8 @@ function getCard(req, res, next) {
|
|||||||
function (err, item) {
|
function (err, item) {
|
||||||
if (item) {
|
if (item) {
|
||||||
var time = new Date(item.time);
|
var time = new Date(item.time);
|
||||||
var timeString = time.toLocaleTimeString('en-US', {timeZone: "America/New_York"});
|
var timeString = time.toLocaleTimeString('en-US', { timeZone: "America/New_York" });
|
||||||
var dateString = time.toLocaleDateString('en-US', {timeZone: "America/New_York"});
|
var dateString = time.toLocaleDateString('en-US', { timeZone: "America/New_York" });
|
||||||
//console.log(item)
|
//console.log(item)
|
||||||
res.render('card.ejs', {
|
res.render('card.ejs', {
|
||||||
item: item,
|
item: item,
|
||||||
@@ -108,58 +108,153 @@ exports.get_card = function(req, res) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
|
async function getPodcast(req, res, next) {
|
||||||
|
const now = new Date().toLocaleString();
|
||||||
|
|
||||||
|
const feedStart = `
|
||||||
|
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:psc="http://podlove.org/simple-chapters" xmlns:podcast="https://podcastindex.org/namespace/1.0" version="2.0">
|
||||||
|
<channel>
|
||||||
|
<title>
|
||||||
|
<![CDATA[ OpenMHz ]]>
|
||||||
|
</title>
|
||||||
|
<description>
|
||||||
|
<![CDATA[ Real public safety radio recordings, from across the country. <a href="hhtps://openmhz.com">OpenMHz</a> is a website that makes it easy to share recordings of public safety radio system. This podcast is a collection of interesting events that has been curated by the OpenMHz community. ]]>
|
||||||
|
</description>
|
||||||
|
<link>https://openmhz.com</link>
|
||||||
|
<generator>Podcast for Node</generator>
|
||||||
|
<lastBuildDate>${now}</lastBuildDate>
|
||||||
|
<atom:link href="https://openmhz.com/rss.xml" rel="self" type="application/rss+xml"/>
|
||||||
|
<author>
|
||||||
|
<![CDATA[ OpenMHz ]]>
|
||||||
|
</author>
|
||||||
|
<pubDate>${now}</pubDate>
|
||||||
|
<copyright>
|
||||||
|
<![CDATA[ © 2023 Robotastic ]]>
|
||||||
|
</copyright>
|
||||||
|
<language>
|
||||||
|
<![CDATA[ en ]]>
|
||||||
|
</language>
|
||||||
|
<ttl>60</ttl>
|
||||||
|
<itunes:author>OpenMHz</itunes:author>
|
||||||
|
<itunes:subtitle>I am a sub title</itunes:subtitle>
|
||||||
|
<itunes:summary>Real public safety radio recordings, from across the country. OpenMHz is a website that makes it easy to share recordings of public safety radio system. This podcast is a collection of interesting events that has been curated by the OpenMHz community.</itunes:summary>
|
||||||
|
<itunes:owner>
|
||||||
|
<itunes:name>Luke Berndt</itunes:name>
|
||||||
|
<itunes:email>luke@robotastic.com</itunes:email>
|
||||||
|
</itunes:owner>
|
||||||
|
<itunes:explicit>false</itunes:explicit>
|
||||||
|
<itunes:category text="Government"/>
|
||||||
|
<itunes:category text="Daily News"/>
|
||||||
|
<itunes:category text="True Crime"/>
|
||||||
|
<itunes:image href="https://openmhz.com/podcast/cover.png"/>
|
||||||
|
`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const feedEnd = `
|
||||||
|
</channel>
|
||||||
|
</rss>
|
||||||
|
`
|
||||||
|
let xml = feedStart;
|
||||||
|
try {
|
||||||
|
const podcastsCollection = db.get().collection('podcasts');
|
||||||
|
podcastsCollection.find().toArray(function (err, podcasts) {
|
||||||
|
|
||||||
|
|
||||||
|
for (const podcast of podcasts) {
|
||||||
|
let description = podcast.description + "\n\nRadio Systems: \n";
|
||||||
|
for (const system of podcast.systems) {
|
||||||
|
description = description + " - " + system + "\n";
|
||||||
|
}
|
||||||
|
xml = xml + `
|
||||||
|
<item>
|
||||||
|
<title>
|
||||||
|
<![CDATA[ ${podcast.title} ]]>
|
||||||
|
</title>
|
||||||
|
<description>
|
||||||
|
<![CDATA[ ${description} ]]>
|
||||||
|
</description>
|
||||||
|
<guid isPermaLink="false">${podcast.downloadUrl}</guid>
|
||||||
|
<dc:creator>
|
||||||
|
<![CDATA[ OpenMHz ]]>
|
||||||
|
</dc:creator>
|
||||||
|
<url>${podcast.eventUrl}</url>
|
||||||
|
<pubDate>${podcast.startTime}</pubDate>
|
||||||
|
<enclosure url="${podcast.downloadUrl}" length="0" type="audio/mp4"/>
|
||||||
|
<itunes:author>OpenMHz</itunes:author>
|
||||||
|
<itunes:summary>${description}</itunes:summary>
|
||||||
|
<itunes:explicit>false</itunes:explicit>
|
||||||
|
</item>
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
xml = xml + feedEnd;
|
||||||
|
res.set('Content-Type', 'text/xml');
|
||||||
|
res.send(xml);
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
async function getPodcast(req, res, next) {
|
async function getPodcast(req, res, next) {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
try {
|
try {
|
||||||
const podcastsCollection = db.get().collection('podcasts');
|
const podcastsCollection = db.get().collection('podcasts');
|
||||||
podcastsCollection.find().toArray(function(err, podcasts) {
|
podcastsCollection.find().toArray(function (err, podcasts) {
|
||||||
const feed = new Podcast({
|
const feed = new Podcast({
|
||||||
title: 'OpenMHz',
|
title: 'OpenMHz',
|
||||||
description: 'Real public safety radio recordings, from across the country. OpenMHz is a website that makes it easy to share recordings of public safety radio system. This podcast is a collection of interesting events that has been curated by the OpenMHz community.',
|
description: 'Real public safety radio recordings, from across the country. OpenMHz is a website that makes it easy to share recordings of public safety radio system. This podcast is a collection of interesting events that has been curated by the OpenMHz community.',
|
||||||
feedUrl: 'https://openmhz.com/rss.xml',
|
feedUrl: 'https://openmhz.com/rss.xml',
|
||||||
siteUrl: 'https://openmhz.com',
|
siteUrl: 'https://openmhz.com',
|
||||||
imageUrl: 'https://openmhz.com/podcast/cover.png',
|
imageUrl: 'https://openmhz.com/podcast/cover.png',
|
||||||
author: 'OpenMHz',
|
author: 'OpenMHz',
|
||||||
copyright: '© 2022 Robotastic',
|
copyright: '© 2022 Robotastic',
|
||||||
language: 'en',
|
language: 'en',
|
||||||
pubDate: 'May 20, 2012 04:00:00 GMT',
|
pubDate: 'May 20, 2012 04:00:00 GMT',
|
||||||
ttl: 60,
|
ttl: 60,
|
||||||
itunesAuthor: 'OpenMHz',
|
itunesAuthor: 'OpenMHz',
|
||||||
itunesSubtitle: 'I am a sub title',
|
itunesSubtitle: 'I am a sub title',
|
||||||
itunesSummary: 'Real public safety radio recordings, from across the country. OpenMHz is a website that makes it easy to share recordings of public safety radio system. This podcast is a collection of interesting events that has been curated by the OpenMHz community.',
|
itunesSummary: 'Real public safety radio recordings, from across the country. OpenMHz is a website that makes it easy to share recordings of public safety radio system. This podcast is a collection of interesting events that has been curated by the OpenMHz community.',
|
||||||
itunesOwner: { name: 'Luke Berndt', email: 'luke@robotastic.com' },
|
itunesOwner: { name: 'Luke Berndt', email: 'luke@robotastic.com' },
|
||||||
itunesExplicit: false,
|
itunesExplicit: false,
|
||||||
itunesCategory: [{
|
itunesCategory: [{
|
||||||
text: 'Government'
|
text: 'Government'
|
||||||
}, { text: "Daily News"}, {text: "True Crime"}],
|
}, { text: "Daily News" }, { text: "True Crime" }],
|
||||||
itunesImage: 'https://openmhz.com/podcast/cover.png'
|
itunesImage: 'https://openmhz.com/podcast/cover.png'
|
||||||
});
|
});
|
||||||
for (const podcast of podcasts) {
|
for (const podcast of podcasts) {
|
||||||
let description = podcast.description +"\\n\\nRadio Systems:\\n";
|
let description = podcast.description + `
|
||||||
|
|
||||||
|
Radio Systems:
|
||||||
|
`;
|
||||||
for (const system of podcast.systems) {
|
for (const system of podcast.systems) {
|
||||||
description = description + " - " + system + "\\n"
|
description = description + " - " + system + "\n"
|
||||||
}
|
}
|
||||||
feed.addItem({
|
feed.addItem({
|
||||||
title: podcast.title,
|
title: podcast.title,
|
||||||
description: description,
|
description: description,
|
||||||
enclosure: {
|
enclosure: {
|
||||||
url: podcast.downloadUrl, // link to the item
|
url: podcast.downloadUrl, // link to the item
|
||||||
},
|
},
|
||||||
author: 'OpenMHz', // optional - defaults to feed author property
|
author: 'OpenMHz', // optional - defaults to feed author property
|
||||||
url: podcast.eventUrl,
|
url: podcast.eventUrl,
|
||||||
date: podcast.startTime, // any format that js Date can parse.
|
date: podcast.startTime, // any format that js Date can parse.
|
||||||
itunesAuthor: 'OpenMHz',
|
itunesAuthor: 'OpenMHz',
|
||||||
itunesExplicit: false,
|
itunesExplicit: false,
|
||||||
itunesSummary: podcast.description,
|
itunesSummary: description,
|
||||||
itunesDuration: podcast.len
|
itunesDuration: podcast.len
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const xml = feed.buildXml();
|
const xml = feed.buildXml();
|
||||||
res.set('Content-Type', 'text/xml');
|
res.set('Content-Type', 'text/xml');
|
||||||
res.send(xml);
|
res.send(xml);
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
@@ -180,27 +275,27 @@ async function getCalls(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.get().collection('calls', function (err, transCollection) {
|
db.get().collection('calls', function (err, transCollection) {
|
||||||
transCollection.findOne({
|
transCollection.findOne({
|
||||||
'_id': o_id
|
'_id': o_id
|
||||||
},
|
},
|
||||||
async function (err, item) {
|
async function (err, item) {
|
||||||
if (item) {
|
if (item) {
|
||||||
var time = new Date(item.time);
|
var time = new Date(item.time);
|
||||||
var timeString = time.toLocaleTimeString('en-US', {timeZone: "America/New_York"});
|
var timeString = time.toLocaleTimeString('en-US', { timeZone: "America/New_York" });
|
||||||
var dateString = time.toDateString('en-US', {timeZone: "America/New_York"});
|
var dateString = time.toDateString('en-US', { timeZone: "America/New_York" });
|
||||||
//console.log(item)
|
//console.log(item)
|
||||||
const tg_coll = db.get().collection('talkgroups');
|
const tg_coll = db.get().collection('talkgroups');
|
||||||
const tg = await tg_coll.findOne({ "num": item.talkgroupNum, 'shortName': req.params.shortName.toLowerCase()})
|
const tg = await tg_coll.findOne({ "num": item.talkgroupNum, 'shortName': req.params.shortName.toLowerCase() })
|
||||||
var title = item.len + " second transmission"
|
var title = item.len + " second transmission"
|
||||||
|
|
||||||
if (tg) {
|
if (tg) {
|
||||||
//console.log(tg)
|
//console.log(tg)
|
||||||
title = tg.description;
|
title = tg.description;
|
||||||
}
|
}
|
||||||
const callId = req.query["call-id"];
|
const callId = req.query["call-id"];
|
||||||
const callUrl = "https://s3.us-west-1.wasabisys.com/openmhz-west/media/dcfd-1039-1613917169.m4a"
|
const callUrl = "https://s3.us-west-1.wasabisys.com/openmhz-west/media/dcfd-1039-1613917169.m4a"
|
||||||
const twitterMeta = `
|
const twitterMeta = `
|
||||||
<meta name="twitter:card" content="player"/>
|
<meta name="twitter:card" content="player"/>
|
||||||
<meta name="twitter:site" content="@openmhz"/>
|
<meta name="twitter:site" content="@openmhz"/>
|
||||||
|
|
||||||
@@ -212,19 +307,19 @@ async function getCalls(req, res, next) {
|
|||||||
<meta name="twitter:player:stream:content_type" content="audio/mp4"/>
|
<meta name="twitter:player:stream:content_type" content="audio/mp4"/>
|
||||||
<meta name="twitter:player:width" content="425"/>
|
<meta name="twitter:player:width" content="425"/>
|
||||||
<meta name="twitter:player:height" content="165"/>`
|
<meta name="twitter:player:height" content="165"/>`
|
||||||
res.render("index.ejs", { TWITTER_META: twitterMeta })
|
res.render("index.ejs", { TWITTER_META: twitterMeta })
|
||||||
} else {
|
} else {
|
||||||
console.warn("Error - /card/:id Could not find Item " + err);
|
console.warn("Error - /card/:id Could not find Item " + err);
|
||||||
res.send(404, 'Sorry, we cannot find that!');
|
res.send(404, 'Sorry, we cannot find that!');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
next()
|
next()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user