From 20b8a7267827e3a07c1eef668c3b9c22fda43765 Mon Sep 17 00:00:00 2001 From: Factiven Date: Tue, 26 Sep 2023 23:35:35 +0700 Subject: Update v4.1.2 --- pages/_app.js | 4 +- pages/admin/index.js | 261 ++++++-------------------------------- pages/api/v2/admin/meta/index.js | 6 - pages/en/anime/[...id].js | 4 +- pages/en/anime/watch/[...info].js | 38 +++++- 5 files changed, 80 insertions(+), 233 deletions(-) (limited to 'pages') diff --git a/pages/_app.js b/pages/_app.js index 9e07d22..f553a98 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -7,9 +7,9 @@ import "react-toastify/dist/ReactToastify.css"; import "react-loading-skeleton/dist/skeleton.css"; import { SkeletonTheme } from "react-loading-skeleton"; import SearchPalette from "@/components/searchPalette"; -import { SearchProvider } from "@/lib/hooks/isOpenState"; +import { SearchProvider } from "@/lib/context/isOpenState"; import Head from "next/head"; -import { WatchPageProvider } from "@/lib/hooks/watchPageProvider"; +import { WatchPageProvider } from "@/lib/context/watchPageProvider"; import { ToastContainer, toast } from "react-toastify"; import { useEffect } from "react"; import { unixTimestampToRelativeTime } from "@/utils/getTimes"; diff --git a/pages/admin/index.js b/pages/admin/index.js index 4fdc8c2..cbb5086 100644 --- a/pages/admin/index.js +++ b/pages/admin/index.js @@ -1,19 +1,14 @@ +import AdminDashboard from "@/components/admin/dashboard"; +import AdminLayout from "@/components/admin/layout"; +import AppendMeta from "@/components/admin/meta/AppendMeta"; +import { + countKeysWithPrefix, + countNumericKeys, + getValuesWithPrefix, +} from "@/utils/getRedisWithPrefix"; 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; -} +import React, { useState } from "react"; export async function getServerSideProps(context) { const sessions = await getServerSession( @@ -43,221 +38,49 @@ export async function getServerSideProps(context) { }; } + const [anime, info, meta, report] = await Promise.all([ + countNumericKeys(), + countKeysWithPrefix("anime:"), + countKeysWithPrefix("meta:"), + getValuesWithPrefix("report:"), + ]); + return { props: { session: sessions, + animeCount: anime || 0, + infoCount: info || 0, + metaCount: meta || 0, + report: report || [], 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)); - }; +export default function Admin({ + animeCount, + infoCount, + metaCount, + report, + api, +}) { + const [page, setPage] = useState(1); return ( - <> -
-

Append Data Page

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