2023-08-14 23:46:35 +00:00
|
|
|
import { addRelays } from '@/db/relays.ts';
|
|
|
|
import { filteredArray } from '@/schema.ts';
|
2023-08-19 20:07:57 +00:00
|
|
|
import { relaySchema } from '@/utils.ts';
|
2023-08-14 23:46:35 +00:00
|
|
|
|
|
|
|
switch (Deno.args[0]) {
|
|
|
|
case 'sync':
|
|
|
|
await sync(Deno.args.slice(1));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.log('Usage: deno run -A scripts/relays.ts sync <url>');
|
|
|
|
}
|
|
|
|
|
|
|
|
async function sync([url]: string[]) {
|
|
|
|
if (!url) {
|
|
|
|
console.error('Error: please provide a URL');
|
|
|
|
Deno.exit(1);
|
|
|
|
}
|
|
|
|
const response = await fetch(url);
|
|
|
|
const data = await response.json();
|
|
|
|
const values = filteredArray(relaySchema).parse(data) as `wss://${string}`[];
|
2023-12-10 23:56:51 +00:00
|
|
|
await addRelays(values, { active: true });
|
2023-08-14 23:46:35 +00:00
|
|
|
console.log(`Done: added ${values.length} relays.`);
|
|
|
|
}
|