[AP] cleaner add and remove comments

This commit is contained in:
les
2019-09-11 13:12:05 +02:00
parent 939e19bb0d
commit 93baf01a55
7 changed files with 63 additions and 27 deletions

View File

@@ -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)
}
}