Add a better admin:event script
This commit is contained in:
parent
3204b61f0b
commit
b73b964fda
10
deno.json
10
deno.json
|
@ -8,19 +8,23 @@
|
|||
"test": "DATABASE_URL=\"sqlite://:memory:\" deno test -A",
|
||||
"check": "deno check src/server.ts",
|
||||
"relays:sync": "deno run -A scripts/relays.ts sync",
|
||||
"nsec": "deno run scripts/nsec.ts"
|
||||
"nsec": "deno run scripts/nsec.ts",
|
||||
"admin:event": "deno run -A scripts/admin-event.ts"
|
||||
},
|
||||
"unstable": ["ffi", "kv"],
|
||||
"exclude": ["./public"],
|
||||
"imports": {
|
||||
"@/": "./src/",
|
||||
"@nostrify/nostrify": "jsr:@nostrify/nostrify@^0.12.1",
|
||||
"~/fixtures/": "./fixtures/",
|
||||
"@std/cli": "jsr:@std/cli@^0.223.0",
|
||||
"@std/json": "jsr:@std/json@^0.223.0",
|
||||
"@std/streams": "jsr:@std/streams@^0.223.0",
|
||||
"hono": "https://deno.land/x/hono@v3.10.1/mod.ts",
|
||||
"hono/middleware": "https://deno.land/x/hono@v3.10.1/middleware.ts",
|
||||
"kysely": "npm:kysely@^0.26.3",
|
||||
"kysely_deno_postgres": "https://deno.land/x/kysely_deno_postgres@v0.4.0/mod.ts",
|
||||
"zod": "npm:zod@^3.23.4"
|
||||
"zod": "npm:zod@^3.23.4",
|
||||
"~/fixtures/": "./fixtures/"
|
||||
},
|
||||
"lint": {
|
||||
"include": ["src/", "scripts/"],
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
import { JsonParseStream } from '@std/json/json-parse-stream';
|
||||
import { TextLineStream } from '@std/streams/text-line-stream';
|
||||
|
||||
import { db } from '@/db.ts';
|
||||
import { AdminSigner } from '@/signers/AdminSigner.ts';
|
||||
import { EventsDB } from '@/storages/events-db.ts';
|
||||
import { type EventStub } from '@/utils/api.ts';
|
||||
import { nostrNow } from '@/utils.ts';
|
||||
|
||||
const signer = new AdminSigner();
|
||||
|
||||
const eventsDB = new EventsDB(db);
|
||||
|
||||
const readable = Deno.stdin.readable
|
||||
.pipeThrough(new TextDecoderStream())
|
||||
.pipeThrough(new TextLineStream())
|
||||
.pipeThrough(new JsonParseStream());
|
||||
|
||||
for await (const t of readable) {
|
||||
const event = await signer.signEvent({
|
||||
content: '',
|
||||
created_at: nostrNow(),
|
||||
tags: [],
|
||||
...t as EventStub,
|
||||
});
|
||||
|
||||
await eventsDB.event(event);
|
||||
}
|
||||
|
||||
Deno.exit(0);
|
|
@ -1,25 +0,0 @@
|
|||
import * as pipeline from '@/pipeline.ts';
|
||||
import { AdminSigner } from '@/signers/AdminSigner.ts';
|
||||
import { type EventStub } from '@/utils/api.ts';
|
||||
import { nostrNow } from '@/utils.ts';
|
||||
|
||||
switch (Deno.args[0]) {
|
||||
case 'publish':
|
||||
await publish(JSON.parse(Deno.args[1]));
|
||||
break;
|
||||
default:
|
||||
console.log('Usage: deno run -A scripts/admin.ts <command>');
|
||||
}
|
||||
|
||||
async function publish(t: EventStub) {
|
||||
const signer = new AdminSigner();
|
||||
|
||||
const event = await signer.signEvent({
|
||||
content: '',
|
||||
created_at: nostrNow(),
|
||||
tags: [],
|
||||
...t,
|
||||
});
|
||||
|
||||
await pipeline.handleEvent(event, AbortSignal.timeout(5000));
|
||||
}
|
Loading…
Reference in New Issue