From c631edf3e3fc2abd5c593c7f5e971197f0e536aa Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 20 Mar 2023 23:25:22 -0500 Subject: [PATCH] Add read-only policy --- read-only-policy.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 read-only-policy.ts diff --git a/read-only-policy.ts b/read-only-policy.ts new file mode 100755 index 0000000..f1e11af --- /dev/null +++ b/read-only-policy.ts @@ -0,0 +1,39 @@ +#!/bin/sh +//bin/true; exec deno run -A "$0" "$@" +import { readLines } from 'https://deno.land/std@0.178.0/io/mod.ts'; + +interface InputMessage { + type: 'new' | 'lookback'; + event: Event; + receivedAt: number; + sourceType: 'IP4' | 'IP6' | 'Import' | 'Stream' | 'Sync'; + sourceInfo: string; +} + +interface OutputMessage { + id: string; + action: 'accept' | 'reject' | 'shadowReject'; + msg: string; +} + +interface Event { + id: string; + sig: string; + kind: number; + tags: string[][]; + pubkey: string; + content: string; + created_at: number; +} + +function handleMessage(msg: InputMessage): OutputMessage { + return { + id: msg.event.id, + action: 'reject', + msg: 'The relay is set to read-only.', + }; +} + +for await (const line of readLines(Deno.stdin)) { + console.log(JSON.stringify(handleMessage(JSON.parse(line)))); +}