From 7e0abcbc17510a6f792f5e85c86e12c913cec922 Mon Sep 17 00:00:00 2001 From: Niko Date: Wed, 9 Feb 2022 19:46:08 +0100 Subject: [PATCH] Add actor URL redirection to /@username when Accepts text/html --- api/src/activity/actor.js | 18 ++++++++++++++++++ api/src/activity/index.js | 1 + 2 files changed, 19 insertions(+) create mode 100644 api/src/activity/actor.js diff --git a/api/src/activity/actor.js b/api/src/activity/actor.js new file mode 100644 index 0000000..4e3d826 --- /dev/null +++ b/api/src/activity/actor.js @@ -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() + }) + }, +} diff --git a/api/src/activity/index.js b/api/src/activity/index.js index 09b873e..a9be412 100644 --- a/api/src/activity/index.js +++ b/api/src/activity/index.js @@ -7,5 +7,6 @@ global.replaceImpl = (funcs, name, withFunc) => { module.exports = { rewriteImplementations: () => { require('./well-known.js').init() + require('./actor.js').init() }, }