fixes profile discovery
This commit is contained in:
@@ -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;
|
||||||
|
if (resource.startsWith("acct:")) {
|
||||||
const [username, domain] = splitUsername(resource.replace("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;
|
||||||
|
|
||||||
const id = `${env.ORIGIN}/api/v1/activitypub/user/${username.toLowerCase()}`
|
} 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 actor = await event.locals.pb.collection("activitypub_actors").getFirstListItem(`iri='${id}'`)
|
const actor = await event.locals.pb.collection("activitypub_actors").getFirstListItem(`iri='${iri}'`)
|
||||||
|
|
||||||
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,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user