Commit missing files

Fixes #21
This commit is contained in:
Darius Kazemi 2019-04-12 05:30:34 -07:00
parent 9d08138408
commit c22dbae3b5
3 changed files with 55 additions and 1 deletions

44
routes/message.js Normal file
View File

@ -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;

View File

@ -62,7 +62,7 @@ function doFeed() {
// FIX THIS
item = transformContent(item);
//console.log(item.urls);
let message = `<p><a href="${item.link}">${item.title}</a></p><p>${item.content}</p>`;
let message = `<p><a href="${item.link}">${item.title}</a></p><p>${item.content || ''}</p>`;
if (item.enclosure && item.enclosure.url && item.enclosure.url.includes('.mp3')) {
message += `<p><a href="${item.enclosure.url}">${item.enclosure.url}</a></p>`;
}

10
views/message.pug Normal file
View File

@ -0,0 +1,10 @@
html
head
<meta name="viewport" content="width=device-width, initial-scale=1">
title= displayName
style
include style.css
body
<a href="/">&larr; RSS to ActivityPub Converter</a>
h1 Hello!
p This is a placeholder for a message that was sent from <a href="#{feedUrl}">this RSS feed</a> via <a href="#{author}">this bot account</a>. We don't want to rehost content here, so the best we can do is point you to <a href="#{link}">this particular post</a> which the RSS feed says should contain the original content. You can share with other people from there.