diff options
| author | Factiven <[email protected]> | 2023-04-17 14:29:11 +0700 |
|---|---|---|
| committer | Factiven <[email protected]> | 2023-04-17 14:29:11 +0700 |
| commit | 89aac9ff49b696e77019e70ed5f9d91e4a112072 (patch) | |
| tree | 48bae9c98cb4cb61ef561fbf3b45040ce9820c38 | |
| parent | 2nd fixes (diff) | |
| download | moopa-89aac9ff49b696e77019e70ed5f9d91e4a112072.tar.xz moopa-89aac9ff49b696e77019e70ed5f9d91e4a112072.zip | |
3rd fixes
| -rw-r--r-- | pages/anime/[...id].js | 12 | ||||
| -rw-r--r-- | pages/anime/watch/[...info].js | 12 | ||||
| -rw-r--r-- | pages/api/get-media.js | 2 | ||||
| -rw-r--r-- | pages/api/get-user.js | 8 | ||||
| -rw-r--r-- | pages/index.js | 2 | ||||
| -rw-r--r-- | pages/profile/[user].js | 12 | ||||
| -rw-r--r-- | pages/testing.js | 92 |
7 files changed, 107 insertions, 33 deletions
diff --git a/pages/anime/[...id].js b/pages/anime/[...id].js index 91a3eed..1df8ea4 100644 --- a/pages/anime/[...id].js +++ b/pages/anime/[...id].js @@ -615,15 +615,9 @@ export async function getServerSideProps(context) { let lastPlayed = null; if (session) { - const res = await fetch(`https://moopa-anilist.vercel.app/api/get-media`, { - method: "POST", - body: JSON.stringify({ - username: session?.user.name, - }), - headers: { - "Content-Type": "application/json", - }, - }); + const res = await fetch( + `https://moopa-anilist.vercel.app/api/get-media?username=${query.user}` + ); const resp = await fetch(`/api/get-user?userName=${session?.user.name}`); const data = await resp.json(); diff --git a/pages/anime/watch/[...info].js b/pages/anime/watch/[...info].js index 4d4d420..e7195d6 100644 --- a/pages/anime/watch/[...info].js +++ b/pages/anime/watch/[...info].js @@ -423,15 +423,9 @@ export async function getServerSideProps(context) { .filter((item) => item.id == id) .map((item) => item.number); - const resp = await fetch(`https://moopa-anilist.vercel.app/api/get-media`, { - method: "POST", - body: JSON.stringify({ - username: session?.user.name, - }), - headers: { - "Content-Type": "application/json", - }, - }); + const resp = await fetch( + `https://moopa-anilist.vercel.app/api/get-media?username=${query.user}` + ); const prog = await resp.json(); diff --git a/pages/api/get-media.js b/pages/api/get-media.js index 4c65654..8558f63 100644 --- a/pages/api/get-media.js +++ b/pages/api/get-media.js @@ -1,5 +1,5 @@ export default async function handler(req, res) { - const { username, status } = req.body; + const { username, status } = req.query; try { const response = await fetch("https://graphql.anilist.co/", { diff --git a/pages/api/get-user.js b/pages/api/get-user.js index 36bc974..439d4eb 100644 --- a/pages/api/get-user.js +++ b/pages/api/get-user.js @@ -1,11 +1,11 @@ import clientPromise from "../../lib/mongodb"; -export async function getUser(userName) { +export async function getUser(userId) { const client = await clientPromise; const db = client.db("authbase"); const collection = db.collection("users"); - const user = await collection.findOne({ name: userName }); + const user = await collection.findOne({ id: userId }); if (user && user._id) { user._id = String(user._id); @@ -15,8 +15,8 @@ export async function getUser(userName) { } export default async function handler(req, res) { - const { userName } = req.query; - const user = await getUser(userName); + const { userId } = req.query; + const user = await getUser(userId); res.status(200).json(user); } diff --git a/pages/index.js b/pages/index.js index f0b6ce4..79e99ed 100644 --- a/pages/index.js +++ b/pages/index.js @@ -123,7 +123,7 @@ export default function Home({ detail, populars, sessions }) { useEffect(() => { async function userData() { if (!sessions) return; - const res = await fetch(`/api/get-user?userName=${sessions?.user.name}`); + const res = await fetch(`/api/get-user?id=${sessions?.user.id}`); const data = await res.json(); const getMedia = diff --git a/pages/profile/[user].js b/pages/profile/[user].js index f53a494..f3c6485 100644 --- a/pages/profile/[user].js +++ b/pages/profile/[user].js @@ -299,15 +299,9 @@ export async function getServerSideProps(context) { const session = await getServerSession(context.req, context.res, authOptions); const query = context.query; - const res = await fetch(`https://moopa-anilist.vercel.app/api/get-media`, { - method: "POST", - body: JSON.stringify({ - username: query.user, - }), - headers: { - "Content-Type": "application/json", - }, - }); + const res = await fetch( + `https://moopa-anilist.vercel.app/api/get-media?username=${query.user}` + ); const get = await res.json(); const sectionOrder = get?.user.mediaListOptions.animeList.sectionOrder; diff --git a/pages/testing.js b/pages/testing.js new file mode 100644 index 0000000..63d5e96 --- /dev/null +++ b/pages/testing.js @@ -0,0 +1,92 @@ +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({ sesi, data, progress, statusWatch }) { + const { data: session, status } = useSession(); + // console.log(session.user.id); + async function handleUpdate() { + // const data = ; + const res = await fetch("/api/update-user", { + method: "POST", + body: JSON.stringify({ + 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", + }, + }); + // const data = await res.json(); // parse the response body as JSON + // console.log(data.dat.id); + console.log(res.status); + } + + console.log(statusWatch); + return ( + <div> + <button onClick={() => handleUpdate()}>Click for update</button> + {!session && ( + <button onClick={() => signIn("AniListProvider")}>LOGIN</button> + )} + {session && <button onClick={() => signOut()}>LOGOUT</button>} + </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, + }, + }; +} |