fix: extract correct username from /users/name URL pattern

The attributionIds fallback was matching "users" from /users/NatalieDavis
instead of the actual username. Now handles /@name, /users/name, and
/ap/users/id patterns correctly.
This commit is contained in:
Ricardo
2026-02-21 15:00:29 +01:00
parent d395a1cc24
commit 94844d5b4d
2 changed files with 14 additions and 5 deletions
+13 -4
View File
@@ -155,10 +155,19 @@ export async function extractObjectData(object, options = {}) {
const attrIds = object.attributionIds; const attrIds = object.attributionIds;
if (attrIds && attrIds.length > 0) { if (attrIds && attrIds.length > 0) {
const authorUrl = attrIds[0].href; const authorUrl = attrIds[0].href;
const authorHostname = new URL(authorUrl).hostname; const parsedUrl = new URL(authorUrl);
// Extract username from URL pattern like /users/name or /@name const authorHostname = parsedUrl.hostname;
const pathMatch = new URL(authorUrl).pathname.match(/\/@?([^/]+)/); // Extract username from common URL patterns:
const username = pathMatch ? pathMatch[1] : ""; // /@username, /users/username, /ap/users/12345/
const pathname = parsedUrl.pathname;
let username = "";
const atPattern = pathname.match(/\/@([^/]+)/);
const usersPattern = pathname.match(/\/users\/([^/]+)/);
if (atPattern) {
username = atPattern[1];
} else if (usersPattern) {
username = usersPattern[1];
}
author = { author = {
name: username || authorHostname, name: username || authorHostname,
url: authorUrl, url: authorUrl,
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@rmdes/indiekit-endpoint-activitypub", "name": "@rmdes/indiekit-endpoint-activitypub",
"version": "1.1.6", "version": "1.1.7",
"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",