diff --git a/src/activitypub/helpers.js b/src/activitypub/helpers.js index e77a5280d8..fb0504e386 100644 --- a/src/activitypub/helpers.js +++ b/src/activitypub/helpers.js @@ -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); diff --git a/src/activitypub/index.js b/src/activitypub/index.js index 54ab2c64ba..8cf1066886 100644 --- a/src/activitypub/index.js +++ b/src/activitypub/index.js @@ -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; diff --git a/src/middleware/activitypub.js b/src/middleware/activitypub.js index 81f104dea1..bcb6dd9b1d 100644 --- a/src/middleware/activitypub.js +++ b/src/middleware/activitypub.js @@ -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');