mirror of
https://github.com/Radiquum/AniX.git
synced 2025-05-17 18:29:40 +05:00
refactor: move login from function to middleware
This commit is contained in:
parent
19dbd69fd5
commit
0bf00b11e5
5 changed files with 96 additions and 92 deletions
|
@ -49,26 +49,33 @@ export default async function middleware(
|
|||
const path = url.pathname.match(/\/api\/proxy\/(.*)/)?.[1] + url.search;
|
||||
|
||||
const ReqContentTypeHeader = request.headers.get("Content-Type") || "";
|
||||
const ReqSignHeader = request.headers.get("Sign") || null;
|
||||
let ResContentTypeHeader = "";
|
||||
let body = null;
|
||||
|
||||
if (ReqContentTypeHeader.split(";")[0] == "multipart/form-data") {
|
||||
ResContentTypeHeader = ReqContentTypeHeader;
|
||||
body = await request.arrayBuffer();
|
||||
} else if (ReqContentTypeHeader == "application/x-www-form-urlencoded") {
|
||||
ResContentTypeHeader = ReqContentTypeHeader;
|
||||
} else {
|
||||
ResContentTypeHeader = "application/json; charset=UTF-8";
|
||||
body = JSON.stringify(await request.json());
|
||||
}
|
||||
|
||||
const data = await fetchDataViaPost(
|
||||
let resHeaders = {};
|
||||
resHeaders["Content-Type"] = ResContentTypeHeader;
|
||||
ReqSignHeader && (resHeaders["Sign"] = ReqSignHeader);
|
||||
|
||||
const { data, error } = await fetchDataViaPost(
|
||||
`${API_URL}/${path}`,
|
||||
body,
|
||||
isApiV2,
|
||||
ResContentTypeHeader
|
||||
resHeaders
|
||||
);
|
||||
|
||||
if (!data) {
|
||||
return new Response(JSON.stringify({ message: "Error Fetching Data" }), {
|
||||
if (error) {
|
||||
return new Response(JSON.stringify(error), {
|
||||
status: 500,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue