mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
PolicyRegistry need not be in app.ts at all
This commit is contained in:
parent
b0036a3d28
commit
72685f227b
3 changed files with 23 additions and 12 deletions
|
|
@ -151,7 +151,6 @@ import dittoNamesRoute from '@/routes/dittoNamesRoute.ts';
|
|||
import pleromaAdminPermissionGroupsRoute from '@/routes/pleromaAdminPermissionGroupsRoute.ts';
|
||||
import pleromaStatusesRoute from '@/routes/pleromaStatusesRoute.ts';
|
||||
import { DittoRelayStore } from '@/storages/DittoRelayStore.ts';
|
||||
import { PolicyRegistry } from '@nostrify/policies';
|
||||
import { adminListPoliciesController, adminCurrentPolicyController } from '@/controllers/api/policies.ts';
|
||||
import { createPolicyEvent, DEFAULT_POLICIES } from '@/utils/policies.ts';
|
||||
|
||||
|
|
@ -200,11 +199,10 @@ const pgstore = new DittoPgStore({
|
|||
|
||||
const pool = new DittoPool({ conf, relay: pgstore });
|
||||
const relay = new DittoRelayStore({ db, conf, pool, relay: pgstore });
|
||||
const policyRegistry = new PolicyRegistry({ antiDuplicationPolicyStore: await Deno.openKv(), store: relay });
|
||||
const havePolicy = await relay.count([{ kinds: [11984], authors: [await conf.signer.getPublicKey()] }]);
|
||||
|
||||
if (!havePolicy) {
|
||||
relay.event(await createPolicyEvent(conf, DEFAULT_POLICIES));
|
||||
relay.event(await createPolicyEvent(conf, { policies: DEFAULT_POLICIES }));
|
||||
}
|
||||
|
||||
await seedZapSplits({ conf, relay });
|
||||
|
|
@ -570,5 +568,4 @@ app.get('*', publicFiles, staticFiles, ratelimit, frontendController);
|
|||
app.onError(errorHandler);
|
||||
|
||||
export default app;
|
||||
export { policyRegistry };
|
||||
export type { AppContext, AppController, AppMiddleware };
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { policyRegistry, type AppController } from '@/app.ts';
|
||||
import { DEFAULT_POLICIES } from "@/utils/policies.ts";
|
||||
import { type AppController } from '@/app.ts';
|
||||
import { DEFAULT_POLICIES, policyRegistry } from "@/utils/policies.ts";
|
||||
|
||||
export const adminListPoliciesController: AppController = (c) => {
|
||||
return c.json(Object.entries(policyRegistry.policies)
|
||||
return c.json(Object.entries(policyRegistry.available)
|
||||
.map(([internalName, item]) => {
|
||||
return {
|
||||
internalName,
|
||||
|
|
|
|||
|
|
@ -1,15 +1,29 @@
|
|||
import { policyRegistry } from '@/app.ts';
|
||||
import { nostrNow } from '@/utils.ts';
|
||||
import type { DittoConf } from "@ditto/conf";
|
||||
import { PolicyRegistry } from '@nostrify/policies';
|
||||
import { MockRelay } from '@nostrify/nostrify/test';
|
||||
|
||||
type ParamValue = string | number | boolean;
|
||||
|
||||
interface PolicySpec {
|
||||
name: keyof typeof policyRegistry.policies;
|
||||
export const policyRegistry = new PolicyRegistry({
|
||||
antiDuplicationPolicyStore: {
|
||||
get: (key: Deno.KvKey) => Promise.resolve({ key, value: null, versionstamp: null }),
|
||||
set: () => Promise.resolve({ ok: true, versionstamp: "00000000000000000000" })
|
||||
},
|
||||
store: new MockRelay()
|
||||
});
|
||||
|
||||
|
||||
interface PolicySpecItem {
|
||||
name: keyof typeof policyRegistry.available;
|
||||
params?: Record<string, ParamValue | ParamValue[]>;
|
||||
}
|
||||
|
||||
export const DEFAULT_POLICIES: PolicySpec[] = [
|
||||
export interface PolicySpec {
|
||||
policies: PolicySpecItem[]
|
||||
}
|
||||
|
||||
export const DEFAULT_POLICIES: PolicySpecItem[] = [
|
||||
{ "name": "AntiDuplicationPolicy" },
|
||||
{ "name": "AuthorPolicy" },
|
||||
{ "name": "DomainPolicy" },
|
||||
|
|
@ -19,7 +33,7 @@ export const DEFAULT_POLICIES: PolicySpec[] = [
|
|||
{ "name": "HashtagPolicy", "params": { "hashtags": ["NSFW", "explicit", "violence", "cp", "porn"] } },
|
||||
];
|
||||
|
||||
export const createPolicyEvent = async (conf: DittoConf, policies: PolicySpec[]) => {
|
||||
export const createPolicyEvent = async (conf: DittoConf, policies: PolicySpec) => {
|
||||
return await conf.signer.signEvent({
|
||||
kind: 11984,
|
||||
content: JSON.stringify({ policies }),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue