feat: add search api. add token parameter for api.

This commit is contained in:
Kentai Radiquum 2024-07-13 19:45:22 +05:00
parent 5490d39b39
commit 1915d46ffc
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
3 changed files with 30 additions and 3 deletions

View file

@ -5,6 +5,7 @@ import { ENDPOINTS } from "../config";
export async function GET(request) {
const page = parseInt(request.nextUrl.searchParams.get(["page"])) || 0;
const status = request.nextUrl.searchParams.get(["status"]) || null;
const token = request.nextUrl.searchParams.get(["token"]) || null;
let statusId;
if (status == "last" || !status) {
@ -15,8 +16,13 @@ export async function GET(request) {
statusId = 2;
} else if (status == "announce") {
statusId = 3;
} else {
return NextResponse.json({message: "Bad status"}, {status: 400});
} else {
return NextResponse.json({ message: "Bad status" }, { status: 400 });
}
let url = new URL(`${ENDPOINTS.filter}/${page}`);
if (token) {
url.searchParams.set("token", token);
}
const data = {
@ -39,6 +45,6 @@ export async function GET(request) {
is_genres_exclude_mode_enabled: false,
};
const response = await fetchDataViaPost(`${ENDPOINTS.filter}/${page}`, data);
const response = await fetchDataViaPost(url.toString(), data);
return NextResponse.json(response);
}

21
app/api/search/route.js Normal file
View file

@ -0,0 +1,21 @@
import { NextResponse } from "next/server";
import { fetchDataViaPost } from "../utils";
import { ENDPOINTS } from "../config";
export async function GET(request) {
const page = parseInt(request.nextUrl.searchParams.get(["page"])) || 0;
const query = request.nextUrl.searchParams.get(["q"]) || null;
const token = request.nextUrl.searchParams.get(["token"]) || null;
if (token) {
url.searchParams.set("token", token);
}
const data = { query, searchBy: 0 };
let url = new URL(`${ENDPOINTS.search}/${page}`);
const response = await fetchDataViaPost(url.toString(), data);
if (!response) {
return NextResponse.json({ message: "Bad request" }, { status: 400 });
}
return NextResponse.json(response);
}

0
app/search/page.js Normal file
View file