mirror of
https://github.com/Radiquum/AniX.git
synced 2025-04-05 15:54:39 +00:00
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { NextResponse, NextRequest } from "next/server";
|
|
import { fetchDataViaGet, fetchDataViaPost } from "../utils";
|
|
import { API_URL } from "../config";
|
|
|
|
export async function GET(
|
|
req: NextRequest,
|
|
{ params }: { params: { endpoint: Array<string> } }
|
|
) {
|
|
const { endpoint } = params;
|
|
let API_V2: boolean | string =
|
|
req.nextUrl.searchParams.get("API_V2") || false;
|
|
if (API_V2 === "true") {
|
|
req.nextUrl.searchParams.delete("API_V2");
|
|
}
|
|
const query = req.nextUrl.searchParams.toString();
|
|
const url = `${API_URL}/${endpoint.join("/")}${query ? `?${query}` : ""}`;
|
|
|
|
const response = await fetchDataViaGet(url, API_V2);
|
|
return NextResponse.json(response);
|
|
}
|
|
|
|
export async function POST(
|
|
req: NextRequest,
|
|
{ params }: { params: { endpoint: Array<string> } }
|
|
) {
|
|
const { endpoint } = params;
|
|
let API_V2: boolean | string =
|
|
req.nextUrl.searchParams.get("API_V2") || false;
|
|
if (API_V2 === "true") {
|
|
req.nextUrl.searchParams.delete("API_V2");
|
|
}
|
|
const query = req.nextUrl.searchParams.toString();
|
|
const url = `${API_URL}/${endpoint.join("/")}${query ? `?${query}` : ""}`;
|
|
const body = JSON.stringify( await req.json());
|
|
|
|
const response = await fetchDataViaPost(url, body, API_V2);
|
|
return NextResponse.json(response);
|
|
}
|