mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: support ldjson with ActivityStreams profile in actor queries
This commit is contained in:
@@ -9,6 +9,7 @@ const request = require('../request');
|
|||||||
const db = require('../database');
|
const db = require('../database');
|
||||||
const ttl = require('../cache/ttl');
|
const ttl = require('../cache/ttl');
|
||||||
const user = require('../user');
|
const user = require('../user');
|
||||||
|
const activitypub = require('.');
|
||||||
|
|
||||||
const webfingerCache = ttl({ ttl: 1000 * 60 * 60 * 24 }); // 24 hours
|
const webfingerCache = ttl({ ttl: 1000 * 60 * 60 * 24 }); // 24 hours
|
||||||
|
|
||||||
@@ -57,7 +58,7 @@ Helpers.query = async (id) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse links to find actor endpoint
|
// Parse links to find actor endpoint
|
||||||
let actorUri = body.links.filter(link => link.type === 'application/activity+json' && link.rel === 'self');
|
let actorUri = body.links.filter(link => activitypub._constants.acceptableTypes.includes(link.type) && link.rel === 'self');
|
||||||
if (actorUri.length) {
|
if (actorUri.length) {
|
||||||
actorUri = actorUri.pop();
|
actorUri = actorUri.pop();
|
||||||
({ href: actorUri } = actorUri);
|
({ href: actorUri } = actorUri);
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ const ActivityPub = module.exports;
|
|||||||
ActivityPub._constants = Object.freeze({
|
ActivityPub._constants = Object.freeze({
|
||||||
uid: -2,
|
uid: -2,
|
||||||
publicAddress: 'https://www.w3.org/ns/activitystreams#Public',
|
publicAddress: 'https://www.w3.org/ns/activitystreams#Public',
|
||||||
|
acceptableTypes: [
|
||||||
|
'application/activity+json',
|
||||||
|
'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
||||||
|
],
|
||||||
});
|
});
|
||||||
ActivityPub._cache = requestCache;
|
ActivityPub._cache = requestCache;
|
||||||
|
|
||||||
|
|||||||
@@ -18,14 +18,10 @@ middleware.assertS2S = async function (req, res, next) {
|
|||||||
return next('route');
|
return next('route');
|
||||||
}
|
}
|
||||||
|
|
||||||
const acceptable = [
|
|
||||||
'application/activity+json',
|
|
||||||
'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
|
||||||
];
|
|
||||||
const pass = (accept && accept.split(',').some((value) => {
|
const pass = (accept && accept.split(',').some((value) => {
|
||||||
const parts = value.split(';').map(v => v.trim());
|
const parts = value.split(';').map(v => v.trim());
|
||||||
return acceptable.includes(value || parts[0]);
|
return activitypub._constants.acceptableTypes.includes(value || parts[0]);
|
||||||
})) || (contentType && acceptable.includes(contentType));
|
})) || (contentType && activitypub._constants.acceptableTypes.includes(contentType));
|
||||||
|
|
||||||
if (!pass) {
|
if (!pass) {
|
||||||
return next('route');
|
return next('route');
|
||||||
|
|||||||
Reference in New Issue
Block a user