From 649fdfcab716d42add69df31e37aafe033e1186e Mon Sep 17 00:00:00 2001 From: TZGyn Date: Tue, 11 Feb 2025 21:08:09 +0800 Subject: [PATCH] update webhook to accept string --- src/routes/webhook/tradingview/+server.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/routes/webhook/tradingview/+server.ts b/src/routes/webhook/tradingview/+server.ts index 4ad7dc4..acbd99a 100644 --- a/src/routes/webhook/tradingview/+server.ts +++ b/src/routes/webhook/tradingview/+server.ts @@ -3,7 +3,9 @@ import { RestClientV5 } from 'bybit-api' import { z } from 'zod' export const POST = async ({ locals, request }) => { - const body = await request.json() + const text = await request.text() + + const body = JSON.parse(text) const flatSchema = z.object({ type: z.literal('Flat'), @@ -26,9 +28,7 @@ export const POST = async ({ locals, request }) => { takeProfitPercent: z.string().optional(), stopLossPercent: z.string().optional(), }) - const form = z - .discriminatedUnion('type', [flatSchema, percentSchema]) - .safeParse(body) + const form = z.union([flatSchema, percentSchema]).safeParse(body) if (!form.success) { console.log(form.error)