fix event content-type

This commit is contained in:
lesion 2022-06-01 14:13:58 +02:00
parent 9b22892466
commit 0764617e5d
No known key found for this signature in database
GPG key ID: 352918250B012177
3 changed files with 13 additions and 5 deletions

View file

@ -154,6 +154,7 @@ if (config.status !== 'READY') {
api.get('/place/:placeName/events', cors, placeController.getEvents)
api.get('/place/all', isAdmin, placeController.getAll)
api.get('/place', cors, placeController.get)
api.put('/place', isAdmin, placeController.updatePlace)

View file

@ -20,7 +20,7 @@ const log = require('../log')
router.use(cors())
// is federation enabled? middleware
router.use((req, res, next) => {
router.use((_req, res, next) => {
if (settingsController.settings.enable_federation) { return next() }
log.debug('Federation disabled!')
return res.status(401).send('Federation disabled')
@ -29,14 +29,20 @@ router.use((req, res, next) => {
router.use(express.json({ type: ['application/json', 'application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'] }))
router.get('/m/:event_id', async (req, res) => {
const settingsController = require('../api/controller/settings')
log.debug('[AP] Get event details ')
const event_id = req.params.event_id
if (req.accepts('html')) { return res.redirect(301, `/event/${event_id}`) }
const acceptHtml = req.accepts('html', 'application/activity+json') === 'html'
if (acceptHtml) { return res.redirect(301, `/event/${event_id}`) }
const event = await Event.findByPk(req.params.event_id, { include: [User, Tag, Place] })
if (!event) { return res.status(404).send('Not found') }
return res.json(event.toAP(settingsController.settings.instance_name, settingsController.settings.instance_locale))
const eventAp = event.toAP(settingsController.settings.instance_name, settingsController.settings.instance_locale)
eventAp['@context'] = [
"https://www.w3.org/ns/activitystreams"
]
res.type('application/activity+json; charset=utf-8')
return res.json(eventAp)
})
// get any message coming from federation

View file

@ -224,7 +224,8 @@ module.exports = {
},
async APRedirect (req, res, next) {
if (!req.accepts('html')) {
const acceptJson = req.accepts('html', 'application/activity+json') === 'application/activity+json'
if (acceptJson) {
const eventController = require('../server/api/controller/event')
const event = await eventController._get(req.params.slug)
if (event) {