diff --git a/server/federation/ego.js b/server/federation/ego.js index 0af8858b..bd7c2fa9 100644 --- a/server/federation/ego.js +++ b/server/federation/ego.js @@ -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])) diff --git a/server/federation/events.js b/server/federation/events.js index ab6719fb..1ddc5927 100644 --- a/server/federation/events.js +++ b/server/federation/events.js @@ -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, diff --git a/server/federation/inbox.js b/server/federation/inbox.js index 1cca6978..7657db54 100644 --- a/server/federation/inbox.js +++ b/server/federation/inbox.js @@ -42,14 +42,19 @@ 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) { log.warn(`[FEDI] APUser not followed or not trusted`) 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': diff --git a/server/federation/resources.js b/server/federation/resources.js index ba3a4355..46eae823 100644 --- a/server/federation/resources.js +++ b/server/federation/resources.js @@ -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