mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-11-03 04:25:55 +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 ttl = require('../cache/ttl');
 | 
			
		||||
const user = require('../user');
 | 
			
		||||
const activitypub = require('.');
 | 
			
		||||
 | 
			
		||||
const webfingerCache = ttl({ ttl: 1000 * 60 * 60 * 24 }); // 24 hours
 | 
			
		||||
 | 
			
		||||
@@ -57,7 +58,7 @@ Helpers.query = async (id) => {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 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) {
 | 
			
		||||
		actorUri = actorUri.pop();
 | 
			
		||||
		({ href: actorUri } = actorUri);
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,10 @@ const ActivityPub = module.exports;
 | 
			
		||||
ActivityPub._constants = Object.freeze({
 | 
			
		||||
	uid: -2,
 | 
			
		||||
	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;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -18,14 +18,10 @@ middleware.assertS2S = async function (req, res, next) {
 | 
			
		||||
		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 parts = value.split(';').map(v => v.trim());
 | 
			
		||||
		return acceptable.includes(value || parts[0]);
 | 
			
		||||
	})) || (contentType && acceptable.includes(contentType));
 | 
			
		||||
		return activitypub._constants.acceptableTypes.includes(value || parts[0]);
 | 
			
		||||
	})) || (contentType && activitypub._constants.acceptableTypes.includes(contentType));
 | 
			
		||||
 | 
			
		||||
	if (!pass) {
 | 
			
		||||
		return next('route');
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user