reqmeister: middleware/cache, reqmeister, nip05, unfurl, refactor some code

This commit is contained in:
Alex Gleason
2023-12-27 20:07:13 -06:00
parent e121a8805e
commit 2fc9988c06
10 changed files with 39 additions and 30 deletions

View File

@@ -1,7 +1,9 @@
import { TTLCache, z } from '@/deps.ts';
import { Debug, TTLCache, z } from '@/deps.ts';
import { Time } from '@/utils/time.ts';
import { fetchWorker } from '@/workers/fetch.ts';
const debug = Debug('ditto:nip05');
const nip05Cache = new TTLCache<string, Promise<string | null>>({ ttl: Time.hours(1), max: 5000 });
const NIP05_REGEX = /^(?:([\w.+-]+)@)?([\w.-]+)$/;
@@ -46,7 +48,7 @@ function lookupNip05Cached(value: string): Promise<string | null> {
const cached = nip05Cache.get(value);
if (cached !== undefined) return cached;
console.log(`Looking up NIP-05 for ${value}`);
debug(`Looking up NIP-05 for ${value}`);
const result = lookup(value);
nip05Cache.set(value, result);

View File

@@ -1,7 +1,9 @@
import { TTLCache, unfurl } from '@/deps.ts';
import { Debug, TTLCache, unfurl } from '@/deps.ts';
import { Time } from '@/utils/time.ts';
import { fetchWorker } from '@/workers/fetch.ts';
const debug = Debug('ditto:unfurl');
interface PreviewCard {
url: string;
title: string;
@@ -20,7 +22,7 @@ interface PreviewCard {
}
async function unfurlCard(url: string, signal: AbortSignal): Promise<PreviewCard | null> {
console.log(`Unfurling ${url}...`);
debug(`Unfurling ${url}...`);
try {
const result = await unfurl(url, {
fetch: (url) => fetchWorker(url, { signal }),