Cache the LNURL response

This commit is contained in:
Alex Gleason
2024-01-22 12:42:39 -06:00
parent d73fa7a311
commit 13c50c71bd
3 changed files with 27 additions and 5 deletions

View File

@@ -1,8 +1,9 @@
import { Conf } from '@/config.ts';
import { encryptAdmin } from '@/crypto.ts';
import { addRelays } from '@/db/relays.ts';
import { deleteAttachedMedia } from '@/db/unattached-media.ts';
import { findUser } from '@/db/users.ts';
import { Debug, type Event, LNURL } from '@/deps.ts';
import { Debug, type Event } from '@/deps.ts';
import { isEphemeralKind } from '@/kinds.ts';
import { isLocallyFollowed } from '@/queries.ts';
import { lnurlCallbackResponseSchema } from '@/schemas/lnurl.ts';
@@ -16,7 +17,7 @@ import { fetchWorker } from '@/workers/fetch.ts';
import { TrendsWorker } from '@/workers/trends.ts';
import { verifySignatureWorker } from '@/workers/verify.ts';
import { signAdminEvent } from '@/sign.ts';
import { encryptAdmin } from '@/crypto.ts';
import { lnurlCache } from '@/utils/lnurl.ts';
const debug = Debug('ditto:pipeline');
@@ -169,7 +170,7 @@ async function submitZaps(event: Event, data: EventData, signal = AbortSignal.ti
const amount = event.tags.find(([name]) => name === 'amount')?.[1];
if (lnurl && amount) {
try {
const details = await LNURL.lookup(lnurl, { fetch: fetchWorker, signal });
const details = await lnurlCache.fetch(lnurl, { signal });
if (details.tag === 'payRequest' && details.allowsNostr && details.nostrPubkey) {
const callback = new URL(details.callback);
const params = new URLSearchParams();