diff --git a/routes/message.js b/routes/message.js new file mode 100644 index 0000000..a62a9f1 --- /dev/null +++ b/routes/message.js @@ -0,0 +1,44 @@ +'use strict'; +const express = require('express'), + router = express.Router(), + Parser = require('rss-parser'), + parser = new Parser(); + +router.get('/:guid', function (req, res) { + let guid = req.params.guid; + if (!guid) { + return res.status(400).send('Bad request.'); + } + // render the raw JSON if JSON headers are passed + else if (req.headers.accept && (req.headers.accept.includes('application/activity+json') || req.headers.accept.includes('application/json') || req.headers.accept.includes('application/json+ld'))) { + let db = req.app.get('db'); + let result = db.prepare('select message from messages where guid = ?').get(guid); + if (result === undefined) { + return res.status(404).send(`No record found for ${guid}.`); + } + else { + res.json(JSON.parse(result.message)); + } + } + // render a human-friendly view otherwise + else { + let db = req.app.get('db'); + let result = db.prepare('select message from messages where guid = ?').get(guid); + if (result === undefined) { + return res.status(404).send(`No record found for ${guid}.`); + } + else { + let message = JSON.parse(result.message); + let domain = req.app.get('domain'); + let username = message.attributedTo.replace(`https://${domain}/u/`,''); + let resultFeed = db.prepare('select feed from feeds where username = ?').get(username); + if (resultFeed === undefined) { + return res.status(404).json(`Something went very wrong!`); + } + let feed = resultFeed.feed; + res.render('message', { description: message.content, feedUrl: feed, author: message.attributedTo, link: message.link}); + } + } +}); + +module.exports = router; diff --git a/updateFeeds.js b/updateFeeds.js index 5623c8f..7f0e23b 100644 --- a/updateFeeds.js +++ b/updateFeeds.js @@ -62,7 +62,7 @@ function doFeed() { // FIX THIS item = transformContent(item); //console.log(item.urls); - let message = `

${item.title}

${item.content}

`; + let message = `

${item.title}

${item.content || ''}

`; if (item.enclosure && item.enclosure.url && item.enclosure.url.includes('.mp3')) { message += `

${item.enclosure.url}

`; } diff --git a/views/message.pug b/views/message.pug new file mode 100644 index 0000000..a1ed698 --- /dev/null +++ b/views/message.pug @@ -0,0 +1,10 @@ +html + head + + title= displayName + style + include style.css + body + ← RSS to ActivityPub Converter + h1 Hello! + p This is a placeholder for a message that was sent from this RSS feed via this bot account. We don't want to rehost content here, so the best we can do is point you to this particular post which the RSS feed says should contain the original content. You can share with other people from there.