relays: don't automatically add crawled relays

This commit is contained in:
Alex Gleason 2023-12-10 17:56:51 -06:00
parent ff278487e8
commit 862ff74d7b
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 8 additions and 3 deletions

View File

@ -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.`);
}

View File

@ -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')