From bff55a7341c45970ddb90b74de8600e96946207a Mon Sep 17 00:00:00 2001 From: Erick Lima Date: Fri, 4 Oct 2024 19:19:02 -0300 Subject: [PATCH 1/3] refactor: Reduce retry time on Anilist API Functions --- app/api/anilist/anilistMedias.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/api/anilist/anilistMedias.ts b/app/api/anilist/anilistMedias.ts index f8f264e7..559f8650 100644 --- a/app/api/anilist/anilistMedias.ts +++ b/app/api/anilist/anilistMedias.ts @@ -39,7 +39,7 @@ function filterMediasWithAdultContent( // HANDLES SERVER ERRORS, most of time when server was not running due to be using the Free Tier axiosRetry(Axios, { retries: 3, - retryDelay: (retryAttempt) => retryAttempt * 1200, + retryDelay: (retryAttempt) => retryAttempt * 250, retryCondition: (error) => error.response?.status == 500 || error.response?.status == 404 || From 5eae33bf2147791e94d31a3de1491e7ae6515a37 Mon Sep 17 00:00:00 2001 From: Erick Lima Date: Fri, 4 Oct 2024 19:30:44 -0300 Subject: [PATCH 2/3] refactor: Reduce retry fetch on IMDB API Rename `searchMedia` to `searchMediaOnIMDB` and `getMediaInfo` to `getMediaInfoOnIMDB` in consumetImdb.ts, and update imports and function calls in page.tsx files accordingly. --- app/api/consumet/consumetImdb.ts | 8 ++++---- app/media/[id]/page.tsx | 4 ++-- app/watch/[id]/page.tsx | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/api/consumet/consumetImdb.ts b/app/api/consumet/consumetImdb.ts index 2471bc89..edd9719c 100644 --- a/app/api/consumet/consumetImdb.ts +++ b/app/api/consumet/consumetImdb.ts @@ -9,7 +9,7 @@ const CONSUMET_API_URL = process.env.NEXT_PUBLIC_CONSUMET_API_URL; // HANDLES SERVER ERRORS, most of time when server was not running due to Free Tier usage axiosRetry(Axios, { retries: 1, - retryDelay: (retryAttempt) => retryAttempt * 1000, + retryDelay: (retryAttempt) => retryAttempt * 250, retryCondition: (error) => error.response?.status == 500 || error.response?.status == 503, onRetry: (retryNumber) => @@ -19,7 +19,7 @@ axiosRetry(Axios, { }); // SEARCH BY MEDIA TITLE -export const searchMedia = cache( +export const searchMediaOnIMDB = cache( async ({ mediaTitle }: { mediaTitle: string }) => { try { const { data } = await Axios({ @@ -37,7 +37,7 @@ export const searchMedia = cache( ); // GET INFO FOR THIS MEDIA -export const getMediaInfo = cache( +export const getMediaInfoOnIMDB = cache( async ({ search, mediaId, @@ -56,7 +56,7 @@ export const getMediaInfo = cache( let mediaSearchedType: string | null = null; if (search && seachTitle) { - const searchResults: ImdbSearchItem[] = await searchMedia({ + const searchResults: ImdbSearchItem[] = await searchMediaOnIMDB({ mediaTitle: stringToOnlyAlphabetic(seachTitle), }).then((res) => res.results); diff --git a/app/media/[id]/page.tsx b/app/media/[id]/page.tsx index 42b00efd..eb11107f 100644 --- a/app/media/[id]/page.tsx +++ b/app/media/[id]/page.tsx @@ -11,7 +11,7 @@ import ScoreRating from "@/app/components/DynamicAssets/ScoreRating"; import { headers } from "next/headers"; import { checkDeviceIsMobile } from "@/app/lib/checkMobileOrDesktop"; import { convertFromUnix, getMediaReleaseDate } from "@/app/lib/formatDateUnix"; -import { getMediaInfo } from "@/app/api/consumet/consumetImdb"; +import { getMediaInfoOnIMDB } from "@/app/api/consumet/consumetImdb"; import { ImdbEpisode, ImdbMediaInfo } from "@/app/ts/interfaces/imdb"; import MediaRelatedContainer from "./components/MediaRelatedContainer"; import CommentsSection from "../../components/CommentsSection"; @@ -48,7 +48,7 @@ export default async function MediaPage({ })) as MediaDataFullInfo; // GET MEDIA INFO ON IMDB - const imdbMediaInfo = (await getMediaInfo({ + const imdbMediaInfo = (await getMediaInfoOnIMDB({ search: true, seachTitle: mediaInfo.title.romaji, releaseYear: mediaInfo.startDate.year, diff --git a/app/watch/[id]/page.tsx b/app/watch/[id]/page.tsx index 32894c07..feed0a19 100644 --- a/app/watch/[id]/page.tsx +++ b/app/watch/[id]/page.tsx @@ -24,7 +24,7 @@ import { optimizedFetchOnGoGoAnime, } from "@/app/lib/dataFetch/optimizedFetchAnimeOptions"; import { ImdbEpisode, ImdbMediaInfo } from "@/app/ts/interfaces/imdb"; -import { getMediaInfo } from "@/app/api/consumet/consumetImdb"; +import { getMediaInfoOnIMDB } from "@/app/api/consumet/consumetImdb"; import { SourceType } from "@/app/ts/interfaces/episodesSource"; import { FetchEpisodeError } from "@/app/components/MediaFetchErrorPage"; import { cookies } from "next/headers"; @@ -130,7 +130,7 @@ export default async function WatchEpisode({ const imdbEpisodesList: ImdbEpisode[] = []; const loadImdbMediaAndEpisodeInfo = async () => { - const imdbMediaInfo: ImdbMediaInfo = (await getMediaInfo({ + const imdbMediaInfo: ImdbMediaInfo = (await getMediaInfoOnIMDB({ search: true, seachTitle: mediaInfo.title.english || mediaInfo.title.romaji, releaseYear: mediaInfo.startDate.year, From 3b60f30c3181a88d447a8a56d729b21986a2a27c Mon Sep 17 00:00:00 2001 From: Erick Lima Date: Fri, 4 Oct 2024 20:00:14 -0300 Subject: [PATCH 3/3] fix: Block IMDB API Fetch due to Vercel Limit Vercel has a limit to wait the responde of the api, but it takes soo much time to load that it closes, giving no results after that. --- app/api/consumet/consumetImdb.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/api/consumet/consumetImdb.ts b/app/api/consumet/consumetImdb.ts index edd9719c..716b1ca7 100644 --- a/app/api/consumet/consumetImdb.ts +++ b/app/api/consumet/consumetImdb.ts @@ -4,7 +4,11 @@ import Axios from "axios"; import axiosRetry from "axios-retry"; import { cache } from "react"; -const CONSUMET_API_URL = process.env.NEXT_PUBLIC_CONSUMET_API_URL; + +// ATTENTION +// PROBLEMS WITH VERCEL FREE TIER LIMIT +// const CONSUMET_API_URL = process.env.NEXT_PUBLIC_CONSUMET_API_URL; +const CONSUMET_API_URL = "process.env.NEXT_PUBLIC_CONSUMET_API_URL"; // its really made to go wrong this one // HANDLES SERVER ERRORS, most of time when server was not running due to Free Tier usage axiosRetry(Axios, {