fix: handle inbox GET, add missing activity type handlers
- Return 405 for GET on inbox endpoints instead of falling through to Indiekit's auth middleware (which redirects to login) - Add handlers for Update (refresh follower data), Block (remove follower), Add and Remove (Mastodon pin/unpin — ignored) - Bump to 1.0.1
This commit is contained in:
@@ -87,6 +87,30 @@ export default class ActivityPubEndpoint {
|
|||||||
return self._fedifyMiddleware(req, res, next);
|
return self._fedifyMiddleware(req, res, next);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Catch-all for federation paths that Fedify didn't handle (e.g. GET
|
||||||
|
// on inbox). Without this, they fall through to Indiekit's auth
|
||||||
|
// middleware and redirect to the login page.
|
||||||
|
router.all("/users/:identifier/inbox", (req, res) => {
|
||||||
|
res
|
||||||
|
.status(405)
|
||||||
|
.set("Allow", "POST")
|
||||||
|
.type("application/activity+json")
|
||||||
|
.json({
|
||||||
|
error: "Method Not Allowed",
|
||||||
|
message: "The inbox only accepts POST requests",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
router.all("/inbox", (req, res) => {
|
||||||
|
res
|
||||||
|
.status(405)
|
||||||
|
.set("Allow", "POST")
|
||||||
|
.type("application/activity+json")
|
||||||
|
.json({
|
||||||
|
error: "Method Not Allowed",
|
||||||
|
message: "The shared inbox only accepts POST requests",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
return router;
|
return router;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,14 +7,18 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
Accept,
|
Accept,
|
||||||
|
Add,
|
||||||
Announce,
|
Announce,
|
||||||
|
Block,
|
||||||
Create,
|
Create,
|
||||||
Delete,
|
Delete,
|
||||||
Follow,
|
Follow,
|
||||||
Like,
|
Like,
|
||||||
Move,
|
Move,
|
||||||
Note,
|
Note,
|
||||||
|
Remove,
|
||||||
Undo,
|
Undo,
|
||||||
|
Update,
|
||||||
} from "@fedify/fedify";
|
} from "@fedify/fedify";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -201,6 +205,46 @@ export function registerInboxListeners(inboxChain, options) {
|
|||||||
objectUrl: newActorUrl,
|
objectUrl: newActorUrl,
|
||||||
summary: `${oldActorUrl} moved to ${newActorUrl}`,
|
summary: `${oldActorUrl} moved to ${newActorUrl}`,
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
.on(Update, async (ctx, update) => {
|
||||||
|
// Remote actor updated their profile — refresh stored follower data
|
||||||
|
const actorObj = await update.getActor();
|
||||||
|
const actorUrl = actorObj?.id?.href || "";
|
||||||
|
if (!actorUrl) return;
|
||||||
|
|
||||||
|
const existing = await collections.ap_followers.findOne({ actorUrl });
|
||||||
|
if (existing) {
|
||||||
|
await collections.ap_followers.updateOne(
|
||||||
|
{ actorUrl },
|
||||||
|
{
|
||||||
|
$set: {
|
||||||
|
name:
|
||||||
|
actorObj.name?.toString() ||
|
||||||
|
actorObj.preferredUsername?.toString() ||
|
||||||
|
actorUrl,
|
||||||
|
handle: actorObj.preferredUsername?.toString() || "",
|
||||||
|
avatar: actorObj.icon
|
||||||
|
? (await actorObj.icon)?.url?.href || ""
|
||||||
|
: "",
|
||||||
|
updatedAt: new Date().toISOString(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on(Block, async (ctx, block) => {
|
||||||
|
// Remote actor blocked us — remove them from followers
|
||||||
|
const actorObj = await block.getActor();
|
||||||
|
const actorUrl = actorObj?.id?.href || "";
|
||||||
|
if (actorUrl) {
|
||||||
|
await collections.ap_followers.deleteOne({ actorUrl });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on(Add, async () => {
|
||||||
|
// Mastodon uses Add for pinning posts to featured collections — safe to ignore
|
||||||
|
})
|
||||||
|
.on(Remove, async () => {
|
||||||
|
// Mastodon uses Remove for unpinning posts from featured collections — safe to ignore
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@rmdes/indiekit-endpoint-activitypub",
|
"name": "@rmdes/indiekit-endpoint-activitypub",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.",
|
"description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"indiekit",
|
"indiekit",
|
||||||
|
|||||||
Reference in New Issue
Block a user