From bae1f53877c3447d3ba940f823e5a8a097f5b22c Mon Sep 17 00:00:00 2001 From: Factiven Date: Wed, 9 Aug 2023 15:11:53 +0700 Subject: Update v3.9.0 - Merged Beta to Main (#41) * initial commit * Update_v.3.6.7-beta-v1.2 * Update_v.3.6.7-beta-v1.3 * Update_v.3.6.7-beta-v1.3 > update API * Fixed mediaList won't update * added .env disqus shortname * Update_v3.6.7-beta-v1.4 >Implementing database * Create main.yml * Update v3.6.7-beta-v1.5 small patch * title home page * Update content.js * Delete db-test.js * Update content.js * Update home page card * Update v3.7.0 * Update v3.7.1-beta > migrating backend to main code > fixed schedule component * Update v3.8.0 > Added dub options > Moved schedule backend * Update v.3.8.1 > Fixed episodes on watch page isn't dubbed * Update v3.8.1-patch-1 * Update v3.8.1-patch-2 > Another patch for dub * Update v3.8.2 > Removed prisma configuration for database since it's not stable yet * Update v3.8.3 > Fixed different provider have same id * Update v.3.8.3 > Fixed player bug where the controls won't hide after updating anilist progress * Update v3.8.4-patch-2 * Update v3.8.5 > Update readme.md > Update .env.example * Update next.config.js * small adjusment info page * Update v3.8.6 > Minor update for Android 13 user * Update v3.8.7 > Added prev and next button to mediaSession * Update v3.8.7-beta-v2 * Beta v2 (#37) * Update schema.prisma * Update schema.prisma * Update schema.prisma * Update 3.9.0-beta-v2.1 > Implemented database for storing user Watch List and settings > Added buttons to auto-play next episodes * Update v3.9.0-beta-v2.2 * Update README.md --------- Co-authored-by: Chitraksh Maheshwari <68012660+chitrakshbotwala@users.noreply.github.com> --- lib/anify/page.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lib/anify/page.js (limited to 'lib/anify/page.js') 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 }; + } +} -- cgit v1.2.3