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:
+13
-4
@@ -155,10 +155,19 @@ export async function extractObjectData(object, options = {}) {
|
||||
const attrIds = object.attributionIds;
|
||||
if (attrIds && attrIds.length > 0) {
|
||||
const authorUrl = attrIds[0].href;
|
||||
const authorHostname = new URL(authorUrl).hostname;
|
||||
// Extract username from URL pattern like /users/name or /@name
|
||||
const pathMatch = new URL(authorUrl).pathname.match(/\/@?([^/]+)/);
|
||||
const username = pathMatch ? pathMatch[1] : "";
|
||||
const parsedUrl = new URL(authorUrl);
|
||||
const authorHostname = parsedUrl.hostname;
|
||||
// Extract username from common URL patterns:
|
||||
// /@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 = {
|
||||
name: username || authorHostname,
|
||||
url: authorUrl,
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"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.",
|
||||
"keywords": [
|
||||
"indiekit",
|
||||
|
||||
Reference in New Issue
Block a user