check event on comment from federation
This commit is contained in:
@@ -1,25 +1,26 @@
|
||||
const { event: Event, comment: Comment } = require('../api/models')
|
||||
const config = require('config')
|
||||
const debug = require('debug')('fediverse:comment')
|
||||
|
||||
module.exports = {
|
||||
async create (body) {
|
||||
async create (req, res) {
|
||||
|
||||
//search for related event
|
||||
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)
|
||||
const event = await Event.findByPk(event_id)
|
||||
if (!event) {
|
||||
return console.error('event not found!')
|
||||
}
|
||||
if (!event) return res.status(404).send('Event not found!')
|
||||
debug('comment from %s to %s', req.body.actor, event.titles)
|
||||
|
||||
return await Comment.create({
|
||||
activitypub_id: body.object.id,
|
||||
data: body.object,
|
||||
eventId: event.id
|
||||
})
|
||||
await Comment.create({
|
||||
activitypub_id: body.object.id,
|
||||
data: body.object,
|
||||
eventId: event.id
|
||||
})
|
||||
|
||||
res.sendStatus(201)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user