Add populate:nip05 script

This commit is contained in:
Alex Gleason 2025-02-07 16:03:22 -06:00
parent 93141c1db1
commit 5157a90b63
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
4 changed files with 53 additions and 2 deletions

View file

@ -21,6 +21,7 @@
"soapbox": "curl -O https://dl.soapbox.pub/main/soapbox.zip && mkdir -p public && mv soapbox.zip public/ && cd public/ && unzip -o soapbox.zip && rm soapbox.zip",
"trends": "deno run -A --env-file --deny-read=.env scripts/trends.ts",
"clean:deps": "deno cache --reload src/app.ts",
"db:populate:nip05": "deno run -A --env-file --deny-read=.env scripts/db-populate-nip05.ts",
"db:populate-search": "deno run -A --env-file --deny-read=.env scripts/db-populate-search.ts",
"db:populate-extensions": "deno run -A --env-file --deny-read=.env scripts/db-populate-extensions.ts",
"db:streak:recompute": "deno run -A --env-file --deny-read=.env scripts/db-streak-recompute.ts",

View file

@ -0,0 +1,45 @@
import { NSchema as n } from '@nostrify/nostrify';
import { Storages } from '@/storages.ts';
import { faviconCache } from '@/utils/favicon.ts';
import { nip05Cache } from '@/utils/nip05.ts';
const store = await Storages.db();
const kysely = await Storages.kysely();
const statsQuery = kysely.selectFrom('author_stats').select('pubkey');
for await (const { pubkey } of statsQuery.stream(10)) {
const signal = AbortSignal.timeout(30_000); // generous timeout
try {
const [author] = await store.query([{ kinds: [0], authors: [pubkey], limit: 1 }]);
if (!author) {
continue;
}
// Parse metadata.
const metadata = n.json().pipe(n.metadata()).catch({}).safeParse(author.content);
if (!metadata.success) continue;
// Update nip05.
const { nip05 } = metadata.data;
if (nip05) {
try {
await nip05Cache.fetch(nip05, { signal });
} catch {
// Ignore.
}
}
// Update favicon.
const domain = nip05?.split('@')[1].toLowerCase();
if (domain) {
await faviconCache.fetch(domain, { signal });
}
} catch {
continue;
}
}
Deno.exit();

View file

@ -23,7 +23,7 @@ export const faviconCache = new SimpleLRU<string, URL>(
const url = await fetchFavicon(domain, signal);
insertFavicon(kysely, domain, url.href).catch(() => {});
await insertFavicon(kysely, domain, url.href);
return url;
},

View file

@ -110,7 +110,12 @@ async function insertNip05(kysely: Kysely<DittoTables>, nip05: string, pubkey: s
nip05_hostname: tld.hostname,
nip05_last_verified_at: ts,
})
.where('nip05_last_verified_at', '<', ts)
.where((eb) =>
eb.or([
eb('author_stats.nip05_last_verified_at', '<', ts),
eb('author_stats.nip05_last_verified_at', 'is', null),
])
)
)
.execute();
}