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