fix proxy

This commit is contained in:
Rizky 2024-02-07 17:13:30 +07:00
parent c3b519382b
commit b09800f152
1 changed files with 30 additions and 25 deletions

View File

@ -64,34 +64,39 @@ export const fetchViaProxy = async (
return raw; return raw;
} }
} else { } else {
const res = await fetch(`${w.basehost ? w.basehost : ""}/_proxy`, { if (body instanceof File) {
method: "POST", const res = await fetch(url, { body, headers: _headers });
body: JSON.stringify([ return await res.text();
{ } else {
url, const res = await fetch(`${w.basehost ? w.basehost : ""}/_proxy`, {
body, method: "POST",
headers, body: JSON.stringify([
}, {
]), url,
headers: { "content-type": "application/json" }, body,
}); headers,
},
]),
headers: { "content-type": "application/json" },
});
let text = ""; let text = "";
try {
text = await res.text();
return JSON.parse(text);
} catch (e) {
let formatted_body = null;
try { try {
formatted_body = JSON.stringify(JSON.parse(body), null, 2); text = await res.text();
} catch (e) {} return JSON.parse(text);
} catch (e) {
let formatted_body = null;
try {
formatted_body = JSON.stringify(JSON.parse(body), null, 2);
} catch (e) {}
console.warn( console.warn(
`\n\n⚡ Failed to JSON.parse fetch result of ${url}:\n\n${JSON.stringify( `\n\n⚡ Failed to JSON.parse fetch result of ${url}:\n\n${JSON.stringify(
text text
)} \n\nwith params:\n${formatted_body}` )} \n\nwith params:\n${formatted_body}`
); );
return text; return text;
}
} }
} }
}; };