relays: don't automatically add crawled relays
This commit is contained in:
parent
ff278487e8
commit
862ff74d7b
|
@ -18,6 +18,6 @@ async function sync([url]: string[]) {
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
const values = filteredArray(relaySchema).parse(data) as `wss://${string}`[];
|
const values = filteredArray(relaySchema).parse(data) as `wss://${string}`[];
|
||||||
await addRelays(values);
|
await addRelays(values, { active: true });
|
||||||
console.log(`Done: added ${values.length} relays.`);
|
console.log(`Done: added ${values.length} relays.`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,19 @@
|
||||||
import { tldts } from '@/deps.ts';
|
import { tldts } from '@/deps.ts';
|
||||||
import { db } from '@/db.ts';
|
import { db } from '@/db.ts';
|
||||||
|
|
||||||
|
interface AddRelaysOpts {
|
||||||
|
active?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
/** Inserts relays into the database, skipping duplicates. */
|
/** 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();
|
if (!relays.length) return Promise.resolve();
|
||||||
|
const { active = false } = opts;
|
||||||
|
|
||||||
const values = relays.map((url) => ({
|
const values = relays.map((url) => ({
|
||||||
url: new URL(url).toString(),
|
url: new URL(url).toString(),
|
||||||
domain: tldts.getDomain(url)!,
|
domain: tldts.getDomain(url)!,
|
||||||
active: true,
|
active,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return db.insertInto('relays')
|
return db.insertInto('relays')
|
||||||
|
|
Loading…
Reference in New Issue