Added script to populate relays from external source
This commit is contained in:
parent
f13616a740
commit
e3ade42f58
|
@ -6,21 +6,22 @@
|
|||
"dev": "deno run --allow-read --allow-write=data --allow-env --allow-net --unstable --watch src/server.ts",
|
||||
"debug": "deno run --allow-read --allow-write=data --allow-env --allow-net --unstable --inspect src/server.ts",
|
||||
"test": "DB_PATH=\":memory:\" deno test --allow-read --allow-write=data --allow-env --unstable src",
|
||||
"check": "deno check --unstable src/server.ts"
|
||||
"check": "deno check --unstable src/server.ts",
|
||||
"relays:sync": "deno run -A --unstable scripts/relays.ts sync",
|
||||
},
|
||||
"imports": {
|
||||
"@/": "./src/",
|
||||
"~/": "./"
|
||||
},
|
||||
"lint": {
|
||||
"include": ["src/"],
|
||||
"include": ["src/", "scripts/"],
|
||||
"rules": {
|
||||
"tags": ["recommended"],
|
||||
"exclude": ["no-explicit-any"]
|
||||
}
|
||||
},
|
||||
"fmt": {
|
||||
"include": ["src/"],
|
||||
"include": ["src/", "scripts/"],
|
||||
"useTabs": false,
|
||||
"lineWidth": 120,
|
||||
"indentWidth": 2,
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
import { addRelays } from '@/db/relays.ts';
|
||||
import { filteredArray } from '@/schema.ts';
|
||||
import { relaySchema } from '~/src/utils.ts';
|
||||
|
||||
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}`[];
|
||||
await addRelays(values);
|
||||
console.log(`Done: added ${values.length} relays.`);
|
||||
}
|
|
@ -164,6 +164,7 @@ export {
|
|||
paginationSchema,
|
||||
parseBody,
|
||||
parseNip05,
|
||||
relaySchema,
|
||||
sha256,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue