aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md12
-rw-r--r--components/anime/watch/primarySide.js1
-rw-r--r--components/dataAni.json182
-rw-r--r--components/videoPlayer.js17
-rw-r--r--lib/prisma.js10
-rw-r--r--next.config.js2
-rw-r--r--package-lock.json82
-rw-r--r--package.json2
-rw-r--r--pages/_document.js4
-rw-r--r--pages/api/user/profile.js83
-rw-r--r--pages/api/user/update/episode.js119
-rw-r--r--pages/en/anime/watch/[...info].js34
-rw-r--r--pages/en/index.js37
-rw-r--r--pages/en/test.js11
-rw-r--r--prisma/migrations/20230809105139_init/migration.sql32
-rw-r--r--prisma/migrations/migration_lock.toml3
-rw-r--r--prisma/user.js317
17 files changed, 398 insertions, 550 deletions
diff --git a/README.md b/README.md
index 0802ba1..f21ccfc 100644
--- a/README.md
+++ b/README.md
@@ -92,7 +92,13 @@ git clone https://github.com/DevanAbinaya/Ani-Moopa.git
npm install
```
-3. Create `.env` file in the root folder and put this inside the file :
+3. Generate Prisma :
+
+```bash
+npx prisma generate
+```
+
+4. Create `.env` file in the root folder and put this inside the file :
```bash
## AniList
@@ -114,13 +120,13 @@ DISQUS_SHORTNAME='put your disqus shortname here. (optional)'
DATABASE_URL="Your postgresql connection url"
```
-4. Add this endpoint as Redirect Url on AniList Developer :
+5. Add this endpoint as Redirect Url on AniList Developer :
```bash
https://your-website-url/api/auth/callback/AniListProvider
```
-5. Start local server :
+6. Start local server :
```bash
npm run dev
diff --git a/components/anime/watch/primarySide.js b/components/anime/watch/primarySide.js
index 2e28563..c601795 100644
--- a/components/anime/watch/primarySide.js
+++ b/components/anime/watch/primarySide.js
@@ -136,6 +136,7 @@ export default function PrimarySide({
episodeData && (
<VideoPlayer
session={session}
+ info={info}
data={episodeData}
provider={providerId}
id={watchId}
diff --git a/components/dataAni.json b/components/dataAni.json
deleted file mode 100644
index 7ffd8ee..0000000
--- a/components/dataAni.json
+++ /dev/null
@@ -1,182 +0,0 @@
-{
- "currentPage": 1,
- "hasNextPage": false,
- "results": [
- {
- "id": "125367",
- "malId": 43608,
- "title": {
- "romaji": "Kaguya-sama wa Kokurasetai: Ultra Romantic",
- "english": "Kaguya-sama: Love is War -Ultra Romantic-",
- "native": "かぐや様は告らせたい-ウルトラロマンティック-",
- "userPreferred": "Kaguya-sama wa Kokurasetai: Ultra Romantic"
- },
- "status": "Completed",
- "image": "https://s4.anilist.co/file/anilistcdn/media/anime/cover/large/bx125367-bl5vGalMH2cC.png",
- "cover": "https://s4.anilist.co/file/anilistcdn/media/anime/banner/125367-hGPJLSNfprO3.jpg",
- "popularity": 174430,
- "description": "The elite members of Shuchiin Academy's student council continue their competitive day-to-day antics. Council president Miyuki Shirogane clashes daily against vice-president Kaguya Shinomiya, each fighting tooth and nail to trick the other into confessing their romantic love. Kaguya struggles within the strict confines of her wealthy, uptight family, rebelling against her cold default demeanor as she warms to Shirogane and the rest of her friends.<br>\n<br>\nMeanwhile, council treasurer Yuu Ishigami suffers under the weight of his hopeless crush on Tsubame Koyasu, a popular upperclassman who helps to instill a new confidence in him. Miko Iino, the newest student council member, grows closer to the rule-breaking Ishigami while striving to overcome her own authoritarian moral code.<br>\n<br>\nAs love further blooms at Shuchiin Academy, the student council officers drag their outsider friends into increasingly comedic conflicts.<br>\n<br>\n(Source: MAL Rewrite)<br>\n<br>\n<i>Note: The first episode had an advanced screening on April 2, in both New York & Los Angeles.<br>",
- "rating": 90,
- "genres": ["Comedy", "Psychological", "Romance", "Slice of Life"],
- "color": "#d6f1a1",
- "totalEpisodes": 13,
- "currentEpisodeCount": 13,
- "type": "TV",
- "releaseDate": 2022
- },
- {
- "id": "112641",
- "malId": 40591,
- "title": {
- "romaji": "Kaguya-sama wa Kokurasetai?: Tensaitachi no Renai Zunousen",
- "english": "Kaguya-sama: Love is War?",
- "native": "かぐや様は告らせたい?~天才たちの恋愛頭脳戦~",
- "userPreferred": "Kaguya-sama wa Kokurasetai?: Tensaitachi no Renai Zunousen"
- },
- "status": "Completed",
- "image": "https://s4.anilist.co/file/anilistcdn/media/anime/cover/large/bx112641-zoGC8d6FaPXU.jpg",
- "cover": "https://s4.anilist.co/file/anilistcdn/media/anime/banner/112641-mKZe0zng0ndV.jpg",
- "popularity": 303429,
- "description": "After a slow but eventful summer vacation, Shuchiin Academy's second term is now starting in full force. As August transitions into September, Miyuki Shirogane's birthday looms ever closer, leaving Kaguya Shinomiya in a serious predicament as to how to celebrate it. Furthermore, the tenure of the school's 67th student council is coming to an end. Due to the council members being in different classes, the only time Kaguya and Miyuki have to be together will soon disappear, putting all of their cunning plans at risk.<br></br>\n\nA long and difficult election that will decide the fate of the new student council awaits, as multiple challengers fight for the coveted title of president.<br></br>\n",
- "rating": 86,
- "genres": ["Comedy", "Psychological", "Romance", "Slice of Life"],
- "color": "#DAD797",
- "totalEpisodes": 12,
- "currentEpisodeCount": 12,
- "type": "TV",
- "releaseDate": 2020
- },
- {
- "id": "101921",
- "malId": 37999,
- "title": {
- "romaji": "Kaguya-sama wa Kokurasetai: Tensaitachi no Renai Zunousen",
- "english": "Kaguya-sama: Love is War",
- "native": "かぐや様は告らせたい~天才たちの恋愛頭脳戦~",
- "userPreferred": "Kaguya-sama wa Kokurasetai: Tensaitachi no Renai Zunousen"
- },
- "status": "Completed",
- "image": "https://s4.anilist.co/file/anilistcdn/media/anime/cover/large/bx101921-VvdGQy1ZySYf.jpg",
- "cover": "https://s4.anilist.co/file/anilistcdn/media/anime/banner/101921-GgvvFhlNhzlF.jpg",
- "popularity": 378107,
- "description": "Known for being both brilliant and powerful, Miyuki Shirogane and Kaguya Shinomiya lead the illustrious Shuchiin Academy as near equals. And everyone thinks they’d make a great couple. Pride and arrogance are in ample supply, so the only logical move is to trick the other into instigating a date! Who will come out on top in this psychological war where the first move is the only one that matters?\n<br><br>\n(Source: Aniplex)",
- "rating": 83,
- "genres": ["Comedy", "Psychological", "Romance", "Slice of Life"],
- "color": "#e45086",
- "totalEpisodes": 12,
- "currentEpisodeCount": 12,
- "type": "TV",
- "releaseDate": 2019
- },
- {
- "id": "125368",
- "malId": 43609,
- "title": {
- "romaji": "Kaguya-sama wa Kokurasetai: Tensaitachi no Renai Zunousen OVA",
- "english": null,
- "native": "かぐや様は告らせたい~天才たちの恋愛頭脳戦~OVA",
- "userPreferred": "Kaguya-sama wa Kokurasetai: Tensaitachi no Renai Zunousen OVA"
- },
- "status": "Completed",
- "image": "https://s4.anilist.co/file/anilistcdn/media/anime/cover/large/bx125368-QhcBkbNP0ZfU.png",
- "cover": "https://s4.anilist.co/file/anilistcdn/media/anime/banner/125368-zCY0WnSQl7RG.jpg",
- "popularity": 63453,
- "description": "OVA adapting both chapters of <i>Kaguya-sama wa Kokurasetai Darkness</i> and Chapter 96 of the main series.",
- "rating": 75,
- "genres": ["Comedy", "Ecchi", "Romance", "Slice of Life"],
- "color": "#c97843",
- "totalEpisodes": 1,
- "currentEpisodeCount": 1,
- "type": "OVA",
- "releaseDate": 2021
- },
- {
- "id": "151384",
- "malId": 52198,
- "title": {
- "romaji": "Kaguya-sama wa Kokurasetai: First Kiss wa Owaranai",
- "english": "Kaguya-sama: Love is War -The First Kiss That Never Ends-",
- "native": "かぐや様は告らせたい -ファーストキッスは終わらない-",
- "userPreferred": "Kaguya-sama wa Kokurasetai: First Kiss wa Owaranai"
- },
- "status": "Completed",
- "image": "https://s4.anilist.co/file/anilistcdn/media/anime/cover/large/bx151384-gv0q8wOE6D58.jpg",
- "cover": "https://s4.anilist.co/file/anilistcdn/media/anime/banner/151384-JybfIpHr2gx6.jpg",
- "popularity": 68747,
- "description": "Shuchiin Academy’s student council room: the place where Student Council Vice President Kaguya Shinomiya and President Miyuki Shirogane met. After a long battle in love, these two geniuses communicated their feelings and, at the Hoshin Festival, had their very first kiss. However, there was no clear confession of love. The relationship between these two, who assumed they would be a couple, remains ambiguous. Now, overly conscious of their feelings, they must face the biggest challenge yet: Christmas. It’s Shirogane who wants it to be perfect versus Kaguya who pursues the imperfect situation. This is the very “normal” love story of two geniuses and the first kiss that never ends.\n<br><br>\n(Source: Aniplex of America)\n<br><br>\n<em>Kaguya-sama: Love is War -The First Kiss That Never Ends- first premiered in theaters across Japan on December 17, 2022. It was later released as 4 episodes on TV, streaming, and Blu-Ray/DVD.<em>",
- "rating": 88,
- "genres": ["Comedy", "Psychological", "Romance", "Slice of Life"],
- "color": "#e45d78",
- "totalEpisodes": 4,
- "currentEpisodeCount": 4,
- "type": "TV",
- "releaseDate": 2023
- },
- {
- "id": "3322",
- "malId": 3322,
- "title": {
- "romaji": "Wagaya no Oinari-sama.",
- "english": "Our Home's Fox Deity",
- "native": "我が家のお稲荷さま。",
- "userPreferred": "Wagaya no Oinari-sama."
- },
- "status": "Completed",
- "image": "https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/3322.jpg",
- "cover": null,
- "popularity": 4111,
- "description": "The Mizuchi bloodline has long been hunted by Yokai, or monsters. Toru and Noboru Takagami are descendents of this bloodline, and under their grandmother's discretion, are given a secret weapon to combat these monsters. It is Tenko Kugen, a fox deity who can take the shape of a man or woman at will. The mischievous deity is accompanied by a shrine maiden, Ko, who will both live with the Takagami brothers at their house. Life just got complicated. <br><br>\n(Source: NIS America) ",
- "rating": 66,
- "genres": ["Adventure", "Fantasy", "Supernatural"],
- "color": "#f1a150",
- "totalEpisodes": 24,
- "currentEpisodeCount": 24,
- "type": "TV",
- "releaseDate": 2008
- },
- {
- "id": "5484",
- "malId": 5484,
- "title": {
- "romaji": "Wagaya no Oinari-sama. Specials",
- "english": null,
- "native": "我が家のお稲荷さま。",
- "userPreferred": "Wagaya no Oinari-sama. Specials"
- },
- "status": "Completed",
- "image": "https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/5484.jpg",
- "cover": null,
- "popularity": 458,
- "description": "Short comedy sketches involving Tenko &amp; Kou.",
- "rating": 55,
- "genres": ["Adventure", "Comedy", "Fantasy", "Supernatural"],
- "color": "#aed678",
- "totalEpisodes": 12,
- "currentEpisodeCount": 12,
- "type": "SPECIAL",
- "releaseDate": 2008
- },
- {
- "id": "165557",
- "malId": 50325,
- "title": {
- "romaji": "Kaguya-sama wa Kokurasetai: Ultra Romantic 3rd Season Teaser PV - Ishigami Yuu wa Kataritai",
- "english": "Kaguya-sama: Love is War -Ultra Romantic- \"Yu Ishigami Wants to Chat\"",
- "native": "第3期『かぐや様は告らせたい-ウルトラロマンティック-』 / ティザーPV 「石上優は語りたい」",
- "userPreferred": "Kaguya-sama wa Kokurasetai: Ultra Romantic 3rd Season Teaser PV - Ishigami Yuu wa Kataritai"
- },
- "status": "Completed",
- "image": "https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/b165557-q7A6HcZD0CHs.png",
- "cover": null,
- "popularity": 2412,
- "description": "Every Thursday, Shuchiin Academy student council secretary Yuu Ishigami can be found in a state of anxiety. He counts down the hours until he can escape to the student council chamber to read the latest chapter of the popular seinen manga series, \"Momo Doesn't Think.\" Joining Ishigami in his weekly reading, student council president Miyuki Shirogane swiftly grows excited at the news of a third season of the manga's anime adaptation.<br><br>\n\nHowever, it is only a matter of time before vice president Kaguya Shinomiya discovers what has been engrossing the two boys. With the stigma of being labeled an otaku looming over his head, Shirogane must do everything he can to keep his embarrassing secret from coming to light.<br><br>\n\n(Source: MAL Rewrite)<br><br>\n\n<i>Note: This short PV adapts the 110th chapter of the manga and serves as a teaser for the April 2022 release of Kaguya-sama wa Kokurasetai: Ultra Romantic.</i>",
- "rating": 77,
- "genres": ["Comedy", "Romance"],
- "color": "#f1d6c9",
- "totalEpisodes": 1,
- "currentEpisodeCount": 1,
- "type": "ONA",
- "releaseDate": 2021
- }
- ]
-}
diff --git a/components/videoPlayer.js b/components/videoPlayer.js
index 8f08fd3..46129ab 100644
--- a/components/videoPlayer.js
+++ b/components/videoPlayer.js
@@ -20,6 +20,7 @@ const fontSize = [
];
export default function VideoPlayer({
+ info,
data,
id,
progress,
@@ -213,7 +214,7 @@ export default function VideoPlayer({
});
let marked = 0;
-
+
art.on("video:playing", () => {
if (!session) return;
const intervalId = setInterval(async () => {
@@ -225,8 +226,11 @@ export default function VideoPlayer({
watchId: id,
title: track?.playing?.title || aniTitle,
aniTitle: aniTitle,
- image: track?.playing?.image,
- number: track?.playing?.number,
+ image:
+ track?.playing?.image ||
+ info?.bannerImage ||
+ info?.coverImage?.extraLarge,
+ number: Number(progress),
duration: art.duration,
timeWatched: art.currentTime,
provider: provider,
@@ -256,8 +260,11 @@ export default function VideoPlayer({
watchId: id,
title: track?.playing?.title || aniTitle,
aniTitle: aniTitle,
- image: track?.playing?.image,
- episode: track?.playing?.number,
+ image:
+ track?.playing?.image ||
+ info?.bannerImage ||
+ info?.coverImage?.extraLarge,
+ episode: Number(progress),
duration: art.duration,
timeWatched: art.currentTime,
provider: provider,
diff --git a/lib/prisma.js b/lib/prisma.js
index 7a6e5d7..ed8c421 100644
--- a/lib/prisma.js
+++ b/lib/prisma.js
@@ -1,11 +1,5 @@
import { PrismaClient } from "@prisma/client";
-const globalForPrisma = globalThis;
+export const prisma = global.prisma || new PrismaClient();
-const prisma = globalForPrisma.prisma || new PrismaClient();
-
-if (process.env.NODE_ENV !== "production") {
- globalForPrisma.prisma = prisma;
-}
-
-module.exports = { prisma };
+if (process.env.NODE_ENV !== "production") global.prisma = prisma;
diff --git a/next.config.js b/next.config.js
index d71ca7e..fcf654b 100644
--- a/next.config.js
+++ b/next.config.js
@@ -20,7 +20,7 @@ module.exports = withPWA({
},
distDir: process.env.BUILD_DIR || ".next",
trailingSlash: true,
- output: 'standalone',
+ output: "standalone",
// async headers() {
// return [
// {
diff --git a/package-lock.json b/package-lock.json
index 3684da5..a1ff279 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "moopa",
- "version": "3.9.0",
+ "version": "3.9.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "moopa",
- "version": "3.9.0",
+ "version": "3.9.1",
"dependencies": {
"@apollo/client": "^3.7.3",
"@headlessui/react": "^1.7.15",
@@ -3786,12 +3786,6 @@
"node": ">= 8"
}
},
- "node_modules/crypto": {
- "version": "1.0.1",
- "resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz",
- "integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==",
- "deprecated": "This package is no longer supported. It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in."
- },
"node_modules/crypto-random-string": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-2.0.0.tgz",
@@ -5866,70 +5860,6 @@
"node": ">=8"
}
},
- "node_modules/jake/node_modules/ansi-styles": {
- "version": "4.3.0",
- "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
- "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
- "dependencies": {
- "color-convert": "^2.0.1"
- },
- "engines": {
- "node": ">=8"
- },
- "funding": {
- "url": "https://github.com/chalk/ansi-styles?sponsor=1"
- }
- },
- "node_modules/jake/node_modules/chalk": {
- "version": "4.1.2",
- "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
- "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
- "dependencies": {
- "ansi-styles": "^4.1.0",
- "supports-color": "^7.1.0"
- },
- "engines": {
- "node": ">=10"
- },
- "funding": {
- "url": "https://github.com/chalk/chalk?sponsor=1"
- }
- },
- "node_modules/jake/node_modules/color-convert": {
- "version": "2.0.1",
- "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
- "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
- "dependencies": {
- "color-name": "~1.1.4"
- },
- "engines": {
- "node": ">=7.0.0"
- }
- },
- "node_modules/jake/node_modules/color-name": {
- "version": "1.1.4",
- "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
- "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
- },
- "node_modules/jake/node_modules/has-flag": {
- "version": "4.0.0",
- "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
- "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
- "engines": {
- "node": ">=8"
- }
- },
- "node_modules/jake/node_modules/supports-color": {
- "version": "7.2.0",
- "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
- "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
- "dependencies": {
- "has-flag": "^4.0.0"
- },
- "engines": {
- "node": ">=8"
- }
- },
"node_modules/jest-worker": {
"version": "27.5.1",
"resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-27.5.1.tgz",
@@ -5951,14 +5881,6 @@
"node": ">=8"
}
},
- "node_modules/jest-worker/node_modules/has-flag": {
- "version": "4.0.0",
- "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
- "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
- "engines": {
- "node": ">=8"
- }
- },
"node_modules/jest-worker/node_modules/supports-color": {
"version": "8.1.1",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz",
diff --git a/package.json b/package.json
index 3d2c0eb..b5ddad8 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "moopa",
- "version": "3.9.0",
+ "version": "3.9.1",
"private": true,
"founder": "Factiven",
"scripts": {
diff --git a/pages/_document.js b/pages/_document.js
index d79f31f..31be82b 100644
--- a/pages/_document.js
+++ b/pages/_document.js
@@ -1,10 +1,6 @@
import { Html, Head, Main, NextScript } from "next/document";
-// import { randomBytes } from "crypto";
export default function Document() {
- // const nonce = randomBytes(128).toString("base64");
- // const csp = `object-src 'none'; base-uri 'none'; script-src 'self' 'unsafe-eval' 'unsafe-inline' https: http: 'nonce-${nonce}' 'strict-dynamic'`;
-
return (
<Html lang="en">
<Head>
diff --git a/pages/api/user/profile.js b/pages/api/user/profile.js
index 2b44ae2..dd22bd8 100644
--- a/pages/api/user/profile.js
+++ b/pages/api/user/profile.js
@@ -1,3 +1,6 @@
+import { getServerSession } from "next-auth";
+import { authOptions } from "../auth/[...nextauth]";
+
import {
createUser,
deleteUser,
@@ -6,47 +9,55 @@ import {
} from "../../../prisma/user";
export default async function handler(req, res) {
- try {
- switch (req.method) {
- case "POST": {
- const { name, setting } = req.body;
- const new_user = await createUser(name, setting);
- if (!new_user) {
- return res.status(200).json({ message: "User is already created" });
- } else {
- return res.status(201).json(new_user);
+ const session = await getServerSession(req, res, authOptions);
+ if (session) {
+ // Signed in
+ try {
+ switch (req.method) {
+ case "POST": {
+ const { name, setting } = req.body;
+ const new_user = await createUser(name, setting);
+ if (!new_user) {
+ return res.status(200).json({ message: "User is already created" });
+ } else {
+ return res.status(201).json(new_user);
+ }
}
- }
- case "PUT": {
- const { name, anime } = req.body;
- const user = await updateUser(name, anime);
- if (!user) {
- return res.status(200).json({ message: "Title is already there" });
- } else {
- return res.status(200).json(user);
+ case "PUT": {
+ const { name, anime } = req.body;
+ const user = await updateUser(name, anime);
+ if (!user) {
+ return res.status(200).json({ message: "Title is already there" });
+ } else {
+ return res.status(200).json(user);
+ }
}
- }
- case "GET": {
- const { name } = req.query;
- const user = await getUser(name);
- if (!user) {
- return res.status(404).json({ message: "User not found" });
- } else {
- return res.status(200).json(user);
+ case "GET": {
+ const { name } = req.query;
+ const user = await getUser(name);
+ if (!user) {
+ return res.status(404).json({ message: "User not found" });
+ } else {
+ return res.status(200).json(user);
+ }
}
- }
- case "DELETE": {
- const { name } = req.body;
- const user = await deleteUser(name);
- if (!user) {
- return res.status(404).json({ message: "User not found" });
- } else {
- return res.status(200).json(user);
+ case "DELETE": {
+ const { name } = req.body;
+ const user = await deleteUser(name);
+ if (!user) {
+ return res.status(404).json({ message: "User not found" });
+ } else {
+ return res.status(200).json(user);
+ }
}
}
+ } catch (error) {
+ console.log(error);
+ return res.status(500).json({ message: "Internal server error" });
}
- } catch (error) {
- console.log(error);
- return res.status(500).json({ message: "Internal server error" });
+ } else {
+ // Not Signed in
+ res.status(401);
}
+ res.end();
}
diff --git a/pages/api/user/update/episode.js b/pages/api/user/update/episode.js
index f69bb78..7974446 100644
--- a/pages/api/user/update/episode.js
+++ b/pages/api/user/update/episode.js
@@ -1,3 +1,6 @@
+import { getServerSession } from "next-auth";
+import { authOptions } from "../../auth/[...nextauth]";
+
import {
createList,
getEpisode,
@@ -5,64 +8,74 @@ import {
} from "../../../../prisma/user";
export default async function handler(req, res) {
- try {
- switch (req.method) {
- case "POST": {
- const { name, id } = JSON.parse(req.body);
+ const session = await getServerSession(req, res, authOptions);
+ if (session) {
+ // Signed in
+ try {
+ switch (req.method) {
+ case "POST": {
+ const { name, id } = JSON.parse(req.body);
- const episode = await createList(name, id);
- if (!episode) {
- return res
- .status(200)
- .json({ message: "Episode is already created" });
- } else {
- return res.status(201).json(episode);
+ const episode = await createList(name, id);
+ if (!episode) {
+ return res
+ .status(200)
+ .json({ message: "Episode is already created" });
+ } else {
+ return res.status(201).json(episode);
+ }
}
- }
- case "PUT": {
- const {
- name,
- id,
- watchId,
- title,
- image,
- number,
- duration,
- timeWatched,
- aniTitle,
- provider,
- } = JSON.parse(req.body);
- const episode = await updateUserEpisode({
- name,
- id,
- watchId,
- title,
- image,
- number,
- duration,
- timeWatched,
- aniTitle,
- provider,
- });
- if (!episode) {
- return res.status(200).json({ message: "Episode is already there" });
- } else {
- return res.status(200).json(episode);
+ case "PUT": {
+ const {
+ name,
+ id,
+ watchId,
+ title,
+ image,
+ number,
+ duration,
+ timeWatched,
+ aniTitle,
+ provider,
+ } = JSON.parse(req.body);
+ const episode = await updateUserEpisode({
+ name,
+ id,
+ watchId,
+ title,
+ image,
+ number,
+ duration,
+ timeWatched,
+ aniTitle,
+ provider,
+ });
+ if (!episode) {
+ return res
+ .status(200)
+ .json({ message: "Episode is already there" });
+ } else {
+ return res.status(200).json(episode);
+ }
}
- }
- case "GET": {
- const { name, id } = req.query;
- // console.log(req.query);
- const episode = await getEpisode(name, id);
- if (!episode) {
- return res.status(404).json({ message: "Episode not found" });
- } else {
- return res.status(200).json(episode);
+ case "GET": {
+ const { name, id } = req.query;
+ // console.log(req.query);
+ const episode = await getEpisode(name, id);
+ if (!episode) {
+ return res.status(404).json({ message: "Episode not found" });
+ } else {
+ return res.status(200).json(episode);
+ }
}
}
+ } catch (error) {
+ console.log(error);
+ return res.status(500).json({ message: "Internal server error" });
}
- } catch (error) {
- console.log(error);
- return res.status(500).json({ message: "Internal server error" });
+ } else {
+ // Not Signed in
+ res.status(401);
}
+ res.end();
}
diff --git a/pages/en/anime/watch/[...info].js b/pages/en/anime/watch/[...info].js
index bc8851b..e013c6b 100644
--- a/pages/en/anime/watch/[...info].js
+++ b/pages/en/anime/watch/[...info].js
@@ -62,6 +62,7 @@ export default function Info({
}
}
}
+ bannerImage
description
coverImage {
extraLarge
@@ -127,7 +128,7 @@ export default function Info({
}
}
}
-
+
setInfo(data.data.Media);
const response = await fetch(
@@ -159,7 +160,7 @@ export default function Info({
setLoading(false);
}
}
-
+
setArtStorage(JSON.parse(localStorage.getItem("artplayer_settings")));
// setEpiData(episodes);
setLoading(false);
@@ -237,18 +238,23 @@ export async function getServerSideProps(context) {
let userData = null;
- if (session) {
- await createUser(session.user.name);
- await createList(session.user.name, watchId);
- const data = await getEpisode(session.user.name, watchId);
- userData = JSON.parse(
- JSON.stringify(data, (key, value) => {
- if (key === "createdDate") {
- return String(value);
- }
- return value;
- })
- );
+ try {
+ if (session) {
+ await createUser(session.user.name);
+ await createList(session.user.name, watchId);
+ const data = await getEpisode(session.user.name, watchId);
+ userData = JSON.parse(
+ JSON.stringify(data, (key, value) => {
+ if (key === "createdDate") {
+ return String(value);
+ }
+ return value;
+ })
+ );
+ }
+ } catch (error) {
+ console.error(error);
+ // Handle the error here
}
return {
diff --git a/pages/en/index.js b/pages/en/index.js
index c3a98fc..159d257 100644
--- a/pages/en/index.js
+++ b/pages/en/index.js
@@ -29,8 +29,13 @@ import { ToastContainer, toast } from "react-toastify";
export async function getServerSideProps(context) {
const session = await getServerSession(context.req, context.res, authOptions);
- if (session) {
- await createUser(session.user.name);
+ try {
+ if (session) {
+ await createUser(session.user.name);
+ }
+ } catch (error) {
+ console.error(error);
+ // Handle the error here
}
const trendingDetail = await aniListData({
@@ -145,22 +150,34 @@ export default function Home({ detail, populars, sessions, upComing }) {
useEffect(() => {
async function userData() {
let data;
- if (sessions?.user?.name) {
- data = await fetch(
- `/api/user/profile?name=${sessions?.user?.name}`
- ).then((res) => {
+ try {
+ if (sessions?.user?.name) {
+ const res = await fetch(
+ `/api/user/profile?name=${sessions.user.name}`
+ );
if (!res.ok) {
switch (res.status) {
case 404: {
- return console.log("user not found");
+ console.log("user not found");
+ break;
}
case 500: {
- return console.log("server error");
+ console.log("server error");
+ break;
+ }
+ default: {
+ console.log("unknown error");
+ break;
}
}
+ } else {
+ data = await res.json();
+ // Do something with the data
}
- return res.json();
- });
+ }
+ } catch (error) {
+ console.error(error);
+ // Handle the error here
}
if (!data) {
const dat = JSON.parse(localStorage.getItem("artplayer_settings"));
diff --git a/pages/en/test.js b/pages/en/test.js
deleted file mode 100644
index cf76827..0000000
--- a/pages/en/test.js
+++ /dev/null
@@ -1,11 +0,0 @@
-import VideoPlayer from "../../components/videoPlayer";
-
-export default function Test() {
- return (
- <div className="flex-center w-screen h-screen">
- <div className="h-full aspect-video bg-black">
- <VideoPlayer />
- </div>
- </div>
- );
-}
diff --git a/prisma/migrations/20230809105139_init/migration.sql b/prisma/migrations/20230809105139_init/migration.sql
new file mode 100644
index 0000000..67268c9
--- /dev/null
+++ b/prisma/migrations/20230809105139_init/migration.sql
@@ -0,0 +1,32 @@
+-- CreateTable
+CREATE TABLE "UserProfile" (
+ "id" TEXT NOT NULL,
+ "name" TEXT NOT NULL,
+ "setting" JSONB,
+
+ CONSTRAINT "UserProfile_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateTable
+CREATE TABLE "WatchListEpisode" (
+ "id" TEXT NOT NULL,
+ "aniId" TEXT,
+ "title" TEXT,
+ "aniTitle" TEXT,
+ "image" TEXT,
+ "episode" INTEGER,
+ "timeWatched" INTEGER,
+ "duration" INTEGER,
+ "provider" TEXT,
+ "createdDate" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
+ "userProfileId" TEXT NOT NULL,
+ "watchId" TEXT NOT NULL,
+
+ CONSTRAINT "WatchListEpisode_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateIndex
+CREATE UNIQUE INDEX "UserProfile_name_key" ON "UserProfile"("name");
+
+-- AddForeignKey
+ALTER TABLE "WatchListEpisode" ADD CONSTRAINT "WatchListEpisode_userProfileId_fkey" FOREIGN KEY ("userProfileId") REFERENCES "UserProfile"("name") ON DELETE RESTRICT ON UPDATE CASCADE;
diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml
new file mode 100644
index 0000000..fbffa92
--- /dev/null
+++ b/prisma/migrations/migration_lock.toml
@@ -0,0 +1,3 @@
+# Please do not edit this file manually
+# It should be added in your version-control system (i.e. Git)
+provider = "postgresql" \ No newline at end of file
diff --git a/prisma/user.js b/prisma/user.js
index 04222d5..8c436a5 100644
--- a/prisma/user.js
+++ b/prisma/user.js
@@ -1,157 +1,183 @@
-// import { prisma } from "../lib/prisma";
-import { PrismaClient } from "@prisma/client";
-const prisma = new PrismaClient();
+// import { PrismaClient } from "@prisma/client";
+// const prisma = new PrismaClient();
+
+import { prisma } from "../lib/prisma";
export const createUser = async (name, setting) => {
- const checkUser = await prisma.userProfile.findUnique({
- where: {
- name: name,
- },
- });
- if (!checkUser) {
- const user = await prisma.userProfile.create({
- data: {
+ try {
+ const checkUser = await prisma.userProfile.findUnique({
+ where: {
name: name,
- setting,
},
});
+ if (!checkUser) {
+ const user = await prisma.userProfile.create({
+ data: {
+ name: name,
+ },
+ });
- return user;
- } else {
- return null;
+ return user;
+ } else {
+ return null;
+ }
+ } catch (error) {
+ console.error(error);
+ throw new Error("Error creating user");
}
};
export const updateUser = async (name, anime) => {
- const checkAnime = await prisma.watchListItem.findUnique({
- where: {
- title: anime.title,
- userProfileId: name,
- },
- });
- if (checkAnime) {
- const checkEpisode = await prisma.watchListEpisode.findUnique({
+ try {
+ const checkAnime = await prisma.watchListItem.findUnique({
where: {
- url: anime.id,
+ title: anime.title,
+ userProfileId: name,
},
});
- if (checkEpisode) {
- return null;
- } else {
- const user = await prisma.watchListItem.update({
+ if (checkAnime) {
+ const checkEpisode = await prisma.watchListEpisode.findUnique({
where: {
- title: anime.title,
- userProfileId: name,
+ url: anime.id,
},
});
- }
- } else {
- const user = await prisma.userProfile.update({
- where: { name: name },
- data: {
- watchList: {
- create: {
+ if (checkEpisode) {
+ return null;
+ } else {
+ const user = await prisma.watchListItem.update({
+ where: {
title: anime.title,
- episodes: {
- create: {
- url: anime.id,
+ userProfileId: name,
+ },
+ });
+ }
+ } else {
+ const user = await prisma.userProfile.update({
+ where: { name: name },
+ data: {
+ watchList: {
+ create: {
+ title: anime.title,
+ episodes: {
+ create: {
+ url: anime.id,
+ },
},
},
},
},
- },
- include: {
- watchList: true,
- },
- });
+ include: {
+ watchList: true,
+ },
+ });
- return user;
+ return user;
+ }
+ } catch (error) {
+ console.error(error);
+ throw new Error("Error updating user");
}
};
export const getUser = async (name) => {
- if (!name) {
- const user = await prisma.userProfile.findMany({
- include: {
- WatchListEpisode: true,
- },
- });
- return user;
- } else {
- const user = await prisma.userProfile.findFirst({
- where: {
- name: name,
- },
- include: {
- WatchListEpisode: {
- orderBy: {
- createdDate: "desc",
+ try {
+ if (!name) {
+ const user = await prisma.userProfile.findMany({
+ include: {
+ WatchListEpisode: true,
+ },
+ });
+ return user;
+ } else {
+ const user = await prisma.userProfile.findFirst({
+ where: {
+ name: name,
+ },
+ include: {
+ WatchListEpisode: {
+ orderBy: {
+ createdDate: "desc",
+ },
},
},
- },
- });
- return user;
+ });
+ return user;
+ }
+ } catch (error) {
+ console.error(error);
+ throw new Error("Error getting user");
}
};
export const deleteUser = async (name) => {
- const user = await prisma.userProfile.delete({
- where: {
- name: name,
- },
- });
- return user;
+ try {
+ const user = await prisma.userProfile.delete({
+ where: {
+ name: name,
+ },
+ });
+ return user;
+ } catch (error) {
+ console.error(error);
+ throw new Error("Error deleting user");
+ }
};
export const createList = async (name, id, title) => {
- const checkEpisode = await prisma.watchListEpisode.findFirst({
- where: {
- userProfileId: name,
- watchId: id,
- },
- });
- if (checkEpisode) {
- return null;
- } else {
- const episode = await prisma.userProfile.update({
- where: { name: name },
- data: {
- WatchListEpisode: {
- create: [
- {
- watchId: id,
- },
- ],
- },
- },
- include: {
- WatchListEpisode: true,
+ try {
+ const checkEpisode = await prisma.watchListEpisode.findFirst({
+ where: {
+ userProfileId: name,
+ watchId: id,
},
});
- return episode;
+ if (checkEpisode) {
+ return null;
+ } else {
+ const episode = await prisma.userProfile.update({
+ where: { name: name },
+ data: {
+ WatchListEpisode: {
+ create: [
+ {
+ watchId: id,
+ },
+ ],
+ },
+ },
+ include: {
+ WatchListEpisode: true,
+ },
+ });
+ return episode;
+ }
+ } catch (error) {
+ console.error(error);
+ throw new Error("Error creating list");
}
};
export const getEpisode = async (name, id) => {
- console.log({ name, id });
- const episode = await prisma.watchListEpisode.findMany({
- // where: {
- // AND: [{ userProfileId: name }, { watchId: id }],
- // },
- where: {
- AND: [
- {
- userProfileId: name,
- },
- {
- watchId: {
- equals: id,
+ try {
+ const episode = await prisma.watchListEpisode.findMany({
+ where: {
+ AND: [
+ {
+ userProfileId: name,
},
- },
- ],
- },
- });
- return episode;
+ {
+ watchId: {
+ equals: id,
+ },
+ },
+ ],
+ },
+ });
+ return episode;
+ } catch (error) {
+ console.error(error);
+ throw new Error("Error getting episode");
+ }
};
export const updateUserEpisode = async ({
@@ -166,38 +192,45 @@ export const updateUserEpisode = async ({
aniTitle,
provider,
}) => {
- const user = await prisma.watchListEpisode.updateMany({
- where: {
- userProfileId: name,
- watchId: watchId,
- },
- data: {
- title: title,
- aniTitle: aniTitle,
- image: image,
- aniId: id,
- provider: provider,
- duration: duration,
- episode: number,
- timeWatched: timeWatched,
- createdDate: new Date(),
- },
- });
-
- // const user = name;
+ try {
+ const user = await prisma.watchListEpisode.updateMany({
+ where: {
+ userProfileId: name,
+ watchId: watchId,
+ },
+ data: {
+ title: title,
+ aniTitle: aniTitle,
+ image: image,
+ aniId: id,
+ provider: provider,
+ duration: duration,
+ episode: number,
+ timeWatched: timeWatched,
+ createdDate: new Date(),
+ },
+ });
- return user;
+ return user;
+ } catch (error) {
+ console.error(error);
+ throw new Error("Error updating user episode");
+ }
};
export const updateTimeWatched = async (id, timeWatched) => {
- const user = await prisma.watchListEpisode.update({
- where: {
- id: id,
- // userProfileId: name,
- },
- data: {
- timeWatched: timeWatched,
- },
- });
- return user;
+ try {
+ const user = await prisma.watchListEpisode.update({
+ where: {
+ id: id,
+ },
+ data: {
+ timeWatched: timeWatched,
+ },
+ });
+ return user;
+ } catch (error) {
+ console.error(error);
+ throw new Error("Error updating time watched");
+ }
};