mirror of
https://github.com/dariusk/rss-to-activitypub.git
synced 2024-11-22 17:29:19 +02:00
parent
f0f67e07cd
commit
4966d0a922
|
@ -10,6 +10,7 @@
|
||||||
"cors": "^2.8.4",
|
"cors": "^2.8.4",
|
||||||
"express": "^4.16.3",
|
"express": "^4.16.3",
|
||||||
"generate-rsa-keypair": "^0.1.2",
|
"generate-rsa-keypair": "^0.1.2",
|
||||||
|
"parse-favicon": "^2.0.0",
|
||||||
"pug": "^2.0.3",
|
"pug": "^2.0.3",
|
||||||
"request": "^2.87.0",
|
"request": "^2.87.0",
|
||||||
"rss-parser": "^3.4.3"
|
"rss-parser": "^3.4.3"
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
const express = require('express'),
|
const express = require('express'),
|
||||||
router = express.Router(),
|
router = express.Router(),
|
||||||
crypto = require('crypto'),
|
crypto = require('crypto'),
|
||||||
|
request = require('request'),
|
||||||
Parser = require('rss-parser'),
|
Parser = require('rss-parser'),
|
||||||
|
parseFavicon = require('parse-favicon').parseFavicon,
|
||||||
generateRSAKeypair = require('generate-rsa-keypair');
|
generateRSAKeypair = require('generate-rsa-keypair');
|
||||||
|
|
||||||
router.get('/convert', function (req, res) {
|
router.get('/convert', function (req, res) {
|
||||||
|
@ -40,17 +42,14 @@ router.get('/convert', function (req, res) {
|
||||||
let domain = req.app.get('domain');
|
let domain = req.app.get('domain');
|
||||||
// create keypair
|
// create keypair
|
||||||
var pair = generateRSAKeypair();
|
var pair = generateRSAKeypair();
|
||||||
let imageUrl = null;
|
getImage(feed, feedData, imageUrl => {
|
||||||
// if image exists set image
|
let actorRecord = createActor(account, domain, pair.public, displayName, imageUrl);
|
||||||
if (feedData.image && feedData.image.url) {
|
let webfingerRecord = createWebfinger(account, domain);
|
||||||
imageUrl = feedData.image.url;
|
const apikey = crypto.randomBytes(16).toString('hex');
|
||||||
}
|
db.prepare('insert or replace into accounts(name, actor, apikey, pubkey, privkey, webfinger) values(?, ?, ?, ?, ?, ?)').run( `${account}@${domain}`, JSON.stringify(actorRecord), apikey, pair.public, pair.private, JSON.stringify(webfingerRecord));
|
||||||
let actorRecord = createActor(account, domain, pair.public, displayName, imageUrl);
|
let content = JSON.stringify(feedData);
|
||||||
let webfingerRecord = createWebfinger(account, domain);
|
db.prepare('insert or replace into feeds(feed, username, content) values(?, ?, ?)').run( feed, username, content);
|
||||||
const apikey = crypto.randomBytes(16).toString('hex');
|
});
|
||||||
db.prepare('insert or replace into accounts(name, actor, apikey, pubkey, privkey, webfinger) values(?, ?, ?, ?, ?, ?)').run( `${account}@${domain}`, apikey, pair.public, pair.private, JSON.stringify(actorRecord), JSON.stringify(webfingerRecord));
|
|
||||||
let content = JSON.stringify(feedData);
|
|
||||||
db.prepare('insert or replace into feeds(feed, username, content) values(?, ?, ?)').run( feed, username, content);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -59,6 +58,29 @@ router.get('/convert', function (req, res) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getImage(feed, feedData, cb) {
|
||||||
|
let imageUrl = null;
|
||||||
|
// if image exists set image
|
||||||
|
if (feedData.image && feedData.image.url) {
|
||||||
|
imageUrl = feedData.image.url;
|
||||||
|
return cb(imageUrl);
|
||||||
|
}
|
||||||
|
// otherwise parse the HTML for the favicon
|
||||||
|
else {
|
||||||
|
let favUrl = new URL(feed);
|
||||||
|
request(favUrl.origin, (err, resp, body) => {
|
||||||
|
parseFavicon(body, {baseURI: favUrl.origin}).then(result => {
|
||||||
|
if (result && result.length) {
|
||||||
|
return cb(result[0].url);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return cb(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function createActor(name, domain, pubkey, displayName, imageUrl) {
|
function createActor(name, domain, pubkey, displayName, imageUrl) {
|
||||||
displayName = displayName || name;
|
displayName = displayName || name;
|
||||||
let actor = {
|
let actor = {
|
||||||
|
|
Loading…
Reference in New Issue