batch process nip5/zapper queue

This commit is contained in:
2023-05-17 21:52:18 +01:00
parent 08e3619418
commit 1d45225336
2 changed files with 56 additions and 36 deletions

View File

@ -6,12 +6,14 @@ interface NostrJson {
names: Record<string, string>;
}
export async function fetchNip05Pubkey(name: string, domain: string) {
export async function fetchNip05Pubkey(name: string, domain: string, timeout = 2_000) {
if (!name || !domain) {
return undefined;
}
try {
const res = await fetch(`https://${domain}/.well-known/nostr.json?name=${encodeURIComponent(name)}`);
const res = await fetch(`https://${domain}/.well-known/nostr.json?name=${encodeURIComponent(name)}`, {
signal: AbortSignal.timeout(timeout),
});
const data: NostrJson = await res.json();
const match = Object.keys(data.names).find(n => {
return n.toLowerCase() === name.toLowerCase();