keep going with federation
This commit is contained in:
@@ -14,11 +14,12 @@ module.exports = {
|
|||||||
return console.error('event not found!')
|
return console.error('event not found!')
|
||||||
}
|
}
|
||||||
|
|
||||||
await Comment.create({
|
return await Comment.create({
|
||||||
activitypub_id: body.object.id,
|
activitypub_id: body.object.id,
|
||||||
data: body.object,
|
data: body.object,
|
||||||
eventId: event.id
|
eventId: event.id
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,14 @@ module.exports = {
|
|||||||
async boost (req, res) {
|
async boost (req, res) {
|
||||||
const event_id = req.body.object.match(`${config.baseurl}/federation/m/(.*)`)[1]
|
const event_id = req.body.object.match(`${config.baseurl}/federation/m/(.*)`)[1]
|
||||||
const event = await Event.findByPk(event_id)
|
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]})
|
await event.update({ boost: [...event.boost, req.body.actor]})
|
||||||
res.sendStatus(201)
|
res.sendStatus(201)
|
||||||
},
|
},
|
||||||
async like (req, res) {
|
async like (req, res) {
|
||||||
const event_id = req.body.object.match(`${config.baseurl}/federation/m/(.*)`)[1]
|
const event_id = req.body.object.match(`${config.baseurl}/federation/m/(.*)`)[1]
|
||||||
const event = await Event.findByPk(event_id)
|
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]})
|
await event.update({ likes: [...event.likes, req.body.actor]})
|
||||||
res.sendStatus(201)
|
res.sendStatus(201)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,11 +49,8 @@ const Helpers = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
async sendEvent(event, user) {
|
async sendEvent(event, user) {
|
||||||
console.error('devo inviare un evento ai followers')
|
|
||||||
const followers = user.followers
|
const followers = user.followers
|
||||||
console.error('send to ', followers)
|
|
||||||
for(let follower of followers) {
|
for(let follower of followers) {
|
||||||
console.error('send message to ', follower)
|
|
||||||
const body = event.toAP(user.username, follower)
|
const body = event.toAP(user.username, follower)
|
||||||
body['@context'] = 'https://www.w3.org/ns/activitystreams'
|
body['@context'] = 'https://www.w3.org/ns/activitystreams'
|
||||||
Helpers.signAndSend(body, user, follower)
|
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/
|
// ref: https://blog.joinmastodon.org/2018/07/how-to-make-friends-and-verify-requests/
|
||||||
async verifySignature(req, res, next) {
|
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
|
// little hack -> https://github.com/joyent/node-http-signature/pull/83
|
||||||
req.headers.authorization = 'Signature ' + req.headers.signature
|
req.headers.authorization = 'Signature ' + req.headers.signature
|
||||||
const parsed = httpSignature.parseRequest(req)
|
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
|
// 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()
|
if (httpSignature.verifySignature(parsed, user.publicKey.publicKeyPem)) return next()
|
||||||
|
|
||||||
|
// ehm, TOFIX!!
|
||||||
|
return next()
|
||||||
// still not valid
|
// 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':
|
case 'Create':
|
||||||
// this is a reply
|
// this is a reply
|
||||||
if (b.object.type === 'Note' && b.object.inReplyTo) {
|
if (b.object.type === 'Note' && b.object.inReplyTo) {
|
||||||
Comments.create(b)
|
await Comments.create(b)
|
||||||
|
res.sendStatus(201)
|
||||||
} else {
|
} else {
|
||||||
console.error('Create what? ', b.object.type)
|
console.error('Create what? ', b.object.type)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user