mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-30 18:44:20 +01:00
Make EventsDB not rely on Conf
This commit is contained in:
@@ -24,7 +24,7 @@ export const policyWorker = Comlink.wrap<CustomPolicy>(
|
||||
);
|
||||
|
||||
try {
|
||||
await policyWorker.import(Conf.policy);
|
||||
await policyWorker.init(Conf.policy, Conf.databaseUrl, Conf.pubkey);
|
||||
console.debug(`Using custom policy: ${Conf.policy}`);
|
||||
} catch (e) {
|
||||
if (e.message.includes('Module not found')) {
|
||||
|
||||
@@ -3,6 +3,9 @@ import { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/nostrify';
|
||||
import { NoOpPolicy, ReadOnlyPolicy } from '@nostrify/nostrify/policies';
|
||||
import * as Comlink from 'comlink';
|
||||
|
||||
import { DittoDB } from '@/db/DittoDB.ts';
|
||||
import { EventsDB } from '@/storages/EventsDB.ts';
|
||||
|
||||
export class CustomPolicy implements NPolicy {
|
||||
private policy: NPolicy = new ReadOnlyPolicy();
|
||||
|
||||
@@ -11,10 +14,18 @@ export class CustomPolicy implements NPolicy {
|
||||
return this.policy.call(event);
|
||||
}
|
||||
|
||||
async import(path: string): Promise<void> {
|
||||
async init(path: string, databaseUrl: string, adminPubkey: string): Promise<void> {
|
||||
const { kysely } = DittoDB.create(databaseUrl, { poolSize: 1 });
|
||||
|
||||
const store = new EventsDB({
|
||||
kysely,
|
||||
pubkey: adminPubkey,
|
||||
timeout: 1_000,
|
||||
});
|
||||
|
||||
try {
|
||||
const Policy = (await import(path)).default;
|
||||
this.policy = new Policy();
|
||||
this.policy = new Policy({ store });
|
||||
} catch (e) {
|
||||
if (e.message.includes('Module not found')) {
|
||||
this.policy = new NoOpPolicy();
|
||||
|
||||
Reference in New Issue
Block a user