diff --git a/api/well-known/webfinger.ts b/api/well-known/webfinger.ts index 8171aaf..1fc2f16 100644 --- a/api/well-known/webfinger.ts +++ b/api/well-known/webfinger.ts @@ -1,35 +1,58 @@ import type { VercelRequest, VercelResponse } from '@vercel/node'; export default function (req: VercelRequest, res: VercelResponse) { + // Get the resource query parameter const { resource } = req.query; - res.statusCode = 200; - res.setHeader("Content-Type", `application/jrd+json`); - res.end(`{ - "subject": "acct:blog@coderrrrr.site", - "aliases": [ - "https://coderrrrr.site/blog", - "https://coderrrrr.site/@blog" - ], - "links": [ - { - "rel": "http://webfinger.net/rel/profile-page", - "type": "text/html", - "href": "https://coderrrrr.site/@blog" - }, - { - "rel": "self", - "type": "application/activity+json", - "href": "https://coderrrrr.site/@blog" - }, - { - "rel": "http://ostatus.org/schema/1.0/subscribe", - "template": "https://coderrrrr.site/authorize_interaction?uri={uri}" - }, - { - "rel": "http://webfinger.net/rel/avatar", - "type": "image/png", - "href": "https://files.usr.cloud/v1/AUTH_f22cbcf5b3904990be9696691ff73fc6/files.usr.cloud/accounts/avatars/113/822/701/816/479/941/original/7d7f6088ba1ddd57.png" - } - ] -}`); + + if (!resource || typeof resource !== "string") { + res.status(400).json({ error: "Missing or invalid resource parameter" }); + return; + } + + // Expected format: acct:username@coderrrrr.site + const match = resource.match(/^acct:([^@]+)@coderrrrr\.site$/i); + if (!match) { + res.status(400).json({ error: "Resource format not supported" }); + return; + } +ṣ + const username = match[1].toLowerCase(); + + // Determine the profile URL based on the username. + // For this example, we support only the "blog" account. + // You can add more supported usernames as needed. + let profileUrl: string; + if (username === "blog") { + profileUrl = "https://coderrrrr.site/blog"; + } else { + // If the username is not recognized, return a 404. + res.status(404).json({ error: "User not found" }); + return; + } + + // Build the WebFinger response object + const webfingerResponse = { + subject: resource, + aliases: [profileUrl], + links: [ + { + rel: "http://webfinger.net/rel/profile-page", + type: "text/html", + href: profileUrl + }, + { + rel: "self", + type: "application/activity+json", + href: profileUrl + }, + // Optional: Add a subscription template if needed. + { + rel: "http://ostatus.org/schema/1.0/subscribe", + template: "https://coderrrrr.site/authorize_interaction?uri={uri}" + } + ] + }; + + res.setHeader("Content-Type", "application/jrd+json"); + res.status(200).json(webfingerResponse); }