mirror of
https://github.com/Radiquum/AniX.git
synced 2025-04-28 00:49:40 +05:00
Merge remote-tracking branch 'origin/feat_player'
This commit is contained in:
parent
bb437fe7ca
commit
25e31a7799
62 changed files with 1508 additions and 701 deletions
38
app/api/[...endpoint]/route.ts
Normal file
38
app/api/[...endpoint]/route.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue