/event redirect to AP repr when accept application/json
This commit is contained in:
@@ -85,11 +85,26 @@ const eventController = {
|
|||||||
res.json(place)
|
res.json(place)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async _get(slug) {
|
||||||
|
// retrocompatibility, old events URL does not use slug, use id as fallback
|
||||||
|
const id = Number(slug) || -1
|
||||||
|
return Event.findOne({
|
||||||
|
where: {
|
||||||
|
[Op.or]: {
|
||||||
|
slug,
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
async get (req, res) {
|
async get (req, res) {
|
||||||
const format = req.params.format || 'json'
|
const format = req.params.format || 'json'
|
||||||
const is_admin = req.user && req.user.is_admin
|
const is_admin = req.user && req.user.is_admin
|
||||||
const slug = req.params.event_id
|
const slug = req.params.event_slug
|
||||||
const id = Number(req.params.event_id) || -1
|
|
||||||
|
// retrocompatibility, old events URL does not use slug, use id as fallback
|
||||||
|
const id = Number(slug) || -1
|
||||||
let event
|
let event
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -301,7 +316,7 @@ const eventController = {
|
|||||||
focalpoint = [parseFloat(focalpoint[0]).toFixed(2), parseFloat(focalpoint[1]).toFixed(2)]
|
focalpoint = [parseFloat(focalpoint[0]).toFixed(2), parseFloat(focalpoint[1]).toFixed(2)]
|
||||||
eventDetails.media = [{
|
eventDetails.media = [{
|
||||||
url,
|
url,
|
||||||
name: body.image_name || '',
|
name: body.image_name || body.title || '',
|
||||||
focalpoint: [parseFloat(focalpoint[0]), parseFloat(focalpoint[1])]
|
focalpoint: [parseFloat(focalpoint[0]), parseFloat(focalpoint[1])]
|
||||||
}]
|
}]
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -214,7 +214,20 @@ module.exports = {
|
|||||||
cursor = cursor.hour(date.hour()).minute(date.minute()).second(0)
|
cursor = cursor.hour(date.hour()).minute(date.minute()).second(0)
|
||||||
log.debug(cursor)
|
log.debug(cursor)
|
||||||
return cursor
|
return cursor
|
||||||
|
},
|
||||||
|
|
||||||
|
async APRedirect (req, res, next) {
|
||||||
|
const accepted = req.accepts('html', 'application/json', 'application/activity+json', 'application/ld+json' )
|
||||||
|
if (accepted && accepted !== 'html') {
|
||||||
|
const eventController = require('../server/api/controller/event')
|
||||||
|
try {
|
||||||
|
const event = await eventController._get(req.params.slug)
|
||||||
|
if (event) {
|
||||||
|
return res.redirect(`/federation/m/${event.id}`)
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,9 +35,10 @@ if (!config.firstrun) {
|
|||||||
|
|
||||||
// rss/ics/atom feed
|
// rss/ics/atom feed
|
||||||
app.get('/feed/:type', cors(), exportController.export)
|
app.get('/feed/:type', cors(), exportController.export)
|
||||||
|
|
||||||
// federation api / activitypub / webfinger / nodeinfo
|
|
||||||
app.use('/.well-known', webfinger)
|
app.use('/.well-known', webfinger)
|
||||||
|
|
||||||
|
app.use('/event/:slug', helpers.APRedirect)
|
||||||
|
// federation api / activitypub / webfinger / nodeinfo
|
||||||
app.use('/federation', federation)
|
app.use('/federation', federation)
|
||||||
app.use(spamFilter)
|
app.use(spamFilter)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user