Add actor URL redirection to /@username when Accepts text/html

This commit is contained in:
Niko 2022-02-09 19:46:08 +01:00
parent 83e34a6dd4
commit 7e0abcbc17
2 changed files with 19 additions and 0 deletions

18
api/src/activity/actor.js Normal file
View File

@ -0,0 +1,18 @@
module.exports = {
init: () => {
apex.net.actor.get.unshift(async (req, res, next) => {
if (req.accepts('text/html')) {
const actor = req.params[apex.actorParam]
const actorIRI = apex.utils.usernameToIRI(actor)
let actorObj
try {
actorObj = await apex.store.getObject(actorIRI)
if (actorObj !== null &&
actorObj.preferredUsername !== undefined)
return res.redirect(`/@${actorObj.preferredUsername[0]}`)
} catch (err) {}
}
next()
})
},
}

View File

@ -7,5 +7,6 @@ global.replaceImpl = (funcs, name, withFunc) => {
module.exports = {
rewriteImplementations: () => {
require('./well-known.js').init()
require('./actor.js').init()
},
}