diff --git a/src/client.ts b/src/client.ts index 211e3c5..e922060 100644 --- a/src/client.ts +++ b/src/client.ts @@ -3,7 +3,7 @@ import { type Event, type SignedEvent } from '@/event.ts'; import { Conf } from './config.ts'; -import { eventDateComparator, type PaginationParams } from './utils.ts'; +import { eventDateComparator, type PaginationParams, Time } from './utils.ts'; const db = await Deno.openKv(); @@ -11,7 +11,7 @@ type Pool = InstanceType; /** HACK: Websockets in Deno are finnicky... get a new pool every 30 minutes. */ const poolCache = new TTLCache<0, Pool>({ - ttl: 30 * 60 * 1000, + ttl: Time.minutes(30), max: 2, dispose: (pool) => { console.log('Closing pool.'); diff --git a/src/nip05.ts b/src/nip05.ts index 1ea0e45..edcb22b 100644 --- a/src/nip05.ts +++ b/src/nip05.ts @@ -1,7 +1,7 @@ import { TTLCache, z } from '@/deps.ts'; +import { Time } from '@/utils.ts'; -const ONE_HOUR = 60 * 60 * 1000; -const nip05Cache = new TTLCache>({ ttl: ONE_HOUR, max: 5000 }); +const nip05Cache = new TTLCache>({ ttl: Time.hours(1), max: 5000 }); const NIP05_REGEX = /^(?:([\w.+-]+)@)?([\w.-]+)$/; diff --git a/src/transmute.ts b/src/transmute.ts index 72d3668..7faf6f3 100644 --- a/src/transmute.ts +++ b/src/transmute.ts @@ -6,7 +6,7 @@ import { Conf } from './config.ts'; import { getAuthor } from './client.ts'; import { verifyNip05Cached } from './nip05.ts'; import { getMediaLinks, type MediaLink, parseNoteContent } from './note.ts'; -import { type Nip05, nostrDate, parseNip05 } from './utils.ts'; +import { type Nip05, nostrDate, parseNip05, Time } from './utils.ts'; import { isCWTag } from 'https://gitlab.com/soapbox-pub/mostr/-/raw/c67064aee5ade5e01597c6d23e22e53c628ef0e2/src/nostr/tags.ts'; const DEFAULT_AVATAR = 'https://gleasonator.com/images/avi.png'; @@ -204,7 +204,7 @@ interface PreviewCard { async function unfurlCard(url: string): Promise { console.log(`Unfurling ${url}...`); try { - const result = await unfurl(url, { fetch, follow: 2, timeout: 1000, size: 1024 * 1024 }); + const result = await unfurl(url, { fetch, follow: 2, timeout: Time.seconds(1), size: 1024 * 1024 }); return { type: result.oEmbed?.type || 'link', url: result.canonical_url || url, @@ -232,9 +232,7 @@ async function unfurlCard(url: string): Promise { } } -const TWELVE_HOURS = 12 * 60 * 60 * 1000; - -const previewCardCache = new TTLCache>({ ttl: TWELVE_HOURS, max: 500 }); +const previewCardCache = new TTLCache>({ ttl: Time.hours(12), max: 500 }); /** Unfurl card from cache if available, otherwise fetch it. */ function unfurlCardCached(url: string): Promise {