mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Use an even simpler query for db:populate:nip05 script
This commit is contained in:
parent
b0dc7faaff
commit
b902abc7cc
1 changed files with 26 additions and 24 deletions
|
|
@ -4,35 +4,37 @@ import { Storages } from '@/storages.ts';
|
||||||
import { faviconCache } from '@/utils/favicon.ts';
|
import { faviconCache } from '@/utils/favicon.ts';
|
||||||
import { nip05Cache } from '@/utils/nip05.ts';
|
import { nip05Cache } from '@/utils/nip05.ts';
|
||||||
|
|
||||||
const store = await Storages.db();
|
const kysely = await Storages.kysely();
|
||||||
|
|
||||||
for await (const msg of store.req([{ kinds: [0] }])) {
|
const query = kysely
|
||||||
if (msg[0] === 'EVENT') {
|
.selectFrom('nostr_events')
|
||||||
const signal = AbortSignal.timeout(30_000); // generous timeout
|
.select('content')
|
||||||
const event = msg[2];
|
.where('kind', '=', 0);
|
||||||
|
|
||||||
// Parse metadata.
|
for await (const { content } of query.stream(100)) {
|
||||||
const metadata = n.json().pipe(n.metadata()).catch({}).safeParse(event.content);
|
const signal = AbortSignal.timeout(30_000); // generous timeout
|
||||||
if (!metadata.success) continue;
|
|
||||||
|
|
||||||
// Update nip05.
|
// Parse metadata.
|
||||||
const { nip05 } = metadata.data;
|
const metadata = n.json().pipe(n.metadata()).catch({}).safeParse(content);
|
||||||
if (nip05) {
|
if (!metadata.success) continue;
|
||||||
try {
|
|
||||||
await nip05Cache.fetch(nip05, { signal });
|
// Update nip05.
|
||||||
} catch {
|
const { nip05 } = metadata.data;
|
||||||
// Ignore.
|
if (nip05) {
|
||||||
}
|
try {
|
||||||
|
await nip05Cache.fetch(nip05, { signal });
|
||||||
|
} catch {
|
||||||
|
// Ignore.
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update favicon.
|
// Update favicon.
|
||||||
const domain = nip05?.split('@')[1].toLowerCase();
|
const domain = nip05?.split('@')[1].toLowerCase();
|
||||||
if (domain) {
|
if (domain) {
|
||||||
try {
|
try {
|
||||||
await faviconCache.fetch(domain, { signal });
|
await faviconCache.fetch(domain, { signal });
|
||||||
} catch {
|
} catch {
|
||||||
// Ignore.
|
// Ignore.
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue