Parse webfinger resource like a URL.

This commit is contained in:
Andrew Pietila 2024-07-28 17:39:33 -05:00
parent 05da3ed57c
commit e8b352c418

View file

@ -7,36 +7,41 @@ export async function GET(request: NextRequest) {
const reqUrl = new URL(request.url);
console.log(reqUrl);
const reqResource = reqUrl.searchParams.get("resource");
// TODO: If this matches a URL, figure it out.
const matches = reqResource?.match(/acct:(.*)@(.*)/);
// if ( !matches || matches?.length === 0 ) {
// const res = new Response("", {status: 404});
// return res;
// }
if ( !reqResource ) {
return new Response("", {status: 404});
}
const resourceUrl = new URL(reqResource);
let user = '';
let domain = '';
if ( resourceUrl.protocol === "acct:" ) {
let pathnameSplit = resourceUrl.pathname.split('@');
user = pathnameSplit[0];
domain = pathnameSplit[1];
}
// TODO: If this matches a URL, figure it out.
// TODO: Multidomain
console.log(matches?.length);
if ( matches && matches.length === 3 && matches[2] === request.headers.get("host") ) {
if ( user !== '' && domain !== '' ) {
// TODO: User specificity
return NextResponse.json({
"subject": `acct:${matches[1]}@${matches[2]}`,
"aliases": [`https://${matches[2]}/@${matches[1]}`, `https://${matches[2]}/users/${matches[1]}`],
"subject": `acct:${user}@${domain}`,
"aliases": [`https://${domain}/@${user}`, `https://${domain}/users/${user}`],
"links": [{
"rel": "http://webfinger.net/rel/profile-page",
"type": "text/html",
"href": `https://${matches[2]}/@${matches[1]}`
"href": `https://${domain}/@${user}`
}, {
"rel": "self",
"type": "application/activity+json",
"href": `https://${matches[2]}/users/${matches[1]}`
"href": `https://${domain}/users/${user}`
}, {
"rel": "http://ostatus.org/schema/1.0/subscribe",
"template": `https://${matches[2]}/authorize_interaction?uri={uri}`
"template": `https://${domain}/authorize_interaction?uri={uri}`
}, {
"rel": "http://webfinger.net/rel/avatar",
"type": "image/png",
// TODO: Avatar URL.
"href": `https://files.${matches[2]}/avatar.png`
"href": `https://files.${domain}/avatar.png`
}]
}, {
headers: { "Content-Type": "application/jrd+json; charset=utf-8" }