AP improvements

This commit is contained in:
lesion 2024-01-11 13:00:39 +01:00
parent e186bc1546
commit 4e61b483c1
No known key found for this signature in database
GPG key ID: 352918250B012177
4 changed files with 23 additions and 10 deletions

View file

@ -4,18 +4,25 @@ 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('[FEDI] %s', JSON.stringify(req.body))
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]}`)
const event = await Event.findByPk(Number(match[1]))
if (!event) { return res.status(404).send('Event not found!') }
// TODO, has to be unique...
if (!event) {
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] })
res.sendStatus(201)
},
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!') }
log.info(`unboost ${match[1]}`)
const event = await Event.findByPk(Number(match[1]))

View file

@ -13,6 +13,8 @@ module.exports = {
const APEvent = req.body?.object
console.error(JSON.stringify(req.body))
// validate coming events
const required_fields = ['name', 'startTime']
let missing_field = required_fields.find(required_field => !APEvent[required_field])
@ -31,7 +33,7 @@ module.exports = {
const place = await eventController._findOrCreatePlace({
place_name: APEvent.location?.name,
place_address: APEvent.location?.address,
place_address: APEvent.location?.address?.streetAddress ?? APEvent.location?.address
})
let media = []
@ -56,7 +58,7 @@ module.exports = {
title: APEvent.name.trim(),
start_datetime: dayjs(APEvent.startTime).unix(),
end_datetime: APEvent?.endTime ? dayjs(APEvent.endTime).unix() : null,
description: helpers.sanitizeHTML(linkifyHtml(APEvent.content)),
description: helpers.sanitizeHTML(linkifyHtml(APEvent?.content ?? APEvent?.summary ?? '')),
media,
is_visible: true,
ap_id,

View file

@ -42,7 +42,10 @@ module.exports = async (req, res) => {
Ego.bookmark(req, res)
break
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)
} else if (message.object?.type === 'Event') {
if (!res.locals.fedi_user.following || !res.locals.fedi_user.trusted) {
@ -50,6 +53,8 @@ module.exports = async (req, res) => {
return res.sendStatus(404)
}
await Events.remove(req, res)
} else {
log.debug('[FEDI] Delete of unknown object: %s', JSON.stringify(message.object))
}
break
case 'Update':

View file

@ -92,7 +92,6 @@ module.exports = {
})
if (!resource) {
log.info(`[FEDI] Comment not found`)
log.debug(req.body)
return res.status(404).send('Not found')
}
// check if fedi_user that requested resource removal