mirror of
https://github.com/dariusk/express-activitypub.git
synced 2024-11-21 15:00:58 +00:00
Fixing remaining better-sqlite bugs, fixing pleroma messagin
This commit is contained in:
parent
e989126e86
commit
49ce163547
3 changed files with 13 additions and 12 deletions
|
@ -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 guidNote = crypto.randomBytes(16).toString('hex');
|
||||
let db = req.app.get('db');
|
||||
|
@ -72,7 +72,7 @@ function createMessage(text, name, domain, req, res) {
|
|||
'published': d.toISOString(),
|
||||
'attributedTo': `https://${domain}/u/${name}`,
|
||||
'content': text,
|
||||
'to': 'https://www.w3.org/ns/activitystreams#Public'
|
||||
'to': ['https://www.w3.org/ns/activitystreams#Public'],
|
||||
};
|
||||
|
||||
let createMessage = {
|
||||
|
@ -81,6 +81,8 @@ function createMessage(text, name, domain, req, res) {
|
|||
'id': `https://${domain}/m/${guidCreate}`,
|
||||
'type': 'Create',
|
||||
'actor': `https://${domain}/u/${name}`,
|
||||
'to': ['https://www.w3.org/ns/activitystreams#Public'],
|
||||
'cc': [follower],
|
||||
|
||||
'object': noteMessage
|
||||
};
|
||||
|
@ -92,7 +94,6 @@ function createMessage(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 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 myURL = new URL(follower);
|
||||
let targetDomain = myURL.hostname;
|
||||
let message = createMessage(text, name, domain, req, res, follower);
|
||||
signAndSend(message, name, domain, req, res, targetDomain, inbox);
|
||||
}
|
||||
res.status(200).json({msg: 'ok'});
|
||||
|
|
|
@ -10,7 +10,7 @@ function signAndSend(message, name, domain, req, res, targetDomain) {
|
|||
let inboxFragment = inbox.replace('https://'+targetDomain,'');
|
||||
// get the private key
|
||||
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) {
|
||||
return res.status(404).send(`No record found for ${name}.`);
|
||||
}
|
||||
|
|
|
@ -9,14 +9,13 @@ router.get('/:guid', function (req, res) {
|
|||
}
|
||||
else {
|
||||
let db = req.app.get('db');
|
||||
db.get('select message from messages where guid = $guid', {$guid: guid}, (err, result) => {
|
||||
if (result === undefined) {
|
||||
return res.status(404).send(`No record found for ${guid}.`);
|
||||
}
|
||||
else {
|
||||
res.json(JSON.parse(result.message));
|
||||
}
|
||||
});
|
||||
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));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue