aboutsummaryrefslogtreecommitdiff
path: root/lib/anilist/aniAdvanceSearch.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/anilist/aniAdvanceSearch.js')
-rw-r--r--lib/anilist/aniAdvanceSearch.js127
1 files changed, 97 insertions, 30 deletions
diff --git a/lib/anilist/aniAdvanceSearch.js b/lib/anilist/aniAdvanceSearch.js
index 02a5c53..cf344b0 100644
--- a/lib/anilist/aniAdvanceSearch.js
+++ b/lib/anilist/aniAdvanceSearch.js
@@ -23,37 +23,104 @@ export async function aniAdvanceSearch({
return result;
}, {});
- const response = await fetch("https://graphql.anilist.co/", {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({
- query: advanceSearchQuery,
- variables: {
- ...(search && {
- search: search,
- ...(!sort && { sort: "SEARCH_MATCH" }),
- }),
- ...(type && { type: type }),
- ...(seasonYear && { seasonYear: seasonYear }),
- ...(season && {
- season: season,
- ...(!seasonYear && { seasonYear: new Date().getFullYear() }),
- }),
- ...(categorizedGenres && { ...categorizedGenres }),
- ...(format && { format: format }),
- // ...(genres && { genres: genres }),
- // ...(tags && { tags: tags }),
- ...(perPage && { perPage: perPage }),
- ...(sort && { sort: sort }),
+ if (type === "MANGA") {
+ const response = await fetch("https://api.anify.tv/search-advanced", {
+ method: "POST",
+ body: JSON.stringify({
+ type: "manga",
+ genres: categorizedGenres,
+ ...(search && { query: search }),
...(page && { page: page }),
+ ...(perPage && { perPage: perPage }),
+ ...(format && { format: format }),
+ ...(seasonYear && { year: seasonYear }),
+ ...(type && { type: type }),
+ }),
+ });
+
+ const data = await response.json();
+ return {
+ pageInfo: {
+ hasNextPage: data.length >= (perPage ?? 20),
+ currentPage: page,
+ lastPage: Math.ceil(data.length / (perPage ?? 20)),
+ perPage: perPage ?? 20,
+ total: data.length,
+ },
+ media: data.map((item) => ({
+ averageScore: item.averageRating,
+ bannerImage: item.bannerImage,
+ chapters: item.totalChapters,
+ coverImage: {
+ color: item.color,
+ extraLarge: item.coverImage,
+ large: item.coverImage,
+ },
+ description: item.description,
+ duration: item.duration ?? null,
+ endDate: {
+ day: null,
+ month: null,
+ year: null,
+ },
+ mappings: item.mappings,
+ format: item.format,
+ genres: item.genres,
+ id: item.id,
+ isAdult: false,
+ mediaListEntry: null,
+ nextAiringEpisode: null,
+ popularity: item.averagePopularity,
+ season: null,
+ seasonYear: item.year,
+ startDate: {
+ day: null,
+ month: null,
+ year: item.year,
+ },
+ status: item.status,
+ studios: { edges: [] },
+ title: {
+ userPreferred:
+ item.title.english ?? item.title.romaji ?? item.title.native,
+ },
+ type: item.type,
+ volumes: item.totalVolumes ?? null,
+ })),
+ };
+ } else {
+ const response = await fetch("https://graphql.anilist.co/", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
},
- }),
- });
+ body: JSON.stringify({
+ query: advanceSearchQuery,
+ variables: {
+ ...(search && {
+ search: search,
+ ...(!sort && { sort: "SEARCH_MATCH" }),
+ }),
+ ...(type && { type: type }),
+ ...(seasonYear && { seasonYear: seasonYear }),
+ ...(season && {
+ season: season,
+ ...(!seasonYear && { seasonYear: new Date().getFullYear() }),
+ }),
+ ...(categorizedGenres && { ...categorizedGenres }),
+ ...(format && { format: format }),
+ // ...(genres && { genres: genres }),
+ // ...(tags && { tags: tags }),
+ ...(perPage && { perPage: perPage }),
+ ...(sort && { sort: sort }),
+ ...(page && { page: page }),
+ },
+ }),
+ });
- const datas = await response.json();
- // console.log(datas);
- const data = datas.data.Page;
- return data;
+ const datas = await response.json();
+ // console.log(datas);
+ const data = datas.data.Page;
+ return data;
+ }
}