27 lines
650 B
TypeScript
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;
|