diff options
Diffstat (limited to 'lib/anify')
| -rw-r--r-- | lib/anify/info.js | 33 | ||||
| -rw-r--r-- | lib/anify/page.js | 39 |
2 files changed, 72 insertions, 0 deletions
diff --git a/lib/anify/info.js b/lib/anify/info.js new file mode 100644 index 0000000..8978664 --- /dev/null +++ b/lib/anify/info.js @@ -0,0 +1,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 }; + } +} diff --git a/lib/anify/page.js b/lib/anify/page.js new file mode 100644 index 0000000..6361230 --- /dev/null +++ b/lib/anify/page.js @@ -0,0 +1,39 @@ +import cacheData from "memory-cache"; + +// 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 { + const cached = cacheData.get(chapterId); + if (cached) { + return cached; + } else { + const data = await fetchData(mediaId, providerId, chapterId, key); + if (!data.error) { + cacheData.put(chapterId, data, 1000 * 60 * 10); + return data; + } else { + return { message: "Manga/Novel not found :(" }; + } + } + } catch (error) { + return { error }; + } +} |