mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: update proceedOnActivityPub middleware to handle how Mastodon doesn't send the 'Accepts' header
This commit is contained in:
@@ -101,7 +101,7 @@ Controller.getInbox = async (req, res) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Controller.postInbox = async (req, res) => {
|
Controller.postInbox = async (req, res) => {
|
||||||
// Note: internal-only, hence no exposure via src/api
|
// Note: underlying methods are internal use only, hence no exposure via src/api
|
||||||
switch (req.body.type) {
|
switch (req.body.type) {
|
||||||
case 'Follow': {
|
case 'Follow': {
|
||||||
await activitypub.inbox.follow(req.body.actor.name, req.body.object.name);
|
await activitypub.inbox.follow(req.body.actor.name, req.body.object.name);
|
||||||
|
|||||||
@@ -310,8 +310,8 @@ middleware.handleMultipart = (req, res, next) => {
|
|||||||
middleware.proceedOnActivityPub = (req, res, next) => {
|
middleware.proceedOnActivityPub = (req, res, next) => {
|
||||||
// For whatever reason, express accepts does not recognize "profile" as a valid differentiator
|
// For whatever reason, express accepts does not recognize "profile" as a valid differentiator
|
||||||
// Therefore, manual header parsing is used here.
|
// Therefore, manual header parsing is used here.
|
||||||
const { accept } = req.headers;
|
const { accept, 'content-type': contentType } = req.headers;
|
||||||
if (!accept || !meta.config.activitypubEnabled) {
|
if (!meta.config.activitypubEnabled || !(accept && contentType)) {
|
||||||
return next('route');
|
return next('route');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,10 +319,10 @@ middleware.proceedOnActivityPub = (req, res, next) => {
|
|||||||
'application/activity+json',
|
'application/activity+json',
|
||||||
'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
||||||
];
|
];
|
||||||
const pass = 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 acceptable.includes(value || parts[0]);
|
||||||
});
|
})) || (contentType && acceptable.includes(contentType));
|
||||||
|
|
||||||
if (!pass) {
|
if (!pass) {
|
||||||
return next('route');
|
return next('route');
|
||||||
|
|||||||
Reference in New Issue
Block a user