blob: b2b1207c3059f03e16b8954d216decf87cda8080 (
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
|
import redis from "../redis";
// Function to fetch new data
async function fetchData(id, providerId, chapterId, key) {
try {
const res = await fetch(
`https://api.anify.tv/pages?id=${id}&providerId=${providerId}&readId=${chapterId}&apikey=${key}`
);
const data = await res.json();
return data;
} catch (error) {
console.error("Error fetching data:", error);
return null;
}
}
export default async function getAnifyPage(
mediaId,
providerId,
chapterId,
key
) {
try {
let cached;
if (redis) {
cached = await redis.get(chapterId);
}
if (cached) {
return JSON.parse(cached);
} else {
const data = await fetchData(mediaId, providerId, chapterId, key);
if (!data.error) {
if (redis) {
await redis.set(chapterId, JSON.stringify(data), "EX", 60 * 10);
}
return data;
} else {
return { message: "Manga/Novel not found :(" };
}
}
} catch (error) {
return { error };
}
}
|