Make EventsDB not rely on Conf

This commit is contained in:
Alex Gleason
2024-09-11 13:06:20 -05:00
parent 624b6b278e
commit d2fb3fd253
14 changed files with 75 additions and 56 deletions

View File

@@ -1,16 +1,13 @@
import { JsonParseStream } from '@std/json/json-parse-stream';
import { TextLineStream } from '@std/streams/text-line-stream';
import { DittoDB } from '@/db/DittoDB.ts';
import { AdminSigner } from '@/signers/AdminSigner.ts';
import { EventsDB } from '@/storages/EventsDB.ts';
import { Storages } from '@/storages.ts';
import { type EventStub } from '@/utils/api.ts';
import { nostrNow } from '@/utils.ts';
const signer = new AdminSigner();
const { kysely } = await DittoDB.getInstance();
const eventsDB = new EventsDB(kysely);
const store = await Storages.db();
const readable = Deno.stdin.readable
.pipeThrough(new TextDecoderStream())
@@ -25,7 +22,7 @@ for await (const t of readable) {
...t as EventStub,
});
await eventsDB.event(event);
await store.event(event);
}
Deno.exit(0);

View File

@@ -1,13 +1,11 @@
import { NSchema } from '@nostrify/nostrify';
import { nip19 } from 'nostr-tools';
import { DittoDB } from '@/db/DittoDB.ts';
import { AdminSigner } from '@/signers/AdminSigner.ts';
import { EventsDB } from '@/storages/EventsDB.ts';
import { Storages } from '@/storages.ts';
import { nostrNow } from '@/utils.ts';
const { kysely } = await DittoDB.getInstance();
const eventsDB = new EventsDB(kysely);
const store = await Storages.db();
const [pubkeyOrNpub, role] = Deno.args;
const pubkey = pubkeyOrNpub.startsWith('npub1') ? nip19.decode(pubkeyOrNpub as `npub1${string}`).data : pubkeyOrNpub;
@@ -25,7 +23,7 @@ if (!['admin', 'user'].includes(role)) {
const signer = new AdminSigner();
const admin = await signer.getPublicKey();
const [existing] = await eventsDB.query([{
const [existing] = await store.query([{
kinds: [30382],
authors: [admin],
'#d': [pubkey],
@@ -59,6 +57,6 @@ const event = await signer.signEvent({
created_at: nostrNow(),
});
await eventsDB.event(event);
await store.event(event);
Deno.exit(0);

View File

@@ -6,11 +6,9 @@
import { NostrEvent, NRelay1, NSchema } from '@nostrify/nostrify';
import { nip19 } from 'nostr-tools';
import { DittoDB } from '@/db/DittoDB.ts';
import { EventsDB } from '@/storages/EventsDB.ts';
import { Storages } from '@/storages.ts';
const { kysely } = await DittoDB.getInstance();
const eventsDB = new EventsDB(kysely);
const store = await Storages.db();
interface ImportEventsOpts {
profilesOnly: boolean;
@@ -21,7 +19,7 @@ const importUsers = async (
authors: string[],
relays: string[],
opts?: Partial<ImportEventsOpts>,
doEvent: DoEvent = async (event: NostrEvent) => await eventsDB.event(event),
doEvent: DoEvent = async (event: NostrEvent) => await store.event(event),
) => {
// Kind 0s + follow lists.
const profiles: Record<string, Record<number, NostrEvent>> = {};