diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Artplayer.js | 19 | ||||
| -rw-r--r-- | lib/anify/info.js | 33 | ||||
| -rw-r--r-- | lib/anify/page.js | 39 | ||||
| -rw-r--r-- | lib/prisma.js | 11 |
4 files changed, 102 insertions, 0 deletions
diff --git a/lib/Artplayer.js b/lib/Artplayer.js index 94ceff1..96afe2b 100644 --- a/lib/Artplayer.js +++ b/lib/Artplayer.js @@ -13,9 +13,17 @@ export default function Player({ getInstance, id, track, + // socket + socket, + isPlay, + watchdata, + room, + autoplay, + setautoplay, ...rest }) { const artRef = useRef(); + const router = useRouter(); function playM3u8(video, url, art) { @@ -70,6 +78,17 @@ export default function Player({ }, ], settings: [ + { + html: "Autoplay", + // icon: '<img width="22" heigth="22" src="/assets/img/state.svg">', + tooltip: "ON/OFF", + switch: localStorage.getItem("autoplay") === "true" ? true : false, + onSwitch: function (item) { + setautoplay(!item.switch); + localStorage.setItem("autoplay", !item.switch); + return !item.switch; + }, + }, provider === "zoro" && { html: "Subtitles", icon: '<svg xmlns="http://www.w3.org/2000/svg" width="35" height="28" viewBox="0 -960 960 960"><path d="M240-350h360v-60H240v60zm420 0h60v-60h-60v60zM240-470h60v-60h-60v60zm120 0h360v-60H360v60zM140-160q-24 0-42-18t-18-42v-520q0-24 18-42t42-18h680q24 0 42 18t18 42v520q0 24-18 42t-42 18H140zm0-60h680v-520H140v520zm0 0v-520 520z"></path></svg>', 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 }; + } +} diff --git a/lib/prisma.js b/lib/prisma.js new file mode 100644 index 0000000..7a6e5d7 --- /dev/null +++ b/lib/prisma.js @@ -0,0 +1,11 @@ +import { PrismaClient } from "@prisma/client"; + +const globalForPrisma = globalThis; + +const prisma = globalForPrisma.prisma || new PrismaClient(); + +if (process.env.NODE_ENV !== "production") { + globalForPrisma.prisma = prisma; +} + +module.exports = { prisma }; |