blob: a7185348c4b0da37ecc937861bad31a41b1f0169 (
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
"use server";
export async function fetch_video_link(id) {
try {
const res = await fetch(
`https://consumet-jade.vercel.app/anime/gogoanime/watch/${id}`,
{ cache: "force-cache" }
);
const data = await res.json();
let vidLink = data.sources[data.sources.length - 2].url;
return vidLink;
} catch (error) {
console.log("Mehh Error", error);
}
}
export async function preFetchAnimeLinks(data, n = 40) {
const limit = Math.min(n, data.episodes.length);
try {
const fetchPromises = [];
for (let i = 0; i < limit; i++) {
const element = data.episodes[i];
const link = `https://consumet-jade.vercel.app/anime/gogoanime/watch/${element.id}`;
fetchPromises.push(fetch(link, { cache: "force-cache" }));
}
await Promise.all(fetchPromises);
console.log("Video links pre-fetched successfully!");
} catch (error) {
console.error("Error occurred while pre-fetching video links:", error);
}
}
export async function preFetchAnimeInfo(data) {
try {
const fetchPromises = data.results.map(async (element) => {
const link = `https://anime-sensei-api.vercel.app/anime/gogoanime/info/${element.id}`;
await fetch(link, { next: { revalidate: 86400 } });
});
await Promise.all(fetchPromises);
console.log("Anime info pre-fetched successfully!");
} catch (error) {
console.error("Error occurred while pre-fetching anime info: ", error);
}
}
|