mirror of
https://github.com/aljazceru/ditto.git
synced 2026-02-08 15:04:19 +01:00
Add a better admin:event script
This commit is contained in:
30
scripts/admin-event.ts
Normal file
30
scripts/admin-event.ts
Normal file
@@ -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));
|
||||
}
|
||||
Reference in New Issue
Block a user