Skip to content

Node.js based forum software built for the modern web

feat(activitypub): implement FEP-baf5 administrator collection and discovery

Julian Lam6a0c4fd76486
diff --git a/src/controllers/activitypub/actors.js b/src/controllers/activitypub/actors.js
index b6f861cebb..213a1c704b 100644
--- a/src/controllers/activitypub/actors.js
+++ b/src/controllers/activitypub/actors.js
@@ -28,11 +28,19 @@ Actors.application = async function (req, res) {
url: `${nconf.get('url')}/actor`,
inbox: `${nconf.get('url')}/inbox`,
outbox: `${nconf.get('url')}/outbox`,
+ attributedTo: `${nconf.get('url')}/actor/admins`,
type: 'Application',
name,
preferredUsername: nconf.get('url_parsed').hostname,
+ implements: [
+ {
+ href: 'https://w3id.org/fep/baf5',
+ name: 'FEP-baf5: Administrator Collection',
+ },
+ ],
+
publicKey: {
id: `${nconf.get('url')}/actor#key`,
owner: `${nconf.get('url')}/actor`,
diff --git a/src/controllers/activitypub/index.js b/src/controllers/activitypub/index.js
index 9158dfe102..a6c1716258 100644
--- a/src/controllers/activitypub/index.js
+++ b/src/controllers/activitypub/index.js
@@ -276,6 +276,27 @@ Controller.getCategoryModerators = async (req, res) => {
});
};
+Controller.getAdmins = async (req, res) => {
+ const adminUids = await user.getAdminsandGlobalMods();
+
+ const actors = await Promise.all(adminUids.map(async (uid) => {
+ return await activitypub.mocks.actors.user(uid);
+ }));
+
+ const collection = await activitypub.helpers.generateCollectionFromItems({
+ items: actors,
+ count: actors.length,
+ page: 1,
+ perPage: actors.length,
+ url: `${nconf.get('url')}/actor/admins`,
+ });
+
+ res.status(200).json({
+ '@context': 'https://www.w3.org/ns/activitystreams',
+ ...collection,
+ });
+};
+
Controller.postOutbox = async (req, res) => {
// This is a client-to-server feature so it is deliberately not implemented at this time.
res.sendStatus(405);
diff --git a/src/routes/activitypub.js b/src/routes/activitypub.js
index 59c14654eb..bb1fef1e93 100644
--- a/src/routes/activitypub.js
+++ b/src/routes/activitypub.js
@@ -33,6 +33,7 @@ module.exports = function (app, middleware, controllers) {
];
app.get('/actor', middlewares, helpers.tryRoute(controllers.activitypub.actors.application));
+ app.get('/actor/admins', middlewares, helpers.tryRoute(controllers.activitypub.getAdmins));
app.post('/inbox', [...middlewares, ...inboxMiddlewares], helpers.tryRoute(controllers.activitypub.postInbox));
app.get('/uid/:uid', [...middlewares, middleware.assert.user, middleware.canViewUsers], helpers.tryRoute(controllers.activitypub.actors.user));