Refactor/fix error handling, add query timeouts
This commit is contained in:
@@ -1,22 +1,25 @@
|
||||
import { Context } from "@oak/oak";
|
||||
import { nip19 } from "@nostr/tools";
|
||||
import { lookupUsernameByPubkey } from "../directory.ts";
|
||||
import notFoundHandler from "../handlers/not-found.ts";
|
||||
import { notFoundHandler } from "../handlers/errors.ts";
|
||||
|
||||
const npubHandler = async function (ctx: Context) {
|
||||
const npub = ctx.state.path;
|
||||
let pubkey: string;
|
||||
|
||||
try {
|
||||
const pubkey = nip19.decode(npub).data as string;
|
||||
const username = await lookupUsernameByPubkey(pubkey);
|
||||
|
||||
if (username) {
|
||||
ctx.response.redirect(`/@${username}`);
|
||||
} else {
|
||||
notFoundHandler(ctx);
|
||||
}
|
||||
pubkey = nip19.decode(npub).data as string;
|
||||
} catch (_e) {
|
||||
notFoundHandler(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
const username = await lookupUsernameByPubkey(pubkey);
|
||||
|
||||
if (username) {
|
||||
ctx.response.redirect(`/@${username}`);
|
||||
} else {
|
||||
notFoundHandler(ctx);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user