aboutsummaryrefslogtreecommitdiff
path: root/src/app/manga/cacher.js
blob: 7f047ab0ac6f15a4d736aa065de4c9c5ee4c9f15 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// This function pre-fetches all the chapter pages links for a manga in the background
"use server";

export async function PreFetchChaterLinks(data) {
	try {
		const fetchPromises = data.map(async (element) => {
			const link = `https://consumet-jade.vercel.app/meta/anilist-manga/read?chapterId=${element.id}&provider=mangadex`;
			await fetch(link, { cache: "force-cache" });
		});

		await Promise.all(fetchPromises);
		console.log("Chapter links pre-fetched successfully!");
	} catch (error) {
		console.error(
			"Error occurred while pre-fetching chapter links:",
			error
		);
	}
}

export async function PreFetchMangaInfo(data) {
	try {
		const fetchPromises = data.results.map(async (element) => {
			const link = `https://consumet-jade.vercel.app/meta/anilist-manga/${element.id}?provider=mangadex`;
			await fetch(link, { next: { revalidate: 86400 } });
		});
		await Promise.all(fetchPromises);
		console.log("Manga info pre-fetched successfully!");
	} catch (error) {
		console.error("error", error);
	}
}