ditto/scripts/admin-event.ts

32 lines
852 B
TypeScript
Raw Normal View History

2024-04-23 22:32:24 +00:00
import { JsonParseStream } from '@std/json/json-parse-stream';
import { TextLineStream } from '@std/streams/text-line-stream';
2024-05-14 23:51:35 +00:00
import { DittoDB } from '@/db/DittoDB.ts';
2024-04-23 22:32:24 +00:00
import { AdminSigner } from '@/signers/AdminSigner.ts';
2024-05-15 13:18:31 +00:00
import { EventsDB } from '@/storages/EventsDB.ts';
2024-04-23 22:32:24 +00:00
import { type EventStub } from '@/utils/api.ts';
import { nostrNow } from '@/utils.ts';
const signer = new AdminSigner();
2024-05-14 23:51:35 +00:00
const kysely = await DittoDB.getInstance();
const eventsDB = new EventsDB(kysely);
2024-04-23 22:32:24 +00:00
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);