aboutsummaryrefslogtreecommitdiff
path: root/src/app/kdrama/components/cacher.js
blob: 476ed95995096a7e4711b787d9eb9775fe02ef04 (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
"use server";

import { drama_info_url } from "../../../../utils/kdrama_urls";
import { videoLink } from "./requests";

export async function PreFetchKdramaInfo(data) {
	try {
		const fetchPromises = data.results.map(async (element) => {
			await fetch(drama_info_url(element.id), {
				next: { revalidate: 21600 },
			});
		});

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

export const PreFetchVideoLinks = async (data, mediaID) => {
	try {
		const fetchPromise = data.map(async (element) => {
			await videoLink(element.id, mediaID);
		});

		await Promise.all(fetchPromise);
		console.log("Kdrama video links pre fetched successfully");
	} catch (error) {
		console.error("Error occured while fetching video links");
	}
};