fixes profile discovery

This commit is contained in:
Christian Beutel
2025-08-22 12:32:37 +02:00
parent f9451d73bf
commit e375747422

View File

@@ -16,34 +16,48 @@ export async function GET(event: RequestEvent) {
try { try {
const resource = event.url.searchParams.get("resource") const resource = event.url.searchParams.get("resource")
if (!resource || !resource.startsWith("acct:")) { if (!resource) {
return error(400, "Bad request"); return error(400, "Bad request");
} }
let iri: string;
let profile: string;
let handle: string;
const hostname = new URL(env.ORIGIN).hostname; const hostname = new URL(env.ORIGIN).hostname;
const [username, domain] = splitUsername(resource.replace("acct:", "")) if (resource.startsWith("acct:")) {
const [username, domain] = splitUsername(resource.replace("acct:", ""))
if (hostname !== domain) { if (hostname !== domain) {
return json({ message: "Not found" }, { status: 404 }); return json({ message: "Not found" }, { status: 404 });
}
iri = `${env.ORIGIN}/api/v1/activitypub/user/${username.toLowerCase()}`
profile = `${env.ORIGIN}/profile/@${username.toLowerCase()}`
handle = resource;
} else if (new RegExp(`${env.ORIGIN}\/profile\/@.*`, "g").test(resource)) {
const username = resource.split('/').pop()!.replace("@", "")
iri = `${env.ORIGIN}/api/v1/activitypub/user/${username.toLowerCase()}`
profile = `${env.ORIGIN}/profile/@${username.toLowerCase()}`
handle = `@${username}@${hostname}`
} else {
return error(400, "Bad request");
} }
const id = `${env.ORIGIN}/api/v1/activitypub/user/${username.toLowerCase()}` const actor = await event.locals.pb.collection("activitypub_actors").getFirstListItem(`iri='${iri}'`)
const actor = await event.locals.pb.collection("activitypub_actors").getFirstListItem(`iri='${id}'`)
const r: WebfingerResponse = { const r: WebfingerResponse = {
subject: resource, subject: handle,
aliases: [id], aliases: [handle, profile],
links: [ links: [
{ {
rel: 'self', rel: 'self',
type: 'application/activity+json', type: 'application/activity+json',
href: id, href: iri,
}, },
{ {
rel: 'http://webfinger.net/rel/profile-page', rel: 'http://webfinger.net/rel/profile-page',
type: 'text/html', type: 'text/html',
href: `${env.ORIGIN}/profile/@${username.toLowerCase()}`, href: profile,
}, },
], ],
} }