From 4c4f8214637ac8d19e16f71d20542982a5eedad7 Mon Sep 17 00:00:00 2001 From: real-zephex Date: Sat, 11 May 2024 01:33:00 +0530 Subject: UI changes, Logic change and complete re-write for anime page --- src/app/anime/components/cacher.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/app/anime/components/cacher.js (limited to 'src/app/anime/components/cacher.js') diff --git a/src/app/anime/components/cacher.js b/src/app/anime/components/cacher.js new file mode 100644 index 0000000..acc780a --- /dev/null +++ b/src/app/anime/components/cacher.js @@ -0,0 +1,29 @@ +"use server"; + +import { info_url, watch_url } from "../../../../utils/anime_urls"; + +export async function preFetchAnimeInfo(data) { + try { + const fetchPromises = data.results.map(async (element) => { + await fetch(info_url(element.id), { next: { revalidate: 21600 } }); + }); + + await Promise.all(fetchPromises); + console.log("Anime info pre-fetched successfully!"); + } catch (error) { + console.error("Error occurred while pre-fetching anime info: ", error); + } +} + +export async function preFetchVideoLinks(data) { + try { + const fetchPromises = data.episodes.map(async (element) => { + await fetch(watch_url(element.id), { next: { revalidate: 21600 } }); + }); + + await Promise.all(fetchPromises); + console.log("Anime video links info pre-fetched successfully!"); + } catch (error) { + console.error("Error occurred while pre-fetching anime info: ", error); + } +} -- cgit v1.2.3 From 513eb617bc627bdc406eddd0f3124411017cbe50 Mon Sep 17 00:00:00 2001 From: real-zephex Date: Sat, 11 May 2024 01:42:48 +0530 Subject: adjustments to the cache system --- src/app/anime/components/cacher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/app/anime/components/cacher.js') diff --git a/src/app/anime/components/cacher.js b/src/app/anime/components/cacher.js index acc780a..d3008fa 100644 --- a/src/app/anime/components/cacher.js +++ b/src/app/anime/components/cacher.js @@ -17,7 +17,7 @@ export async function preFetchAnimeInfo(data) { export async function preFetchVideoLinks(data) { try { - const fetchPromises = data.episodes.map(async (element) => { + const fetchPromises = data.map(async (element) => { await fetch(watch_url(element.id), { next: { revalidate: 21600 } }); }); -- cgit v1.2.3