mirror of
https://framagit.org/les/gancio.git
synced 2025-02-01 00:52:01 +01:00
48 lines
2.1 KiB
JavaScript
48 lines
2.1 KiB
JavaScript
const Event = require('../api/models/event')
|
|
const config = require('config')
|
|
const log = require('../log')
|
|
|
|
module.exports = {
|
|
async boost (req, res) {
|
|
const match = req.body.object.match(`${config.baseurl}/federation/m/(.*)`)
|
|
if (!match || match.length < 2) { return res.status(404).send('Event not found!') }
|
|
log.debug(`boost ${match[1]}`)
|
|
const event = await Event.findByPk(Number(match[1]))
|
|
if (!event) { return res.status(404).send('Event not found!') }
|
|
// TODO, has to be unique...
|
|
await event.update({ boost: [...event.boost, req.body.actor] })
|
|
res.sendStatus(201)
|
|
},
|
|
|
|
async unboost (req, res) {
|
|
const match = req.body.object.match(`${config.baseurl}/federation/m/(.*)`)
|
|
if (!match || match.length < 2) { return res.status(404).send('Event not found!') }
|
|
log.debug(`unboost ${match[1]}`)
|
|
const event = await Event.findByPk(Number(match[1]))
|
|
if (!event) { return res.status(404).send('Event not found!') }
|
|
await event.update({ boost: event.boost.filter(actor => actor !== req.body.actor) })
|
|
},
|
|
|
|
async bookmark (req, res) {
|
|
const match = req.body.object.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]))
|
|
log.debug(`${req.body.actor} bookmark ${event.title} (${event.likes.length})`)
|
|
if (!event) { return res.status(404).send('Event not found!') }
|
|
// TODO: has to be unique
|
|
await event.update({ likes: [...event.likes, req.body.actor] })
|
|
res.sendStatus(201)
|
|
},
|
|
|
|
async unbookmark (req, res) {
|
|
const body = req.body
|
|
const object = body.object
|
|
const match = object.object.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]))
|
|
log.debug(`${body.actor} unbookmark ${event.title} (${event.likes.length})`)
|
|
if (!event) { return res.status(404).send('Event not found!') }
|
|
await event.update({ likes: event.likes.filter(actor => actor !== body.actor) })
|
|
res.sendStatus(201)
|
|
}
|
|
}
|