aboutsummaryrefslogtreecommitdiff
path: root/lib/anify/info.js
blob: 897866473b5ff1aae0d8ff1c0ad8a8f7562995dd (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
import axios from "axios";
import cacheData from "memory-cache";

export async function fetchInfo(id, key) {
  try {
    const { data } = await axios.get(
      `https://api.anify.tv/info/${id}?apikey=${key}`
    );
    return data;
  } catch (error) {
    console.error("Error fetching data:", error);
    return null;
  }
}

export default async function getAnifyInfo(id, key) {
  try {
    const cached = cacheData.get(id);
    if (cached) {
      return cached;
    } else {
      const data = await fetchInfo(id, key);
      if (data) {
        cacheData.put(id, data, 1000 * 60 * 10);
        return data;
      } else {
        return { message: "Schedule not found" };
      }
    }
  } catch (error) {
    return { error };
  }
}