Let a proxy tag not be a URL (to support atproto URIs)

This commit is contained in:
Alex Gleason 2024-11-22 10:49:05 -06:00
parent da82462fa2
commit 418dbd6d0c
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 3 additions and 20 deletions

View file

@ -10,7 +10,7 @@ import { nip27 } from 'nostr-tools';
import { DittoTables } from '@/db/DittoTables.ts'; import { DittoTables } from '@/db/DittoTables.ts';
import { dbEventsCounter } from '@/metrics.ts'; import { dbEventsCounter } from '@/metrics.ts';
import { RelayError } from '@/RelayError.ts'; import { RelayError } from '@/RelayError.ts';
import { isNostrId, isURL } from '@/utils.ts'; import { isNostrId } from '@/utils.ts';
import { abortError } from '@/utils/abort.ts'; import { abortError } from '@/utils/abort.ts';
import { purifyEvent } from '@/utils/purify.ts'; import { purifyEvent } from '@/utils/purify.ts';
import { DittoEvent } from '@/interfaces/DittoEvent.ts'; import { DittoEvent } from '@/interfaces/DittoEvent.ts';
@ -49,7 +49,7 @@ class EventsDB extends NPostgres {
'n': ({ count, value }) => count < 50 && value.length < 50, 'n': ({ count, value }) => count < 50 && value.length < 50,
'P': ({ count, value }) => count === 0 && isNostrId(value), 'P': ({ count, value }) => count === 0 && isNostrId(value),
'p': ({ event, count, value }) => (count < 15 || event.kind === 3) && 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), 'q': ({ event, count, value }) => count === 0 && event.kind === 1 && isNostrId(value),
'r': ({ event, count }) => (event.kind === 1985 ? count < 20 : count < 3), 'r': ({ event, count }) => (event.kind === 1985 ? count < 20 : count < 3),
't': ({ event, count, value }) => (event.kind === 1985 ? count < 20 : count < 5) && value.length < 50, 't': ({ event, count, value }) => (event.kind === 1985 ? count < 20 : count < 5) && value.length < 50,

View file

@ -1,6 +1,5 @@
import { NostrEvent, NSchema as n } from '@nostrify/nostrify'; import { NostrEvent, NSchema as n } from '@nostrify/nostrify';
import { nip19 } from 'nostr-tools'; import { nip19 } from 'nostr-tools';
import { z } from 'zod';
/** Get the current time in Nostr format. */ /** Get the current time in Nostr format. */
const nostrNow = (): number => Math.floor(Date.now() / 1000); const nostrNow = (): number => Math.floor(Date.now() / 1000);
@ -69,11 +68,6 @@ function isNostrId(value: unknown): boolean {
return n.id().safeParse(value).success; 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. */ /** Render an empty author event so other things can stick to it. */
function fallbackAuthor(pubkey: string): NostrEvent { function fallbackAuthor(pubkey: string): NostrEvent {
return { return {
@ -87,17 +81,6 @@ function fallbackAuthor(pubkey: string): NostrEvent {
}; };
} }
export { export { bech32ToPubkey, eventAge, fallbackAuthor, findTag, isNostrId, type Nip05, nostrDate, nostrNow, parseNip05 };
bech32ToPubkey,
eventAge,
fallbackAuthor,
findTag,
isNostrId,
isURL,
type Nip05,
nostrDate,
nostrNow,
parseNip05,
};
export { Time } from '@/utils/time.ts'; export { Time } from '@/utils/time.ts';