mirror of
https://github.com/dariusk/rss-to-activitypub.git
synced 2024-11-22 17:29:19 +02:00
45e1362aa2
This commit mostly fixes the duplicate messages issue. What was happening was I was creating multiple Note objects if I was sending a Note to multiple people. Instead I create one Note object and reference that in multiple Create events.
59 lines
2.2 KiB
JavaScript
59 lines
2.2 KiB
JavaScript
const config = require('./config.json');
|
|
const { DOMAIN, PRIVKEY_PATH, CERT_PATH, PORT_HTTP, PORT_HTTPS } = config;
|
|
const express = require('express');
|
|
const app = express();
|
|
const Database = require('better-sqlite3');
|
|
const db = new Database('bot-node.db');
|
|
const fs = require('fs');
|
|
const routes = require('./routes'),
|
|
bodyParser = require('body-parser'),
|
|
cors = require('cors'),
|
|
http = require('http');
|
|
let sslOptions;
|
|
|
|
try {
|
|
sslOptions = {
|
|
key: fs.readFileSync(PRIVKEY_PATH),
|
|
cert: fs.readFileSync(CERT_PATH)
|
|
};
|
|
} catch(err) {
|
|
if (err.errno === -2) {
|
|
console.log('No SSL key and/or cert found, not enabling https server');
|
|
}
|
|
else {
|
|
console.log(err);
|
|
}
|
|
}
|
|
|
|
// if there is no `accounts` table in the DB, create an empty table
|
|
db.prepare('CREATE TABLE IF NOT EXISTS accounts (name TEXT PRIMARY KEY, privkey TEXT, pubkey TEXT, webfinger TEXT, actor TEXT, apikey TEXT, followers TEXT, messages TEXT)').run();
|
|
// if there is no `feeds` table in the DB, create an empty table
|
|
db.prepare('CREATE TABLE IF NOT EXISTS feeds (feed TEXT PRIMARY KEY, username TEXT, content TEXT)').run();
|
|
// if there is no `messages` table in the DB, create an empty table
|
|
db.prepare('CREATE TABLE IF NOT EXISTS messages (guid TEXT PRIMARY KEY, message TEXT)').run();
|
|
|
|
app.set('db', db);
|
|
app.set('domain', DOMAIN);
|
|
app.set('port', process.env.PORT || PORT_HTTP);
|
|
app.set('port-https', process.env.PORT_HTTPS || PORT_HTTPS);
|
|
app.set('views', './views');
|
|
app.set('view engine', 'pug');
|
|
app.use(bodyParser.json({type: 'application/activity+json'})); // support json encoded bodies
|
|
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
|
|
|
|
app.get('/', (req, res) => res.render('home'));
|
|
|
|
// admin page
|
|
app.options('/api', cors());
|
|
app.use('/api', cors(), routes.api);
|
|
app.use('/admin', express.static('public/admin'));
|
|
app.use('/convert', express.static('public/convert'));
|
|
app.use('/.well-known/webfinger', cors(), routes.webfinger);
|
|
app.use('/u', cors(), routes.user);
|
|
app.use('/m', cors(), routes.message);
|
|
app.use('/api/inbox', cors(), routes.inbox);
|
|
|
|
http.createServer(app).listen(app.get('port'), function(){
|
|
console.log('Express server listening on port ' + app.get('port'));
|
|
});
|