import { Context } from "@oak/oak"; import { nip19 } from "@nostr/tools"; import { lookupUsernameByPubkey } from "../directory.ts"; import notFoundHandler from "../handlers/not-found.ts"; const nprofileHandler = async function (ctx: Context) { const nprofile = ctx.state.path; try { const data = nip19.decode(nprofile).data as nip19.ProfilePointer; const username = await lookupUsernameByPubkey(data.pubkey); if (username) { ctx.response.redirect(`/@${username}`); } else { notFoundHandler(ctx); } } catch (_e) { notFoundHandler(ctx); } }; export default nprofileHandler;