Typing all the types

This commit is contained in:
2024-10-23 00:27:20 +02:00
parent edaf5f5c71
commit 46ad9813eb
15 changed files with 97 additions and 105 deletions

View File

@@ -1,23 +1,21 @@
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 naddrHandler = async function (ctx: Context) {
const naddr = ctx.params.path;
const naddr = ctx.state.path;
try {
const r = nip19.decode(naddr);
const username = await lookupUsernameByPubkey(r.data.pubkey);
const data = nip19.decode(naddr).data as nip19.AddressPointer;
const username = await lookupUsernameByPubkey(data.pubkey);
if (username && r.data.identifier) {
ctx.response.redirect(`/@${username}/${r.data.identifier}`);
if (username && data.identifier) {
ctx.response.redirect(`/@${username}/${data.identifier}`);
} else {
notFoundHandler(ctx);
}
} catch (e) {
log(e, "yellow");
} catch (_e) {
notFoundHandler(ctx);
}
};