diff options
| author | Factiven <[email protected]> | 2023-06-18 00:56:47 +0700 |
|---|---|---|
| committer | Factiven <[email protected]> | 2023-06-18 00:56:47 +0700 |
| commit | 62a3826876e6c37002882c1b5712b3771f805907 (patch) | |
| tree | 233f8dd13f33220502476690702d06aac4b56057 | |
| parent | Fixed Error: Missing "key" prop for element in iterator (diff) | |
| download | moopa-62a3826876e6c37002882c1b5712b3771f805907.tar.xz moopa-62a3826876e6c37002882c1b5712b3771f805907.zip | |
Performance update
| -rw-r--r-- | README.md | 8 | ||||
| -rw-r--r-- | lib/useNotify.js | 41 | ||||
| -rw-r--r-- | pages/anime/[...id].js | 43 | ||||
| -rw-r--r-- | pages/anime/watch/[...info].js | 17 |
4 files changed, 41 insertions, 68 deletions
@@ -96,6 +96,7 @@ GRAPHQL_ENDPOINT="https://graphql.anilist.co" NEXTAUTH_SECRET='run this cmd in your bash terminal (openssl rand -base64 32) with no bracket, and paste it here' NEXTAUTH_URL="for development use http://localhost:3000/ and for production use your domain url" PROXY_URI="I recommend you to use this cors-anywhere as a proxy https://github.com/Rob--W/cors-anywhere follow the instruction on how to use it there." +API_URI="host your own API from this repo https://github.com/consumet/api.consumet.org you can deploy it using the one click setup there. very easy" ``` 4. Add this endpoint as Redirect Url on AniList Developer : @@ -114,7 +115,7 @@ npm run dev - [Consumet API](https://github.com/consumet/api.consumet.org) - [AniList API](https://github.com/AniList/ApiV2-GraphQL-Docs) -- [miru](https://github.com/ThaUnknown/miru/blob/master/README.md?plain=1) for inspiring me making this site +- [miru](https://github.com/ThaUnknown/miru/) for inspiring me making this site ## License @@ -125,9 +126,8 @@ This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md Thank You for passing by!! If you have any questions or feedback, please reach out to us at [[email protected]](mailto:[email protected]?subject=[Moopa]%20-%20Your%20Subject), or you can join our [discord sever](https://discord.gg/4xTGhr85BG). <br> -or you can DM me on Discord `Factiven#9110`/`CritenDust#3704`. (just contact me on one of these account) - - +or you can DM me on Discord `Factiven#9110`/`CritenDust#3704`. (just contact me on one of these account) + [](https://discord.gg/v5fjSdKwr2) ## Support This Project diff --git a/lib/useNotify.js b/lib/useNotify.js deleted file mode 100644 index e6ba7e6..0000000 --- a/lib/useNotify.js +++ /dev/null @@ -1,41 +0,0 @@ -import { useState, useCallback } from "react"; -import { motion as m, AnimatePresence } from "framer-motion"; - -export const useNotification = () => { - const [showNotification, setShowNotification] = useState(false); - const [notificationMessage, setNotificationMessage] = useState(""); - - const show = useCallback( - (message) => { - setNotificationMessage(message); - setShowNotification(true); - setTimeout(() => { - setShowNotification(false); - }, 5000); - }, - [setNotificationMessage, setShowNotification] - ); - - const NotificationComponent = () => { - return ( - <AnimatePresence> - {showNotification && ( - <m.div - key="teasa" - transition={{ duration: 0.5 }} - initial={{ opacity: 0, y: 100 }} - animate={{ opacity: 1, y: 0 }} - exit={{ opacity: 0, y: 100 }} - className="z-50 fixed bottom-10 w-screen flex justify-center text-center" - > - <div className="bg-green-600 text-white px-2 py-2 font-bold rounded-[30px]"> - {notificationMessage} - </div> - </m.div> - )} - </AnimatePresence> - ); - }; - - return { Notification: NotificationComponent, show }; -}; diff --git a/pages/anime/[...id].js b/pages/anime/[...id].js index 2d68bd4..eb6909d 100644 --- a/pages/anime/[...id].js +++ b/pages/anime/[...id].js @@ -31,7 +31,7 @@ import { GET_MEDIA_INFO } from "../../queries"; // import { aniInfo } from "../../components/devComp/data"; // console.log(GET_MEDIA_USER); -export default function Info({ info, color }) { +export default function Info({ info, color, api }) { // Episodes dropdown const [firstEpisodeIndex, setFirstEpisodeIndex] = useState(0); const [lastEpisodeIndex, setLastEpisodeIndex] = useState(); @@ -70,6 +70,8 @@ export default function Info({ info, color }) { const [provider, setProvider] = useState(); const [prvValue, setPrvValue] = useState("gogoanime"); + + const [availableProviders, setAvailableProviders] = useState([]); // const [err, setErr] = useState(''); function handleProvider(e) { @@ -119,15 +121,9 @@ export default function Info({ info, color }) { try { const fetchPromises = [ - fetch( - `https://api.moopa.my.id/meta/anilist/info/${info.id}?provider=enime` - ), - fetch( - `https://api.moopa.my.id/meta/anilist/info/${info.id}?provider=zoro` - ), - fetch( - `https://api.moopa.my.id/meta/anilist/info/${info.id}?provider=gogoanime` - ), + fetch(`${api}/meta/anilist/info/${info.id}?provider=enime`), + fetch(`${api}/meta/anilist/info/${info.id}?provider=zoro`), + fetch(`${api}/meta/anilist/info/${info.id}?provider=gogoanime`), ]; const results = await Promise.allSettled(fetchPromises); @@ -158,6 +154,17 @@ export default function Info({ info, color }) { gogoanime: gogoanime?.episodes || gogoanime, }; + const aPrv = [ + { name: "enime", available: enime?.episodes ? true : false }, + { name: "zoro", available: zoro?.episodes ? true : false }, + { + name: "gogoanime", + available: gogoanime?.episodes ? true : false, + }, + ]; + + setAvailableProviders(aPrv); + const infProv = { enime: enime, zoro: zoro, @@ -260,7 +267,7 @@ export default function Info({ info, color }) { fetchData(); }, [id, info, session?.user?.name]); - // console.log(); + console.log(availableProviders); function handleOpen() { setOpen(true); @@ -678,9 +685,15 @@ export default function Info({ info, color }) { value={prvValue} className="flex items-center text-sm gap-5 rounded-[3px] bg-secondary py-1 px-3 pr-8 font-karla appearance-none cursor-pointer outline-none focus:ring-1 focus:ring-action" > - <option value="gogoanime">Gogoanime</option> - <option value="zoro">Zoro</option> - <option value="enime">Enime</option> + {availableProviders + ?.filter((p) => p.available === true) + .map((p) => { + return ( + <option key={p.name} value={p.name}> + {p.name} + </option> + ); + })} </select> <ChevronDownIcon className="absolute right-2 top-1/2 transform -translate-y-1/2 w-5 h-5 pointer-events-none" /> </div> @@ -1044,6 +1057,7 @@ export default function Info({ info, color }) { export async function getServerSideProps(context) { const { id } = context.query; + const API_URI = process.env.API_URI; const res = await fetch("https://graphql.anilist.co/", { method: "POST", @@ -1078,6 +1092,7 @@ export async function getServerSideProps(context) { props: { info: data, color: color, + api: API_URI, }, }; } diff --git a/pages/anime/watch/[...info].js b/pages/anime/watch/[...info].js index a6ae025..d47071e 100644 --- a/pages/anime/watch/[...info].js +++ b/pages/anime/watch/[...info].js @@ -22,7 +22,7 @@ const VideoPlayer = dynamic(() => import("../../../components/videoPlayer", { ssr: false }) ); -export default function Info({ sessions, id, aniId, provider, proxy }) { +export default function Info({ sessions, id, aniId, provider, proxy, api }) { const [epiData, setEpiData] = useState(null); const [data, setAniData] = useState(null); const [skip, setSkip] = useState({ op: null, ed: null }); @@ -73,14 +73,12 @@ export default function Info({ sessions, id, aniId, provider, proxy }) { try { if (provider) { const res = await fetch( - `https://api.moopa.my.id/meta/anilist/watch/${id}?provider=${provider}` + `${api}/meta/anilist/watch/${id}?provider=${provider}` ); const epiData = await res.json(); setEpiData(epiData); } else { - const res = await fetch( - `https://api.moopa.my.id/meta/anilist/watch/${id}` - ); + const res = await fetch(`${api}/meta/anilist/watch/${id}`); const epiData = await res.json(); setEpiData(epiData); } @@ -95,15 +93,13 @@ export default function Info({ sessions, id, aniId, provider, proxy }) { if (provider) { const res = await fetch( - `https://api.moopa.my.id/meta/anilist/info/${aniId}?provider=${provider}` + `${api}/meta/anilist/info/${aniId}?provider=${provider}` ); aniData = await res.json(); setEpisodes(aniData.episodes?.reverse()); setAniData(aniData); } else { - const res2 = await fetch( - `https://api.moopa.my.id/meta/anilist/info/${aniId}` - ); + const res2 = await fetch(`${api}/meta/anilist/info/${aniId}`); aniData = await res2.json(); setEpisodes(aniData.episodes?.reverse()); setAniData(aniData); @@ -561,6 +557,8 @@ export default function Info({ sessions, id, aniId, provider, proxy }) { export async function getServerSideProps(context) { dotenv.config(); + const API_URI = process.env.API_URI; + const session = await getServerSession(context.req, context.res, authOptions); const proxy = process.env.PROXY_URI; @@ -583,6 +581,7 @@ export async function getServerSideProps(context) { aniId, provider, proxy, + api: API_URI, }, }; } |