From b09800f1529f042e9049f5fe30eab7d80dfbc2fd Mon Sep 17 00:00:00 2001 From: Rizky Date: Wed, 7 Feb 2024 17:13:30 +0700 Subject: [PATCH] fix proxy --- app/web/src/base/load/proxy.ts | 55 ++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/app/web/src/base/load/proxy.ts b/app/web/src/base/load/proxy.ts index f8ace16c..b6a71980 100644 --- a/app/web/src/base/load/proxy.ts +++ b/app/web/src/base/load/proxy.ts @@ -64,34 +64,39 @@ export const fetchViaProxy = async ( return raw; } } else { - const res = await fetch(`${w.basehost ? w.basehost : ""}/_proxy`, { - method: "POST", - body: JSON.stringify([ - { - url, - body, - headers, - }, - ]), - headers: { "content-type": "application/json" }, - }); + if (body instanceof File) { + const res = await fetch(url, { body, headers: _headers }); + return await res.text(); + } else { + const res = await fetch(`${w.basehost ? w.basehost : ""}/_proxy`, { + method: "POST", + body: JSON.stringify([ + { + url, + body, + headers, + }, + ]), + headers: { "content-type": "application/json" }, + }); - let text = ""; - try { - text = await res.text(); - return JSON.parse(text); - } catch (e) { - let formatted_body = null; + let text = ""; try { - formatted_body = JSON.stringify(JSON.parse(body), null, 2); - } catch (e) {} + text = await res.text(); + return JSON.parse(text); + } catch (e) { + let formatted_body = null; + try { + formatted_body = JSON.stringify(JSON.parse(body), null, 2); + } catch (e) {} - console.warn( - `\n\n⚡ Failed to JSON.parse fetch result of ${url}:\n\n${JSON.stringify( - text - )} \n\nwith params:\n${formatted_body}` - ); - return text; + console.warn( + `\n\n⚡ Failed to JSON.parse fetch result of ${url}:\n\n${JSON.stringify( + text + )} \n\nwith params:\n${formatted_body}` + ); + return text; + } } } };