import { Context } from "@oak/oak"; import { nip19 } from "@nostr/tools"; import { log } from "../log.ts"; import { lookupUsernameByPubkey } from "../ldap.ts"; import { fetchProfileEvent } from "../nostr.ts"; import { profilePageHtml } from "../html.ts"; const npubHandler = async function (ctx: Context) { const { request } = ctx; const npub = ctx.params.path; try { const r = nip19.decode(npub); const username = await lookupUsernameByPubkey(r.data); if (username) { ctx.response.redirect(`/@${username}`); } else { ctx.response.status = 404; ctx.response.body = "Not Found"; } } catch (e) { log(e, "yellow"); ctx.response.status = 404; ctx.response.body = "Not Found"; } }; export default npubHandler;