From 1a85c2571690ba592ac5183d5eadaf9846fe532b Mon Sep 17 00:00:00 2001 From: Factiven Date: Mon, 25 Sep 2023 00:44:40 +0700 Subject: Update v4.1.0 (#79) * Update v4.1.0 * Update pages/_app.js --- pages/404.js | 4 +- pages/_app.js | 110 ++++-- pages/admin/index.js | 263 +++++++++++++++ pages/api/user/profile.js | 103 +++--- pages/api/user/update/episode.js | 2 +- pages/api/v2/admin/broadcast/index.js | 40 +++ pages/api/v2/admin/bug-report/index.js | 49 +++ pages/api/v2/admin/meta/index.js | 47 +++ pages/api/v2/episode/[id].js | 121 +++++-- pages/api/v2/etc/recent/[page].js | 12 + pages/api/v2/etc/schedule/index.js | 14 +- pages/api/v2/info/[id].js | 10 +- pages/api/v2/source/index.js | 12 + pages/en/about.js | 83 ++--- pages/en/anime/[...id].js | 29 +- pages/en/anime/popular.js | 4 +- pages/en/anime/recent.js | 4 +- pages/en/anime/recently-watched.js | 13 +- pages/en/anime/trending.js | 4 +- pages/en/anime/watch/[...info].js | 598 +++++++++++++++++++++++---------- pages/en/contact.js | 9 +- pages/en/dmca.js | 16 +- pages/en/index.js | 111 +++--- pages/en/manga/[id].js | 14 +- pages/en/manga/read/[...params].js | 22 +- pages/en/profile/[user].js | 9 +- pages/en/schedule/index.js | 65 +--- pages/en/search/[...param].js | 31 +- pages/id/index.js | 8 +- 29 files changed, 1292 insertions(+), 515 deletions(-) create mode 100644 pages/admin/index.js create mode 100644 pages/api/v2/admin/broadcast/index.js create mode 100644 pages/api/v2/admin/bug-report/index.js create mode 100644 pages/api/v2/admin/meta/index.js (limited to 'pages') diff --git a/pages/404.js b/pages/404.js index 5b6162b..f6e609f 100644 --- a/pages/404.js +++ b/pages/404.js @@ -1,10 +1,9 @@ import Head from "next/head"; -import Footer from "../components/footer"; -import Navbar from "../components/navbar"; import Link from "next/link"; import { useEffect, useState } from "react"; import { parseCookies } from "nookies"; import Image from "next/image"; +import Footer from "@/components/shared/footer"; export default function Custom404() { const [lang, setLang] = useState("en"); @@ -31,7 +30,6 @@ export default function Custom404() { -
{ + async function getBroadcast() { + try { + const res = await fetch("/api/v2/admin/broadcast", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-Broadcast-Key": "get-broadcast", + }, + }); + const data = await res.json(); + if ( + data && + data?.message !== "No broadcast" && + data?.message !== "unauthorized" + ) { + toast(data.message + unixTimestampToRelativeTime(data.startAt), { + position: "top-center", + autoClose: false, + closeOnClick: true, + draggable: true, + theme: "colored", + className: "toaster", + style: { + background: "#232329", + color: "#fff", + }, + }); + } + } catch (err) { + console.log(err); + } + } + getBroadcast(); + }, []); + return ( <> @@ -26,37 +66,41 @@ export default function App({ - - - - - - - - - + + + + + + + + + + + + + diff --git a/pages/admin/index.js b/pages/admin/index.js new file mode 100644 index 0000000..4fdc8c2 --- /dev/null +++ b/pages/admin/index.js @@ -0,0 +1,263 @@ +import { getServerSession } from "next-auth"; +import { authOptions } from "pages/api/auth/[...nextauth]"; +import { useState } from "react"; +import { toast } from "react-toastify"; + +// Define a function to convert the data +function convertData(episodes) { + const convertedData = episodes.map((episode) => ({ + episode: episode.episode, + title: episode?.title, + description: episode?.description || null, + img: episode?.img?.hd || episode?.img?.mobile || null, // Use hd if available, otherwise use mobile + })); + + return convertedData; +} + +export async function getServerSideProps(context) { + const sessions = await getServerSession( + context.req, + context.res, + authOptions + ); + + if (!sessions) { + return { + redirect: { + destination: "/", + permanent: false, + }, + }; + } + + const admin = sessions?.user?.name === process.env.ADMIN_USERNAME; + const api = process.env.API_URI; + + if (!admin) { + return { + redirect: { + destination: "/", + permanent: false, + }, + }; + } + + return { + props: { + session: sessions, + api, + }, + }; +} + +export default function Admin({ api }) { + const [id, setId] = useState(); + const [resultData, setResultData] = useState(null); + + const [query, setQuery] = useState(""); + const [tmdbId, setTmdbId] = useState(); + const [hasilQuery, setHasilQuery] = useState([]); + const [season, setSeason] = useState(); + + const [override, setOverride] = useState(); + + const [loading, setLoading] = useState(false); + + const handleSearch = async () => { + try { + setLoading(true); + setResultData(null); + const res = await fetch(`${api}/meta/tmdb/${query}`); + const json = await res.json(); + const data = json.results; + setHasilQuery(data); + setLoading(false); + } catch (err) { + console.log(err); + } + }; + + const handleDetail = async () => { + try { + setLoading(true); + const res = await fetch(`${api}/meta/tmdb/info/${tmdbId}?type=TV%20Series +`); + const json = await res.json(); + const data = json.seasons; + setHasilQuery(data); + setLoading(false); + } catch (err) { + console.log(err); + } + }; + + const handleStore = async () => { + try { + setLoading(true); + if (!resultData && !id) { + console.log("No data to store"); + setLoading(false); + return; + } + const data = await fetch("/api/v2/admin/meta", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + id: id, + data: resultData, + }), + }); + if (data.status === 200) { + const json = await data.json(); + toast.success(json.message); + setLoading(false); + } + } catch (err) { + console.log(err); + } + }; + + const handleOverride = async () => { + setResultData(JSON.parse(override)); + }; + + return ( + <> +
+

Append Data Page

+
+
+ + setQuery(e.target.value)} + /> + +
+
+ + setTmdbId(e.target.value)} + /> + +
+ +
+ +