mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-01 04:09:51 +01:00
feat: activitypub actor endpoint for user accounts
This commit is contained in:
41
src/controllers/activitypub.js
Normal file
41
src/controllers/activitypub.js
Normal file
@@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
|
||||
const nconf = require('nconf');
|
||||
|
||||
const user = require('../user');
|
||||
const activitypub = require('../activitypub');
|
||||
|
||||
const Controller = module.exports;
|
||||
|
||||
Controller.getActor = async (req, res) => {
|
||||
// todo: view:users priv gate
|
||||
const { userslug } = req.params;
|
||||
const { uid } = res.locals;
|
||||
const { username, aboutme, picture, 'cover:url': cover } = await user.getUserData(uid);
|
||||
const publicKey = await activitypub.getPublicKey(uid);
|
||||
|
||||
res.status(200).json({
|
||||
'@context': [
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
'https://w3id.org/security/v1',
|
||||
],
|
||||
id: `${nconf.get('url')}/user/${userslug}`,
|
||||
url: `${nconf.get('url')}/user/${userslug}`,
|
||||
followers: `${nconf.get('url')}/user/${userslug}/followers`,
|
||||
following: `${nconf.get('url')}/user/${userslug}/following`,
|
||||
inbox: `${nconf.get('url')}/user/${userslug}/inbox`,
|
||||
outbox: `${nconf.get('url')}/user/${userslug}/outbox`,
|
||||
|
||||
type: 'Person',
|
||||
preferredUsername: username,
|
||||
summary: aboutme,
|
||||
icon: picture ? `${nconf.get('url')}${picture}` : null,
|
||||
image: cover ? `${nconf.get('url')}${cover}` : null,
|
||||
|
||||
publicKey: {
|
||||
id: `${nconf.get('url')}/user/${userslug}`,
|
||||
owner: `${nconf.get('url')}/user/${userslug}#key`,
|
||||
publicKeyPem: publicKey,
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -13,6 +13,7 @@ const Controllers = module.exports;
|
||||
|
||||
Controllers.ping = require('./ping');
|
||||
Controllers['well-known'] = require('./well-known');
|
||||
Controllers.activitypub = require('./activitypub');
|
||||
Controllers.home = require('./home');
|
||||
Controllers.topics = require('./topics');
|
||||
Controllers.posts = require('./posts');
|
||||
|
||||
@@ -16,7 +16,6 @@ Controller.webfinger = async (req, res) => {
|
||||
}
|
||||
|
||||
const canView = await privileges.global.can('view:users', req.uid);
|
||||
console.log('canView', canView, req.uid);
|
||||
if (!canView) {
|
||||
return res.sendStatus(403);
|
||||
}
|
||||
@@ -41,6 +40,11 @@ Controller.webfinger = async (req, res) => {
|
||||
type: 'text/html',
|
||||
href: `${nconf.get('url')}/user/${slug}`,
|
||||
},
|
||||
{
|
||||
rel: 'self',
|
||||
type: 'application/activity+json',
|
||||
href: `${nconf.get('url')}/user/${slug}`, // actor
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user