mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import { nostrNow } from '@/utils.ts';
|
|
import type { DittoConf } from '@ditto/conf';
|
|
import { PolicyRegistry } from './registry.ts';
|
|
import { MockRelay } from '@nostrify/nostrify/test';
|
|
import { nip19 } from 'nostr-tools';
|
|
|
|
type ParamValue = string | number | boolean;
|
|
|
|
export { PolicyRegistry };
|
|
|
|
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(),
|
|
});
|
|
|
|
export type PolicyParam = ParamValue | (string | number)[];
|
|
export type PolicyParams = Record<string, PolicyParam>;
|
|
|
|
interface PolicySpecItem {
|
|
name: keyof typeof policyRegistry.available;
|
|
params?: PolicyParams;
|
|
}
|
|
|
|
export interface PolicySpec {
|
|
policies: PolicySpecItem[];
|
|
}
|
|
|
|
export const normalizeNpub = (itm: string) => {
|
|
if (!itm.startsWith('npub1')) return itm;
|
|
return nip19.decode(itm as `npub1${string}`).data;
|
|
};
|
|
|
|
export const DEFAULT_POLICY_SPEC: PolicySpec = {
|
|
policies: [
|
|
{ 'name': 'SizePolicy' },
|
|
{ 'name': 'HellthreadPolicy' },
|
|
{ 'name': 'HashtagPolicy', 'params': { 'hashtags': ['NSFW', 'explicit', 'violence', 'cp', 'porn'] } },
|
|
{ 'name': 'ReplyBotPolicy' },
|
|
{ 'name': 'AntiDuplicationPolicy' },
|
|
],
|
|
};
|
|
|
|
export const createPolicyEvent = async (conf: DittoConf, policies: PolicySpec) => {
|
|
return await conf.signer.signEvent({
|
|
kind: 11984,
|
|
content: JSON.stringify(policies),
|
|
created_at: nostrNow(),
|
|
tags: [],
|
|
});
|
|
};
|