From 418dbd6d0cc59876ef06829f71a0d978f4463446 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 22 Nov 2024 10:49:05 -0600 Subject: [PATCH] Let a proxy tag not be a URL (to support atproto URIs) --- src/storages/EventsDB.ts | 4 ++-- src/utils.ts | 19 +------------------ 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/src/storages/EventsDB.ts b/src/storages/EventsDB.ts index 4413ef5e..6dccdcb2 100644 --- a/src/storages/EventsDB.ts +++ b/src/storages/EventsDB.ts @@ -10,7 +10,7 @@ import { nip27 } from 'nostr-tools'; import { DittoTables } from '@/db/DittoTables.ts'; import { dbEventsCounter } from '@/metrics.ts'; import { RelayError } from '@/RelayError.ts'; -import { isNostrId, isURL } from '@/utils.ts'; +import { isNostrId } from '@/utils.ts'; import { abortError } from '@/utils/abort.ts'; import { purifyEvent } from '@/utils/purify.ts'; import { DittoEvent } from '@/interfaces/DittoEvent.ts'; @@ -49,7 +49,7 @@ class EventsDB extends NPostgres { 'n': ({ count, value }) => count < 50 && value.length < 50, 'P': ({ count, value }) => count === 0 && isNostrId(value), 'p': ({ event, count, value }) => (count < 15 || event.kind === 3) && isNostrId(value), - 'proxy': ({ count, value }) => count === 0 && isURL(value), + 'proxy': ({ count, value }) => count === 0 && value.length < 256, 'q': ({ event, count, value }) => count === 0 && event.kind === 1 && isNostrId(value), 'r': ({ event, count }) => (event.kind === 1985 ? count < 20 : count < 3), 't': ({ event, count, value }) => (event.kind === 1985 ? count < 20 : count < 5) && value.length < 50, diff --git a/src/utils.ts b/src/utils.ts index a1298de9..02827785 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,6 +1,5 @@ import { NostrEvent, NSchema as n } from '@nostrify/nostrify'; import { nip19 } from 'nostr-tools'; -import { z } from 'zod'; /** Get the current time in Nostr format. */ const nostrNow = (): number => Math.floor(Date.now() / 1000); @@ -69,11 +68,6 @@ function isNostrId(value: unknown): boolean { return n.id().safeParse(value).success; } -/** Test whether the value is a URL. */ -function isURL(value: unknown): boolean { - return z.string().url().safeParse(value).success; -} - /** Render an empty author event so other things can stick to it. */ function fallbackAuthor(pubkey: string): NostrEvent { return { @@ -87,17 +81,6 @@ function fallbackAuthor(pubkey: string): NostrEvent { }; } -export { - bech32ToPubkey, - eventAge, - fallbackAuthor, - findTag, - isNostrId, - isURL, - type Nip05, - nostrDate, - nostrNow, - parseNip05, -}; +export { bech32ToPubkey, eventAge, fallbackAuthor, findTag, isNostrId, type Nip05, nostrDate, nostrNow, parseNip05 }; export { Time } from '@/utils/time.ts';