From 5e98bc65c027c4fb27e565c325d5a9c902456351 Mon Sep 17 00:00:00 2001 From: Siddharth Singh Date: Sun, 30 Mar 2025 14:22:52 +0530 Subject: [PATCH] clean up some confusing naming around policy specs --- packages/ditto/app.ts | 6 +++--- packages/ditto/utils/policies.ts | 22 ++++++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/packages/ditto/app.ts b/packages/ditto/app.ts index 4cc8cdbf..56a83d71 100644 --- a/packages/ditto/app.ts +++ b/packages/ditto/app.ts @@ -152,7 +152,7 @@ import pleromaAdminPermissionGroupsRoute from '@/routes/pleromaAdminPermissionGr import pleromaStatusesRoute from '@/routes/pleromaStatusesRoute.ts'; import { DittoRelayStore } from '@/storages/DittoRelayStore.ts'; import { adminListPoliciesController, adminCurrentPolicyController } from '@/controllers/api/policies.ts'; -import { createPolicyEvent, DEFAULT_POLICIES } from '@/utils/policies.ts'; +import { createPolicyEvent, DEFAULT_POLICY_SPEC } from '@/utils/policies.ts'; export interface AppEnv extends DittoEnv { Variables: DittoEnv['Variables'] & { @@ -201,8 +201,8 @@ const pool = new DittoPool({ conf, relay: pgstore }); const relay = new DittoRelayStore({ db, conf, pool, relay: pgstore }); const havePolicy = await relay.count([{ kinds: [11984], authors: [await conf.signer.getPublicKey()] }]); -if (!havePolicy) { - relay.event(await createPolicyEvent(conf, { policies: DEFAULT_POLICIES })); +if (!havePolicy.count) { + await relay.event(await createPolicyEvent(conf, DEFAULT_POLICY_SPEC)); } await seedZapSplits({ conf, relay }); diff --git a/packages/ditto/utils/policies.ts b/packages/ditto/utils/policies.ts index af4c1223..8f4b8104 100644 --- a/packages/ditto/utils/policies.ts +++ b/packages/ditto/utils/policies.ts @@ -23,20 +23,22 @@ export interface PolicySpec { policies: PolicySpecItem[] } -export const DEFAULT_POLICIES: PolicySpecItem[] = [ - { "name": "AntiDuplicationPolicy" }, - { "name": "AuthorPolicy" }, - { "name": "DomainPolicy" }, - { "name": "HellthreadPolicy" }, - { "name": "ReplyBotPolicy" }, - { "name": "SizePolicy" }, - { "name": "HashtagPolicy", "params": { "hashtags": ["NSFW", "explicit", "violence", "cp", "porn"] } }, -]; +export const DEFAULT_POLICY_SPEC: PolicySpec = { + policies: [ + { "name": "AntiDuplicationPolicy" }, + { "name": "AuthorPolicy" }, + { "name": "DomainPolicy" }, + { "name": "HellthreadPolicy" }, + { "name": "ReplyBotPolicy" }, + { "name": "SizePolicy" }, + { "name": "HashtagPolicy", "params": { "hashtags": ["NSFW", "explicit", "violence", "cp", "porn"] } }, + ] +}; export const createPolicyEvent = async (conf: DittoConf, policies: PolicySpec) => { return await conf.signer.signEvent({ kind: 11984, - content: JSON.stringify({ policies }), + content: JSON.stringify(policies), created_at: nostrNow(), tags: [] })