From 5007e48c8546d8138092039bf3cecc0b9904a407 Mon Sep 17 00:00:00 2001 From: Factiven Date: Thu, 13 Apr 2023 22:14:50 +0700 Subject: Update 4th --- components/videoPlayer.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'components') diff --git a/components/videoPlayer.js b/components/videoPlayer.js index e568772..092f53a 100644 --- a/components/videoPlayer.js +++ b/components/videoPlayer.js @@ -90,7 +90,7 @@ export default function VideoPlayer({ // use >= instead of > markProgress(aniId, progress); } else { - console.log("Something went wrong"); + return; } }); @@ -99,11 +99,25 @@ export default function VideoPlayer({ console.log("Video ended"); }); - art.on("destroy", () => { + art.on("destroy", async () => { + if (!session) return; const lastPlayed = { id: id, time: art.currentTime, }; + const res = await fetch("/api/watched-episode", { + method: "POST", + body: JSON.stringify({ + username: session?.user.name, + id: aniId, + newData: lastPlayed, + }), + headers: { + "Content-Type": "application/json", + }, + }); + + console.log(res.status); const title = titles; const prevDataStr = localStorage.getItem("lastPlayed") || "[]"; -- cgit v1.2.3