substr/handlers/nprofile.ts
Râu Cao 8e802f314a
All checks were successful
CI / Test and lint (push) Successful in 16s
CI / Test and lint (pull_request) Successful in 16s
Remove debug statements
2024-12-03 18:50:40 +01:00

27 lines
650 B
TypeScript

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