mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
refactor: parse zap request with zod
This commit is contained in:
parent
bf017195a6
commit
8b67a05792
1 changed files with 3 additions and 3 deletions
|
|
@ -548,11 +548,11 @@ const zappedByController: AppController = async (c) => {
|
||||||
const store = await Storages.db();
|
const store = await Storages.db();
|
||||||
const amountSchema = z.coerce.number().int().nonnegative().catch(0);
|
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];
|
const zapRequestString = event.tags.find(([name]) => name === 'description')?.[1];
|
||||||
if (!zapRequestString) return;
|
if (!zapRequestString) return;
|
||||||
try {
|
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];
|
const amount = zapRequest?.tags.find(([name]: any) => name === 'amount')?.[1];
|
||||||
if (!amount) {
|
if (!amount) {
|
||||||
const amount = getAmount(event?.tags.find(([name]) => name === 'bolt11')?.[1]);
|
const amount = getAmount(event?.tags.find(([name]) => name === 'bolt11')?.[1]);
|
||||||
|
|
@ -563,7 +563,7 @@ const zappedByController: AppController = async (c) => {
|
||||||
} catch {
|
} catch {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}).filter(Boolean);
|
}).filter(Boolean) as DittoEvent[];
|
||||||
|
|
||||||
await hydrateEvents({ events, store });
|
await hydrateEvents({ events, store });
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue