mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-03 05:34:23 +01:00
reqmeister: middleware/cache, reqmeister, nip05, unfurl, refactor some code
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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 }),
|
||||
|
||||
Reference in New Issue
Block a user