Reimplement well-known WebFinger to support multiple aliases and specify profile-page

This commit is contained in:
Niko 2022-02-09 14:15:06 +01:00
parent a22f8a352b
commit d775e56c35
3 changed files with 41 additions and 0 deletions

11
api/src/activity/index.js Normal file
View File

@ -0,0 +1,11 @@
global.replaceImpl = (funcs, name, withFunc) => {
for (var i = 0; i < funcs.length; i++)
if (funcs[i].name === name)
funcs[i] = withFunc
}
module.exports = {
rewriteImplementations: () => {
require('./well-known.js').init()
},
}

View File

@ -0,0 +1,28 @@
module.exports = {
init: () => {
replaceImpl(apex.net.webfinger.get, 'respondWebfinger', (req, res, next) => {
const resource = req.query.resource
const actorObj = res.locals.apex.target
if (!actorObj) {
return res.status(404).send(`${resource} not found`)
}
const profilePage = `https://${apex.domain}/@${actorObj.preferredUsername[0]}`
return res.json({
subject: resource,
aliases: [ profilePage, actorObj.id ],
links: [
{
rel: 'http://webfinger.net/rel/profile-page',
type: 'text/html',
href: profilePage
},
{
rel: 'self',
type: 'application/activity+json',
href: actorObj.id
}
]
})
})
},
}

View File

@ -1,5 +1,6 @@
const express = require('express') const express = require('express')
const ActivitypubExpress = require('activitypub-express') const ActivitypubExpress = require('activitypub-express')
const activity = require('./activity/index.js')
const port = 8080 const port = 8080
const app = express() const app = express()
@ -43,6 +44,7 @@ app.use(require('cookie-parser')())
app.use(bodyParser.urlencoded({ extended: true })) app.use(bodyParser.urlencoded({ extended: true }))
// define routes using prepacakged middleware collections // define routes using prepacakged middleware collections
activity.rewriteImplementations()
app.route(routes.inbox) app.route(routes.inbox)
.get(apex.net.inbox.get) .get(apex.net.inbox.get)
.post(apex.net.inbox.post) .post(apex.net.inbox.post)