check event on comment from federation

This commit is contained in:
les 2019-08-09 14:37:51 +02:00
parent 181557aa43
commit f722187c65
3 changed files with 16 additions and 16 deletions

View file

@ -1,25 +1,26 @@
const { event: Event, comment: Comment } = require('../api/models') const { event: Event, comment: Comment } = require('../api/models')
const config = require('config') const config = require('config')
const debug = require('debug')('fediverse:comment')
module.exports = { module.exports = {
async create (body) { async create (req, res) {
//search for related event //search for related event
const inReplyTo = body.object.inReplyTo const inReplyTo = body.object.inReplyTo
const event_id = inReplyTo.match(`${config.baseurl}/federation/m/(.*)`)[1] const match = inReplyTo.match(`${config.baseurl}/federation/m/(.*)`)
if (!match || match.length<2) return res.status(404).send('Event not found!')
const event = await Event.findByPk(Number(match[1]))
console.error(event_id) if (!event) return res.status(404).send('Event not found!')
const event = await Event.findByPk(event_id) debug('comment from %s to %s', req.body.actor, event.titles)
if (!event) {
return console.error('event not found!')
}
return await Comment.create({ 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
}) })
res.sendStatus(201)
} }
} }

View file

@ -62,8 +62,7 @@ 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) {
await Comments.create(b) await Comments.create(req, res)
res.status(201).send()
} else { } else {
console.error('Create what? ', b.object.type) console.error('Create what? ', b.object.type)
} }

View file

@ -96,12 +96,12 @@ router.get('/nodeinfo', async (req, res) => {
// Handle 404 // Handle 404
router.use(function(req, res) { router.use(function(req, res) {
res.send('404: Page not Found', 404) res.status(404).send('404: Page not Found')
}) })
// Handle 500 // Handle 500
router.use(function(error, req, res, next) { router.use(function(error, req, res, next) {
res.send('500: Internal Server Error', 500) res.status(500).send('500: Internal Server Error')
}) })
module.exports = router module.exports = router