diff --git a/scripts/relays.ts b/scripts/relays.ts index 94d0afd..84f8a7e 100644 --- a/scripts/relays.ts +++ b/scripts/relays.ts @@ -18,6 +18,6 @@ async function sync([url]: string[]) { const response = await fetch(url); const data = await response.json(); const values = filteredArray(relaySchema).parse(data) as `wss://${string}`[]; - await addRelays(values); + await addRelays(values, { active: true }); console.log(`Done: added ${values.length} relays.`); } diff --git a/src/db/relays.ts b/src/db/relays.ts index d41948f..836f520 100644 --- a/src/db/relays.ts +++ b/src/db/relays.ts @@ -1,14 +1,19 @@ import { tldts } from '@/deps.ts'; import { db } from '@/db.ts'; +interface AddRelaysOpts { + active?: boolean; +} + /** Inserts relays into the database, skipping duplicates. */ -function addRelays(relays: `wss://${string}`[]) { +function addRelays(relays: `wss://${string}`[], opts: AddRelaysOpts = {}) { if (!relays.length) return Promise.resolve(); + const { active = false } = opts; const values = relays.map((url) => ({ url: new URL(url).toString(), domain: tldts.getDomain(url)!, - active: true, + active, })); return db.insertInto('relays')