substr/handlers/nprofile.ts

30 lines
792 B
TypeScript

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 nprofileHandler = async function (ctx: Context) {
const { request } = ctx;
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 {
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 nprofileHandler;