mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 16:42:22 +01:00
AP improvements
This commit is contained in:
parent
e186bc1546
commit
4e61b483c1
4 changed files with 23 additions and 10 deletions
|
@ -4,18 +4,25 @@ const log = require('../log')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
async boost (req, res) {
|
async boost (req, res) {
|
||||||
const match = req.body.object.match(`${config.baseurl}/federation/m/(.*)`)
|
log.debug('[FEDI] %s', JSON.stringify(req.body))
|
||||||
if (!match || match.length < 2) { return res.status(404).send('Event not found!') }
|
const match = req.body?.object?.match(`${config.baseurl}/federation/m/(.*)`)
|
||||||
|
if (!match || match.length < 2) {
|
||||||
|
log.debug('[FEDI] Boosted something not local: %s', req.body.object)
|
||||||
|
return res.status(404).send('Event not found!')
|
||||||
|
}
|
||||||
log.info(`[FEDI] boost ${match[1]}`)
|
log.info(`[FEDI] boost ${match[1]}`)
|
||||||
const event = await Event.findByPk(Number(match[1]))
|
const event = await Event.findByPk(Number(match[1]))
|
||||||
if (!event) { return res.status(404).send('Event not found!') }
|
if (!event) {
|
||||||
// TODO, has to be unique...
|
log.debug('[FEDI] Boosted event not found: %s', req.body.object)
|
||||||
|
return res.status(404).send('Event not found!')
|
||||||
|
}
|
||||||
|
|
||||||
await event.update({ boost: [...event.boost, req.body.actor] })
|
await event.update({ boost: [...event.boost, req.body.actor] })
|
||||||
res.sendStatus(201)
|
res.sendStatus(201)
|
||||||
},
|
},
|
||||||
|
|
||||||
async unboost (req, res) {
|
async unboost (req, res) {
|
||||||
const match = req.body.object.match(`${config.baseurl}/federation/m/(.*)`)
|
const match = req.body?.object?.match(`${config.baseurl}/federation/m/(.*)`)
|
||||||
if (!match || match.length < 2) { return res.status(404).send('Event not found!') }
|
if (!match || match.length < 2) { return res.status(404).send('Event not found!') }
|
||||||
log.info(`unboost ${match[1]}`)
|
log.info(`unboost ${match[1]}`)
|
||||||
const event = await Event.findByPk(Number(match[1]))
|
const event = await Event.findByPk(Number(match[1]))
|
||||||
|
|
|
@ -13,6 +13,8 @@ module.exports = {
|
||||||
|
|
||||||
const APEvent = req.body?.object
|
const APEvent = req.body?.object
|
||||||
|
|
||||||
|
console.error(JSON.stringify(req.body))
|
||||||
|
|
||||||
// validate coming events
|
// validate coming events
|
||||||
const required_fields = ['name', 'startTime']
|
const required_fields = ['name', 'startTime']
|
||||||
let missing_field = required_fields.find(required_field => !APEvent[required_field])
|
let missing_field = required_fields.find(required_field => !APEvent[required_field])
|
||||||
|
@ -31,7 +33,7 @@ module.exports = {
|
||||||
|
|
||||||
const place = await eventController._findOrCreatePlace({
|
const place = await eventController._findOrCreatePlace({
|
||||||
place_name: APEvent.location?.name,
|
place_name: APEvent.location?.name,
|
||||||
place_address: APEvent.location?.address,
|
place_address: APEvent.location?.address?.streetAddress ?? APEvent.location?.address
|
||||||
})
|
})
|
||||||
|
|
||||||
let media = []
|
let media = []
|
||||||
|
@ -56,7 +58,7 @@ module.exports = {
|
||||||
title: APEvent.name.trim(),
|
title: APEvent.name.trim(),
|
||||||
start_datetime: dayjs(APEvent.startTime).unix(),
|
start_datetime: dayjs(APEvent.startTime).unix(),
|
||||||
end_datetime: APEvent?.endTime ? dayjs(APEvent.endTime).unix() : null,
|
end_datetime: APEvent?.endTime ? dayjs(APEvent.endTime).unix() : null,
|
||||||
description: helpers.sanitizeHTML(linkifyHtml(APEvent.content)),
|
description: helpers.sanitizeHTML(linkifyHtml(APEvent?.content ?? APEvent?.summary ?? '')),
|
||||||
media,
|
media,
|
||||||
is_visible: true,
|
is_visible: true,
|
||||||
ap_id,
|
ap_id,
|
||||||
|
|
|
@ -42,14 +42,19 @@ module.exports = async (req, res) => {
|
||||||
Ego.bookmark(req, res)
|
Ego.bookmark(req, res)
|
||||||
break
|
break
|
||||||
case 'Delete':
|
case 'Delete':
|
||||||
if (['Note','Tombstone'].includes(message.object?.type)) {
|
if (message.object?.type === 'Tombstone') {
|
||||||
|
message.object.type = message.object?.formerType ?? 'Tombstone'
|
||||||
|
}
|
||||||
|
if (message.object?.type==='Note') {
|
||||||
await Resources.remove(req, res)
|
await Resources.remove(req, res)
|
||||||
} else if (message.object?.type === 'Event') {
|
} else if (message.object?.type === 'Event') {
|
||||||
if (!res.locals.fedi_user.following || !res.locals.fedi_user.trusted) {
|
if (!res.locals.fedi_user.following || !res.locals.fedi_user.trusted) {
|
||||||
log.warn(`[FEDI] APUser not followed or not trusted`)
|
log.warn(`[FEDI] APUser not followed or not trusted`)
|
||||||
return res.sendStatus(404)
|
return res.sendStatus(404)
|
||||||
}
|
}
|
||||||
await Events.remove(req, res)
|
await Events.remove(req, res)
|
||||||
|
} else {
|
||||||
|
log.debug('[FEDI] Delete of unknown object: %s', JSON.stringify(message.object))
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'Update':
|
case 'Update':
|
||||||
|
|
|
@ -92,7 +92,6 @@ module.exports = {
|
||||||
})
|
})
|
||||||
if (!resource) {
|
if (!resource) {
|
||||||
log.info(`[FEDI] Comment not found`)
|
log.info(`[FEDI] Comment not found`)
|
||||||
log.debug(req.body)
|
|
||||||
return res.status(404).send('Not found')
|
return res.status(404).send('Not found')
|
||||||
}
|
}
|
||||||
// check if fedi_user that requested resource removal
|
// check if fedi_user that requested resource removal
|
||||||
|
|
Loading…
Reference in a new issue