Fixing remaining better-sqlite bugs, fixing pleroma messagin

This commit is contained in:
Darius Kazemi 2019-03-26 00:01:34 -07:00
parent e989126e86
commit 49ce163547
3 changed files with 13 additions and 12 deletions

View file

@ -60,7 +60,7 @@ function signAndSend(message, name, domain, req, res, targetDomain, inbox) {
} }
} }
function createMessage(text, name, domain, req, res) { function createMessage(text, name, domain, req, res, follower) {
const guidCreate = crypto.randomBytes(16).toString('hex'); const guidCreate = crypto.randomBytes(16).toString('hex');
const guidNote = crypto.randomBytes(16).toString('hex'); const guidNote = crypto.randomBytes(16).toString('hex');
let db = req.app.get('db'); let db = req.app.get('db');
@ -72,7 +72,7 @@ function createMessage(text, name, domain, req, res) {
'published': d.toISOString(), 'published': d.toISOString(),
'attributedTo': `https://${domain}/u/${name}`, 'attributedTo': `https://${domain}/u/${name}`,
'content': text, 'content': text,
'to': 'https://www.w3.org/ns/activitystreams#Public' 'to': ['https://www.w3.org/ns/activitystreams#Public'],
}; };
let createMessage = { let createMessage = {
@ -81,6 +81,8 @@ function createMessage(text, name, domain, req, res) {
'id': `https://${domain}/m/${guidCreate}`, 'id': `https://${domain}/m/${guidCreate}`,
'type': 'Create', 'type': 'Create',
'actor': `https://${domain}/u/${name}`, 'actor': `https://${domain}/u/${name}`,
'to': ['https://www.w3.org/ns/activitystreams#Public'],
'cc': [follower],
'object': noteMessage 'object': noteMessage
}; };
@ -92,7 +94,6 @@ function createMessage(text, name, domain, req, res) {
} }
function sendCreateMessage(text, name, domain, req, res) { function sendCreateMessage(text, name, domain, req, res) {
let message = createMessage(text, name, domain, req, res);
let db = req.app.get('db'); let db = req.app.get('db');
let result = db.prepare('select followers from accounts where name = ?').get(`${name}@${domain}`); let result = db.prepare('select followers from accounts where name = ?').get(`${name}@${domain}`);
@ -108,6 +109,7 @@ function sendCreateMessage(text, name, domain, req, res) {
let inbox = follower+'/inbox'; let inbox = follower+'/inbox';
let myURL = new URL(follower); let myURL = new URL(follower);
let targetDomain = myURL.hostname; let targetDomain = myURL.hostname;
let message = createMessage(text, name, domain, req, res, follower);
signAndSend(message, name, domain, req, res, targetDomain, inbox); signAndSend(message, name, domain, req, res, targetDomain, inbox);
} }
res.status(200).json({msg: 'ok'}); res.status(200).json({msg: 'ok'});

View file

@ -10,7 +10,7 @@ function signAndSend(message, name, domain, req, res, targetDomain) {
let inboxFragment = inbox.replace('https://'+targetDomain,''); let inboxFragment = inbox.replace('https://'+targetDomain,'');
// get the private key // get the private key
let db = req.app.get('db'); let db = req.app.get('db');
let result = db.prepare('select privkey from accounts where name = ?').get(name); let result = db.prepare('select privkey from accounts where name = ?').get(`${name}@${domain}`);
if (result === undefined) { if (result === undefined) {
return res.status(404).send(`No record found for ${name}.`); return res.status(404).send(`No record found for ${name}.`);
} }

View file

@ -9,14 +9,13 @@ router.get('/:guid', function (req, res) {
} }
else { else {
let db = req.app.get('db'); let db = req.app.get('db');
db.get('select message from messages where guid = $guid', {$guid: guid}, (err, result) => { let result = db.prepare('select message from messages where guid = ?').get(guid);
if (result === undefined) { if (result === undefined) {
return res.status(404).send(`No record found for ${guid}.`); return res.status(404).send(`No record found for ${guid}.`);
} }
else { else {
res.json(JSON.parse(result.message)); res.json(JSON.parse(result.message));
} }
});
} }
}); });