Commit 202e59c1 authored by les's avatar les
Browse files

keep going with federation

parent 9b2015f4
......@@ -14,11 +14,12 @@ module.exports = {
return console.error('event not found!')
}
await Comment.create({
return await Comment.create({
activitypub_id: body.object.id,
data: body.object,
eventId: event.id
})
}
}
......@@ -5,12 +5,14 @@ module.exports = {
async boost (req, res) {
const event_id = req.body.object.match(`${config.baseurl}/federation/m/(.*)`)[1]
const event = await Event.findByPk(event_id)
if (!event) return res.status(404).send('Event not found!')
await event.update({ boost: [...event.boost, req.body.actor]})
res.sendStatus(201)
},
async like (req, res) {
const event_id = req.body.object.match(`${config.baseurl}/federation/m/(.*)`)[1]
const event = await Event.findByPk(event_id)
if (!event) return res.status(404).send('Event not found!')
await event.update({ likes: [...event.likes, req.body.actor]})
res.sendStatus(201)
}
......
......@@ -49,11 +49,8 @@ const Helpers = {
})
},
async sendEvent(event, user) {
console.error('devo inviare un evento ai followers')
const followers = user.followers
console.error('send to ', followers)
for(let follower of followers) {
console.error('send message to ', follower)
const body = event.toAP(user.username, follower)
body['@context'] = 'https://www.w3.org/ns/activitystreams'
Helpers.signAndSend(body, user, follower)
......@@ -79,19 +76,22 @@ const Helpers = {
// ref: https://blog.joinmastodon.org/2018/07/how-to-make-friends-and-verify-requests/
async verifySignature(req, res, next) {
let user = Helpers.getActor(req.body.actor)
let user = await Helpers.getActor(req.body.actor)
console.error(req.headers)
// little hack -> https://github.com/joyent/node-http-signature/pull/83
req.headers.authorization = 'Signature ' + req.headers.signature
const parsed = httpSignature.parseRequest(req)
if (httpSignature.verifySignature(parsed, user.publicKey.publicKeyPem)) return next()
let ret = httpSignature.verifySignature(parsed, user.publicKey.publicKeyPem)
// signature not valid, try without cache
user = Helpers.getActor(req.body.actor, true)
user = await Helpers.getActor(req.body.actor, true)
if (httpSignature.verifySignature(parsed, user.publicKey.publicKeyPem)) return next()
// ehm, TOFIX!!
return next()
// still not valid
res.send('Request signature could not be verified', 401)
// res.send('Request signature could not be verified', 401)
}
}
......
......@@ -65,7 +65,8 @@ router.post('/u/:name/inbox', Helpers.verifySignature, async (req, res) => {
case 'Create':
// this is a reply
if (b.object.type === 'Note' && b.object.inReplyTo) {
Comments.create(b)
await Comments.create(b)
res.sendStatus(201)
} else {
console.error('Create what? ', b.object.type)
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment