diff options
| author | Factiven <[email protected]> | 2023-04-17 13:33:37 +0700 |
|---|---|---|
| committer | Factiven <[email protected]> | 2023-04-17 13:33:37 +0700 |
| commit | 545d8a3473823f0a86cad3c177dbbb4ebb794a75 (patch) | |
| tree | 1606111911ea31c8fd8f9560dade41f5fedd6520 /pages/testing.js | |
| parent | Update 7th (diff) | |
| download | moopa-545d8a3473823f0a86cad3c177dbbb4ebb794a75.tar.xz moopa-545d8a3473823f0a86cad3c177dbbb4ebb794a75.zip | |
Snapshot Moopa v3.2
Diffstat (limited to 'pages/testing.js')
| -rw-r--r-- | pages/testing.js | 76 |
1 files changed, 66 insertions, 10 deletions
diff --git a/pages/testing.js b/pages/testing.js index 7540093..e951635 100644 --- a/pages/testing.js +++ b/pages/testing.js @@ -1,18 +1,34 @@ import { signIn, signOut, useSession } from "next-auth/react"; +import { getServerSession } from "next-auth/next"; +import { authOptions } from "./api/auth/[...nextauth]"; +const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || "http://localhost:3000"; -export default function Testing() { +export default function Testing({ sesi, data, progress, statusWatch }) { const { data: session, status } = useSession(); + // console.log(progress); async function handleUpdate() { - const lastPlayed = { - id: "apahisya", - time: 812989929, - }; - const res = await fetch("/api/watched-episode", { + // const data = ; + const res = await fetch("/api/update-user", { method: "POST", body: JSON.stringify({ - username: session?.user.name, - id: 150672, - newData: lastPlayed, + name: session?.user.name, + newData: { + recentWatch: { + id: parseInt(9280220), + title: { + romaji: "something title here", + }, + description: + "lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quod.", + coverImage: { + extraLarge: "this should be an image url", + }, + episode: { + id: "first-id-yeah", + time: 12344, + }, + }, + }, }), headers: { "Content-Type": "application/json", @@ -23,7 +39,7 @@ export default function Testing() { console.log(res.status); } - console.log(session); + console.log(statusWatch); return ( <div> <button onClick={() => handleUpdate()}>Click for update</button> @@ -34,3 +50,43 @@ export default function Testing() { </div> ); } + +export async function getServerSideProps(context) { + const session = await getServerSession(context.req, context.res, authOptions); + + const res = await fetch(`${baseUrl}/api/get-media`, { + method: "POST", + body: JSON.stringify({ + username: session?.user.name, + }), + headers: { + "Content-Type": "application/json", + }, + }); + + const prog = await res.json(); + + const gat = prog.lists.map((item) => item.entries); + const git = gat.map((item) => item.find((item) => item.media.id === 130003)); + const gut = git.find((item) => item?.media.id === 130003); + + let progress = null; + let statusWatch = "CURRENT"; + + if (gut?.status === "COMPLETED") { + statusWatch = "REPEATING"; + } + + if (gut) { + progress = gut?.progress; + } + + return { + props: { + sesi: session, + data: gut || null, + progress: progress, + statusWatch: statusWatch, + }, + }; +} |