[AP] cleaner add and remove comments
This commit is contained in:
@@ -7,14 +7,19 @@ module.exports = {
|
||||
const body = req.body
|
||||
//search for related event
|
||||
const inReplyTo = body.object.inReplyTo
|
||||
const match = inReplyTo.match(`${config.baseurl}/federation/m/(.*)`)
|
||||
if (!match || match.length<2) return res.status(404).send('Event not found!')
|
||||
const match = inReplyTo.match('.*\/federation\/m\/(.*)')
|
||||
console.error('inReplyTo', inReplyTo)
|
||||
console.error('match', match)
|
||||
if (!match || match.length<2) {
|
||||
debug("Comment not found %s", inReplyTo)
|
||||
return res.status(404).send('Event not found!')
|
||||
}
|
||||
let event = await Event.findByPk(Number(match[1]))
|
||||
|
||||
debug('comment coming for %s', inReplyTo)
|
||||
if (!event) {
|
||||
// in reply to another comment...
|
||||
const comment = await Comment.findByPk(inReplyTo, { include: [Event] })
|
||||
const comment = await Comment.findOne({ where: { activitypub_id: inReplyTo }, include: [Event] })
|
||||
if (!comment) return res.status(404).send('Not found')
|
||||
event = comment.event
|
||||
}
|
||||
@@ -27,6 +32,16 @@ module.exports = {
|
||||
})
|
||||
|
||||
res.sendStatus(201)
|
||||
},
|
||||
|
||||
async remove (req, res) {
|
||||
const comment = await Comment.findOne({where: { activitypub_id: req.body.object.id }})
|
||||
if (!comment) {
|
||||
debug('Comment %s not found', req.body.object.id)
|
||||
return res.status(404).send('Not found')
|
||||
}
|
||||
await comment.destroy()
|
||||
debug('Comment %s removed!', req.body.object.id)
|
||||
return res.sendStatus(201)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user