From 8b67a057927ede183d6cacd4ef7ee5ee527381d8 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Mon, 17 Jun 2024 21:07:27 -0300 Subject: [PATCH] refactor: parse zap request with zod --- src/controllers/api/statuses.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index 51842474..28e0778a 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -548,11 +548,11 @@ const zappedByController: AppController = async (c) => { const store = await Storages.db(); const amountSchema = z.coerce.number().int().nonnegative().catch(0); - const events: DittoEvent[] = (await store.query([{ kinds: [9735], '#e': [id], limit: 100 }])).map((event) => { + const events = (await store.query([{ kinds: [9735], '#e': [id], limit: 100 }])).map((event) => { const zapRequestString = event.tags.find(([name]) => name === 'description')?.[1]; if (!zapRequestString) return; try { - const zapRequest = JSON.parse(zapRequestString); + const zapRequest = n.json().pipe(n.event()).parse(zapRequestString); const amount = zapRequest?.tags.find(([name]: any) => name === 'amount')?.[1]; if (!amount) { const amount = getAmount(event?.tags.find(([name]) => name === 'bolt11')?.[1]); @@ -563,7 +563,7 @@ const zappedByController: AppController = async (c) => { } catch { return; } - }).filter(Boolean); + }).filter(Boolean) as DittoEvent[]; await hydrateEvents({ events, store });