New Home page, New UI, Proxy api requests through next.js api routes

This commit is contained in:
Kentai Radiquum 2024-07-11 07:33:56 +05:00
parent 49b9ac069f
commit a30ddcfc6a
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
20 changed files with 5385 additions and 0 deletions

27
app/api/config.js Normal file
View file

@ -0,0 +1,27 @@
export const API_URL = "https://api.anixart.tv";
export const USER_AGENT =
"AnixartApp/8.2.1-23121216 (Android 11; SDK 30; arm64-v8a;)";
export const ENDPOINTS = {
release: {
info: `${API_URL}/release`,
episode: `${API_URL}/episode`,
},
profile: `${API_URL}/profile`,
filter: `${API_URL}/filter`,
auth: `${API_URL}/auth/signIn`,
user: {
history: `${API_URL}/history`,
watching: `${API_URL}/profile/list/all/1`,
planned: `${API_URL}/profile/list/all/2`,
watched: `${API_URL}/profile/list/all/3`,
delayed: `${API_URL}/profile/list/all/4`,
abandoned: `${API_URL}/profile/list/all/5`,
favorite: `${API_URL}/favorite`,
},
search: `${API_URL}/search/releases`,
statistic: {
addHistory: `${API_URL}/history/add`,
markWatched: `${API_URL}/episode/watch`,
},
};

42
app/api/home/route.js Normal file
View file

@ -0,0 +1,42 @@
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 status = request.nextUrl.searchParams.get(["status"]) || null;
let statusId;
if (status == "last" || !status) {
statusId = null;
} else if (status == "finished") {
statusId = 1;
} else if (status == "ongoing") {
statusId = 2;
} else if (status == "announce") {
statusId = 3;
}
const data = {
country: null,
season: null,
sort: 0,
studio: null,
age_ratings: [],
category_id: null,
end_year: null,
episode_duration_from: null,
episode_duration_to: null,
episodes_from: null,
episodes_to: null,
genres: [],
profile_list_exclusions: [],
start_year: null,
status_id: statusId,
types: [],
is_genres_exclude_mode_enabled: false,
};
const response = await fetchDataViaPost(`${ENDPOINTS.filter}/${page}`, data);
return NextResponse.json(response);
}

31
app/api/utils.js Normal file
View file

@ -0,0 +1,31 @@
import { USER_AGENT } from "./config";
export const HEADERS = {
"User-Agent": USER_AGENT,
"Content-Type": "application/json; charset=UTF-8",
};
export const fetchDataViaGet = async (url) => {
try {
const response = await fetch(url, {
headers: HEADERS,
});
const data = await response.json();
return data;
} catch (error) {
console.log(error);
}
};
export const fetchDataViaPost = async (url, body) => {
try {
const response = await fetch(url, {
method: "POST",
headers: HEADERS,
body: JSON.stringify(body),
});
const data = await response.json();
return data;
} catch (error) {
console.log(error);
}
};