From e1750f1c6ba18feee435f4fd174a3681a07cbd6b Mon Sep 17 00:00:00 2001 From: "impr.visible@gmail.com" Date: Sun, 16 Apr 2023 19:48:55 +0200 Subject: [PATCH] Portage to react Everything is rewrited with React --- package.json | 92 +++---- src/AddMedia.js | 351 +++++++++++++++++++++++ src/App.css | 138 +++++++--- src/Book.js | 1 + src/Books.js | 23 +- src/CreateAccount.js | 84 ++++++ src/EditMovie.js | 25 +- src/EditSerie.js | 55 +--- src/Header.js | 23 +- src/Login.js | 10 +- src/Movie.js | 21 +- src/Movies.js | 81 +++++- src/Season.js | 35 ++- src/SetServerAdress.js | 29 +- src/Settings.js | 236 +++++++++++++++- src/index.js | 38 +-- src/static/js/actor.js | 474 -------------------------------- src/static/js/addMedia.js | 238 ---------------- src/static/js/book.js | 84 ------ src/static/js/books.js | 48 ---- src/static/js/channel.js | 34 --- src/static/js/consoles.js | 47 ---- src/static/js/createAccount.js | 7 - src/static/js/editMovie.js | 35 --- src/static/js/editSerie.js | 35 --- src/static/js/game.js | 4 - src/static/js/games.js | 45 --- src/static/js/main.js | 42 --- src/static/js/other.js | 166 ----------- src/static/js/otherVideo.js | 163 ----------- src/static/js/profil.js | 38 --- src/static/js/service-worker.js | 107 ------- src/static/js/settings.js | 260 ------------------ src/static/js/tv.js | 71 ----- 34 files changed, 1019 insertions(+), 2121 deletions(-) create mode 100644 src/AddMedia.js create mode 100644 src/CreateAccount.js delete mode 100644 src/static/js/actor.js delete mode 100644 src/static/js/addMedia.js delete mode 100644 src/static/js/book.js delete mode 100644 src/static/js/books.js delete mode 100644 src/static/js/channel.js delete mode 100644 src/static/js/consoles.js delete mode 100644 src/static/js/createAccount.js delete mode 100644 src/static/js/editMovie.js delete mode 100644 src/static/js/editSerie.js delete mode 100644 src/static/js/game.js delete mode 100644 src/static/js/games.js delete mode 100644 src/static/js/main.js delete mode 100644 src/static/js/other.js delete mode 100644 src/static/js/otherVideo.js delete mode 100644 src/static/js/profil.js delete mode 100644 src/static/js/service-worker.js delete mode 100644 src/static/js/settings.js delete mode 100644 src/static/js/tv.js diff --git a/package.json b/package.json index cf1de4a..65ac5f5 100644 --- a/package.json +++ b/package.json @@ -1,47 +1,47 @@ { - "name": "chocolatereact", - "version": "0.1.0", - "private": true, - "dependencies": { - "@react-icons/all-files": "^4.1.0", - "@testing-library/jest-dom": "^5.16.5", - "@testing-library/react": "^13.4.0", - "@testing-library/user-event": "^13.5.0", - "axios": "^1.3.3", - "buffer": "^6.0.3", - "framer-motion": "^9.0.4", - "http": "^0.0.1-security", - "react": "^18.2.0", - "react-awesome-player": "^1.1.0", - "react-dom": "^18.2.0", - "react-icons": "^4.7.1", - "react-router-dom": "^6.8.1", - "react-scripts": "5.0.1", - "videojs-max-quality-selector": "^0.9.1", - "web-vitals": "^2.1.4" - }, - "scripts": { - "start": "react-scripts start", - "build": "react-scripts build", - "test": "react-scripts test", - "eject": "react-scripts eject" - }, - "eslintConfig": { - "extends": [ - "react-app", - "react-app/jest" - ] - }, - "browserslist": { - "production": [ - ">0.2%", - "not dead", - "not op_mini all" - ], - "development": [ - "last 1 chrome version", - "last 1 firefox version", - "last 1 safari version" - ] - } -} + "name": "chocolatereact", + "version": "0.1.0", + "private": true, + "dependencies": { + "@react-icons/all-files": "^4.1.0", + "@testing-library/jest-dom": "^5.16.5", + "@testing-library/react": "^13.4.0", + "@testing-library/user-event": "^13.5.0", + "axios": "^1.3.3", + "buffer": "^6.0.3", + "framer-motion": "^9.0.4", + "http": "^0.0.1-security", + "react": "^18.2.0", + "react-awesome-player": "^1.1.0", + "react-dom": "^18.2.0", + "react-icons": "^4.7.1", + "react-router-dom": "^6.8.1", + "react-scripts": "5.0.1", + "videojs-max-quality-selector": "^0.9.1", + "web-vitals": "^2.1.4" + }, + "scripts": { + "start": "react-scripts start", + "build": "GENERATE_SOURCEMAP=false react-scripts build", + "test": "react-scripts test", + "eject": "react-scripts eject" + }, + "eslintConfig": { + "extends": [ + "react-app", + "react-app/jest" + ] + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} \ No newline at end of file diff --git a/src/AddMedia.js b/src/AddMedia.js new file mode 100644 index 0000000..96182b0 --- /dev/null +++ b/src/AddMedia.js @@ -0,0 +1,351 @@ +import "./App.css"; +import Header from "./Header"; +import Popup from "./Popup"; +import { useEffect } from "react"; + +function Actor() { + + function getCookie(name) { + let cookieValue = null; + if (document.cookie && document.cookie !== "") { + const cookies = document.cookie.split(";"); + for (let i = 0; i < cookies.length; i++) { + const cookie = cookies[i].trim(); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) === (name + "=")) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; + } + const language = JSON.parse(localStorage.getItem("languageFile")); + + function addQualities() { + let chocolateServerAdress = getCookie("serverAdress"); + let mediaType = document.querySelector(`#mediaType option[value="${document.getElementById("mediaTypeInput").value}"]`).getAttribute("data-value") + console.log(mediaType) + fetch(`${chocolateServerAdress}listQualities/${mediaType}`).then(response => response.json()).then(data => { + let select = document.getElementById("allQualities"); + select.innerHTML = ""; + for (let i = 0; i < data.length; i++) { + let option = document.createElement("option"); + option.value = data[i]["name"]; + option.setAttribute("data-value", data[i]["id"]); + document.getElementById("allQualities").appendChild(option); + } + }) + .catch(error => console.error(error)); + if (mediaType === "serie") { + fetch(`${chocolateServerAdress}listLanguageProfiles/${mediaType}`, { + method: 'GET' + }) + .then(response => response.json()) + .then(data => { + let select = document.getElementById("allLanguages"); + let languagePart = document.getElementsByClassName("languagePart")[0]; + languagePart.style.display = "block"; + select.innerHTML = ""; + for (let i = 0; i < data.length; i++) { + let option = document.createElement("option"); + option.value = data[i]["name"]; + option.setAttribute("data-value", data[i]["id"]); + document.getElementById("allLanguages").appendChild(option); + } + }) + } +} + + function showErrorMessage(message, type) { + //if there's already an alert, return + if (document.getElementsByClassName("alert").length > 0) { + return; + } + let alert = document.createElement("div"); + alert.className = "alert"; + alert.setAttribute("role", "alert"); + alert.innerHTML = message; + document.body.appendChild(alert); + setTimeout(function() { + alert.className = "alert alert-fade-in alert-" + type; + }, 100); + + setTimeout(function() { + alert.classList.add("alert-fade-out"); + setTimeout(function() { + alert.remove(); + }, 500); + }, 4000); + } + + + function searchForMedia() { + let mediaType = document.querySelector(`#mediaType option[value="${document.getElementById("mediaTypeInput").value}"]`) + if (mediaType === null) { + showErrorMessage("Please select a media type", "alert") + return; + } else { + mediaType = mediaType.getAttribute("data-value") + } + let title = document.getElementById("title").value + let chocolateServerAdress = getCookie("serverAdress"); + let results = document.getElementById("results"); + if (results.childElementCount > 0) { + results.innerHTML = ""; + } + fetch(chocolateServerAdress+'lookup', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + mediaType: mediaType, + query: title + }) + }) + .then(response => response.json()) + .then(data => { + console.log(data); + let results = document.getElementById("results"); + results.innerHTML = ""; + if (data.length === 0) { + showErrorMessage("No results found", "alert") + return; + } + for (let i = 0; i < data.length; i++) { + let file = data[i]; + let type = undefined + let poster = file["remotePoster"]; + let title = file["title"]; + const uniqueID = i; + + if (mediaType === "book") { + poster = file["remoteCover"]; + } else if (mediaType === "music") { + console.log(file); + //ID = file["foreignId"]; + if (file["artist"] !== undefined) { + file = file["artist"]; + poster = file["remotePoster"]; + title = file["artistName"]; + //ID = title + type = "artist"; + } else if (file["album"] !== undefined) { + file = file["album"]; + poster = file["remoteCover"]; + title = file["title"]; + //ID = title + type = "album"; + } + } + if (poster === undefined) { + continue; + } + if (poster.includes("thetvdb.com")) { + let chocolateServerAdress = getCookie("serverAdress"); + fetch(chocolateServerAdress+'getIMDBPoster', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + imdbId: file["imdbId"] + }) + }) + .then(response => response.json()) + .then(data => { + poster = data["url"]; + if (poster !== "/static/img/broken.webp" && poster !== " ") { + setCard(poster, i, title, type, uniqueID); + } + }) + } else { + setCard(poster, i, title, type, uniqueID); + } + } + }) + } + + function setCard(url, ID, title=undefined, type=undefined, uniqueID) { + //check if the card already exists + let card = document.querySelector(`.coverAddMedia[data-id="${ID}"]`); + if (card !== null) { + return; + } + card = document.createElement("div"); + card.classList.add("coverAddMedia"); + card.setAttribute("data-id", ID); + card.setAttribute("data-type", type); + card.setAttribute("data-uniqueID", uniqueID); + + // Create the image + let image = document.createElement("img"); + image.classList.add("cover-image"); + image.setAttribute("src", url); + + card.appendChild(image); + + // Create the title if it exists + if (title !== undefined) { + let titleBlock = document.createElement("p"); + titleBlock.classList.add("cover-title"); + titleBlock.innerHTML = title; + card.appendChild(titleBlock); + } + + + card.addEventListener("click", function() { + setMovie(uniqueID); + }); + + let results = document.getElementById("results"); + results.appendChild(card); + } + + + function addMedia(qualityID) { + let mediaType = document.querySelector(`#mediaType option[value="${document.getElementById("mediaTypeInput").value}"]`).getAttribute("data-value") + let type = ""; + try { + type = document.querySelector(".coverAddMedia").getAttribute("data-type"); + } catch { + showErrorMessage("Please select a media", "alert"); + return; + } + let ID = document.querySelector(".coverAddMedia").getAttribute("data-id"); + let chocolateServerAdress = getCookie("serverAdress"); + let body = {} + try { + body ={ + mediaType: mediaType, + ID: ID, + qualityID: qualityID, + type: type, + term: document.getElementById("title").value, + languageId: document.querySelector(`#allLanguages option[value="${document.getElementById("languagesInput").value}"]`).getAttribute("data-value") + } + } catch { + body ={ + mediaType: mediaType, + ID: ID, + qualityID: qualityID, + type: type, + term: document.getElementById("title").value, + } } + + fetch(chocolateServerAdress+'/addMedia', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(body) + }) + .then(response => response.json()) + .then(data => { + console.log(data); + if (data["status"] === "ok") { + showErrorMessage("Media added successfully", "success"); + setTimeout(function() { + window.location.reload(); + }, 9000); + } else { + showErrorMessage("Error adding media", "alert"); + } + }) + } + + + function showButton(qualityID) { + if (document.getElementsByClassName("addMovieButton").length > 0) { + return; + } + let addButton = document.createElement("button"); + addButton.classList.add("addMovieButton"); + + addButton.innerHTML = "Add"; + addButton.addEventListener("click", function() { + addMedia(qualityID); + }); + let fakeForm = document.getElementById("fakeForm"); + fakeForm.appendChild(addButton); + } + + function setMovie(ID) { + // remove all the other cards + let cards = document.getElementsByClassName("coverAddMedia"); + while (cards.length > 1) { + for (let i = 0; i < cards.length; i++) { + if (cards[i].getAttribute("data-uniqueID").toString() !== ID.toString()) { + cards[i].remove(); + } + } + } + } + + useEffect(() => { + let mediaTypeInput = document.getElementById("mediaTypeInput"); + mediaTypeInput.removeEventListener('change', console.log("removed"), true); + mediaTypeInput.addEventListener('change', function() { + addQualities(); + }); + + document.getElementById("qualityInput").removeEventListener('change', console.log("removed"), true); + document.getElementById("qualityInput").addEventListener("change", function() { + var selectedOption = this.value; + let qualityID = document.querySelector('#allQualities option[value="' + selectedOption + '"]').getAttribute("data-value"); + showButton(qualityID) + }); + + let timeoutId = null; + + const input = document.querySelector('#title'); + input.removeEventListener('input', console.log("removed"), true); + input.addEventListener('input', function() { + clearTimeout(timeoutId); + timeoutId = setTimeout(function() { + console.log('No change for 2 seconds'); + searchForMedia() + }, 2000); + }); + }, []); + + return ( +
+
+
+
+

Set the media type (ex: Films, TV Show, Books)

+ + + +
+
+
+

Set the title

+
+
+
+
+

Set the quality

+ + + +
+

Set the language

+ + + +
+
+
+
+ ); + +} + +export default Actor; \ No newline at end of file diff --git a/src/App.css b/src/App.css index e238b02..ab80aa7 100644 --- a/src/App.css +++ b/src/App.css @@ -350,12 +350,12 @@ header { justify-items: center; display: flex; flex-wrap: wrap; - justify-content: space-between; row-gap: 5vh; position: absolute; width: 95vw; margin-top: 22vh; margin-left: 4vw; + column-gap: 0.66666666666vw; } .logo_svg { @@ -579,6 +579,17 @@ label[for="addLibraryButton"] { display: inline-block !important; } +#ambientModeBackground { + top: 0vh; + left: 3vw; + height: 100vh !important; + width: 97vw; + position: absolute; + background-repeat: no-repeat; + background-size: cover; + filter: blur(85px); +} + @keyframes showPencil { 0% { transform: scale(0); @@ -612,7 +623,7 @@ label[for="addLibraryButton"] { position: absolute; top: 2vh; right: 2vw; - width: 7vw; + padding: 0 1vw; height: 6vh; background: none; cursor: pointer; @@ -830,6 +841,7 @@ label[for="books"] { padding: 2vh; background: #2b2b2b; border-radius: 1vw; + position: relative; } .librarySetting>h1 { @@ -838,8 +850,8 @@ label[for="books"] { .moveLibrary { position: absolute; - margin-top: -41vh; - margin-left: 19vw; + top: 3vh; + right: 2vw; cursor: grab; font-size: 2vh; } @@ -1023,13 +1035,13 @@ svg[name="play"] { } .video-js[tabindex="-1"] { - top: 1vh; - left: 11.5vw; - height: 45vw !important; + top: 6vh; + left: 16vw; + height: 40vw !important; aspect-ratio: calc(16 / 9); padding: 0 !important; margin: 0 !important; - width: auto !important; + width: calc(40vw / 9 * 16); } .notSorted { @@ -1546,7 +1558,7 @@ input[type="search"]::-webkit-search-results-decoration { } .buttonsShow { - margin-top: 1vh; + margin-top: 7vh; height: 10vh; display: flex; align-items: center; @@ -1742,14 +1754,12 @@ input[type="search"]::-webkit-search-results-decoration { } .consoleList { - display: grid; - grid-template-rows: 50vh; - grid-template-columns: repeat(3, 30vw); - grid-row-gap: 4vh; - grid-column-gap: 0px; - width: 89.5vw; + display: flex; + width: 91vw; margin-top: 20vh; - margin-left: 9.5vw; + margin-left: 6vw; + flex-wrap: wrap; + justify-content: space-around; } .systemDiv { @@ -2609,7 +2619,9 @@ svg[name="download-outline"] { } .buttonFullScreenClicked { - margin-right: -94vw; + right: 0; + bottom: 4vh; + margin: 0; } .bookImage { @@ -2694,6 +2706,13 @@ svg[name="download-outline"] { width: 94vw; } +.leftPart, +.rightPart, +.centerPartText { + flex-direction: column; + align-items: flex-start; +} + .leftPart h3, .centerPart h3, .rightPart h3 { @@ -2708,12 +2727,16 @@ svg[name="download-outline"] { display: flex; flex-direction: row; flex-wrap: wrap; - justify-content: flex-start; + justify-content: space-around; row-gap: 1vh; column-gap: 1vw; overflow: scroll; width: 65vw; max-height: 45vh; + min-height: 45vh; + border: 5px solid #0b0b0b; + border-radius: 3vh; + padding: 10px 10px; } .coverAddMedia { @@ -2733,31 +2756,54 @@ svg[name="download-outline"] { } .alert { - display: flex; - justify-content: center; - opacity: 0; - width: 97vw; + padding: 2vh 2vw; margin-left: 3vw; transition: all 0.5s ease-in-out; + position: fixed; + top: 15vh; + background: #0b0b0b; + border-radius: 1vh; + z-index: 9999999999999999; + right: -20vw; } -.alert-message { - display: flex; - justify-content: center; - position: fixed; - bottom: 1vh; - padding: 20px; - background: rgb(25 25 25); - border-radius: 1vw; +.alert-fade-in { + right: 1vw !important; +} + +.alert-fade-out { + right: -20vw !important; +} + +.alert-alert { + border-left: 10px solid #ff0000; +} + +.alert-success { + border-left: 10px solid #00ff00; } .addMovieButton { position: absolute; - bottom: 4vh; + bottom: -8vh; right: 3vw; - padding: 5vh 6vw; - border-radius: 6vh; - font-size: 4vh; + background: transparent; + box-shadow: 0.1vh 0.1vh 0.5vh #000; + padding: 4vh 5vw; + transition: 300ms background, color; + cursor: pointer; + border: 0.2vw solid #ffffff; + border-radius: 1.5vw; + font-size: 2.4vh; + font-weight: 700; + color: #ffffff; + text-decoration: none; + text-shadow: 0.1vh 0.1vh 0.5vh #000; +} + +.addMovieButton:hover { + background: #ffffff; + color: #000000; } .hidden { @@ -3139,6 +3185,7 @@ svg[name="download-outline"] { width: 94vw; margin-top: 8vh; margin-left: 6vw; + justify-content: space-around; } .card { width: 42vw; @@ -3268,9 +3315,6 @@ svg[name="download-outline"] { .settingsCheckbox { transform: scale(1); } - .submitNewLib { - width: 34vw; - } .profileDiv { width: 50vw; margin-top: 12vh; @@ -3406,8 +3450,8 @@ svg[name="download-outline"] { align-items: center; z-index: 5; top: 37vh; - left: 60vw; - padding: 1.7vh 4vw; + left: 52vw; + padding: 2vh 4vw; transition: 300ms background, color; cursor: pointer; border: 0.2vw solid #ffffff; @@ -3423,8 +3467,9 @@ svg[name="download-outline"] { } .rescanButton { margin-top: 37vh; - padding: 0vh 1vw; + padding: 1.4vh 2vw; font-size: 1vh; + border-radius: 3vw; } .rescanButton svg { padding: 0.5vh 1vw; @@ -3532,7 +3577,7 @@ svg[name="download-outline"] { } .expandBook { margin-top: 50vh; - margin-right: -71vw; + margin-right: -25vw; } .arrowButtonBook { font-size: 8vw; @@ -3556,4 +3601,15 @@ svg[name="download-outline"] { .pie:after { transform: rotate(calc(var(--p)*3.6deg)) translateY(calc(50% - 9vw/2)); } + .gameName { + display: table-cell; + width: 46vw; + height: 8vh; + text-align: center; + vertical-align: middle; + } + .gameDiv { + width: auto; + margin: 0 1vw; + } } \ No newline at end of file diff --git a/src/Book.js b/src/Book.js index 5a89962..5952d98 100644 --- a/src/Book.js +++ b/src/Book.js @@ -85,6 +85,7 @@ function Book() { // Function to zoom the book function zoomBook() { + let bookDiv = document.getElementById("bookDiv"); bookDiv.classList.toggle("bigBookDiv"); document.getElementById("expandBook").classList.toggle("buttonFullScreenClicked"); document.getElementById("previous-page").classList.toggle("bigArrowPrev"); diff --git a/src/Books.js b/src/Books.js index 291720e..a10a7f7 100644 --- a/src/Books.js +++ b/src/Books.js @@ -57,6 +57,7 @@ function Books() { let bookDiv = document.createElement("div"); bookDiv.className = "bookDiv"; bookDiv.setAttribute("data-name", book.title); + bookDiv.setAttribute("data-type", book.bookType); let bookNameDiv = document.createElement("div"); bookNameDiv.className = "bookNameDiv"; let bookImageDiv = document.createElement("div"); @@ -72,12 +73,22 @@ function Books() { bookNameDiv.appendChild(bookName); bookDiv.appendChild(bookImageDiv); bookDiv.appendChild(bookNameDiv); - bookImageDiv.addEventListener("click", function() { - window.location.href = `/book/${bookID}`; - }); - bookNameDiv.addEventListener("click", function() { - window.location.href = `/book/${bookID}`; - }); + console.log(book) + if (book.bookType !== "folder") { + bookImageDiv.addEventListener("click", function() { + window.location.href = `/book/${bookID}`; + }); + bookNameDiv.addEventListener("click", function() { + window.location.href = `/book/${bookID}`; + }); + } else { + bookImageDiv.addEventListener("click", function() { + window.location.href = `/books/${book.libraryName}-${book.title}`; + }); + bookNameDiv.addEventListener("click", function() { + window.location.href = `/books/${book.libraryName}-${book.title}`; + }); + } bookList.appendChild(bookDiv); } }) diff --git a/src/CreateAccount.js b/src/CreateAccount.js new file mode 100644 index 0000000..94b59ce --- /dev/null +++ b/src/CreateAccount.js @@ -0,0 +1,84 @@ +import "./App.css"; +import { useEffect } from "react"; + +function CreateAccount() { + + function getCookie(name) { + let cookieValue = null; + if (document.cookie && document.cookie !== "") { + const cookies = document.cookie.split(";"); + for (let i = 0; i < cookies.length; i++) { + const cookie = cookies[i].trim(); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) === (name + "=")) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; + } + const language = JSON.parse(localStorage.getItem("languageFile")); + + function createAccount() { + let name = document.getElementsByClassName("name")[0].value + let password = document.getElementsByClassName("password")[0].value + let profilePicture = document.getElementById("profilePicture").files[0] + let type = "Admin" + let formData = new FormData() + formData.append("name", name) + formData.append("password", password) + formData.append("profilePicture", profilePicture) + formData.append("type", type) + + let chocolateServerAdress = getCookie("serverAdress"); + + fetch(`${chocolateServerAdress}createAccount`, { + method: "POST", + body: formData, + }).then(function(response) { + return response.json(); + }).then(function(data) { + //go to / + console.log(data) + window.location.href = "/" + }); + } + + let chocolateServerAdress = getCookie("serverAdress"); + + fetch(chocolateServerAdress+"getAllUsers", { + credentials: "same-origin" + }) +.then(response => response.json()) +.then(data => { + if (data.users.length > 0 && data.status === "ok") { + window.location.href = "/" + } +}) + + return ( +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ ); + +} + +export default CreateAccount; \ No newline at end of file diff --git a/src/EditMovie.js b/src/EditMovie.js index dae5036..1c14505 100644 --- a/src/EditMovie.js +++ b/src/EditMovie.js @@ -21,22 +21,6 @@ function EditMovie() { return cookieValue; } - function repairJSON(json) { - - json = json.replace(/", "/g, "", ""); - json = json.replace(/\\\\/g, "\\"); - json = json.replace(/, "/g, ', "'); - json = json.replace(/: "/g, ': "'); - json = json.replace(/": /g, '": '); - json = json.replace(/"}]/g, '"}]'); - json = json.replace(/{"/g, '{"'); - json = json.replace(/False/g, "false"); - json = json.replace(/True/g, "true"); - json = json.replace(/None/g, "null"); - json = json.replace(/\\/g, "") - - return json - } function getMovies() { @@ -64,9 +48,6 @@ function EditMovie() { data = data.movies for (let i = 0; i < data.length; i++) { let film = data[i]; - film = repairJSON(film) - console.log(JSON.stringify(film)) - film = JSON.parse(film) console.log(film) console.log(typeof film) @@ -193,9 +174,9 @@ function EditMovie() { getMovies(); }, []); - const currentHref = window.location.href; - const movieName = currentHref.split("/")[4]; - const libraryName = currentHref.split("/")[5]; + const currentHref = unescape(window.location.href) + const movieName = decodeURIComponent(escape(currentHref.split("/")[4])) + const libraryName = decodeURIComponent(escape(currentHref.split("/")[5])) return (
diff --git a/src/EditSerie.js b/src/EditSerie.js index c115da6..0483a4b 100644 --- a/src/EditSerie.js +++ b/src/EditSerie.js @@ -21,40 +21,14 @@ function EditSerie() { return cookieValue; } - function repairJSON(json) { - let replaceObj = { - "{'": '{"', - "'}": '"}', - "': ": '": ', - ", '": ', "', - "\": '": '": "', - "', \"": '", "', - "\\'": "'", - "False": "false", - "True": "true", - "None": "null", - "['": '["', - "'],": '"],', - } - - for (let key in replaceObj) { - while (json.includes(key)) { - json = json.replace(key, replaceObj[key]) - } - } - - return json - } - - function getSeries() { let chocolateServerAdress = getCookie("serverAdress"); - const currentHref = window.location.href; - const serieName = currentHref.split("/")[4]; - const library = currentHref.split("/")[5]; + const currentHref = unescape(window.location.href) + const serieName = decodeURIComponent(escape(currentHref.split("/")[4])) + const libraryName = decodeURIComponent(escape(currentHref.split("/")[5])) - let url = `${chocolateServerAdress}/editSerie/${serieName}/${library}`; + let url = `${chocolateServerAdress}editSerie/${serieName}/${libraryName}`; //for all serie finded let destinationDIV = document.getElementsByClassName("editSerieDiv")[0]; @@ -71,10 +45,8 @@ function EditSerie() { .then(data => { for (let i = 0; i < data.length; i++) { let serie = data[i]; - serie = repairJSON(serie) - console.log(serie) - serie = JSON.parse(serie) console.log(serie) + console.log(typeof serie) let serieFindedDiv = document.createElement("div"); serieFindedDiv.className = "serieFinded"; @@ -100,14 +72,16 @@ function EditSerie() { serieFindedDiv.addEventListener("click", function() { let serieID = serieFindedDiv.id let chocolateServerAdress = getCookie("serverAdress"); - let method = "POST"; - let url = `${chocolateServerAdress}/editSerie/${serieName}/${libraryName}`; + + let url = `${chocolateServerAdress}editSerie/${serieName}/${libraryName}`; + let body = { "newSerieID": serieID } + fetch(url, { credentials: "same-origin", - method: method, + method: "POST", headers: { "Content-Type": "application/json", }, @@ -201,12 +175,9 @@ function EditSerie() { getSeries(); }, []); - const currentHref = window.location.href; - let serieName = currentHref.split("/")[4] - while (serieName.includes("%20")) { - serieName = serieName.replace("%20", " ") - } - const libraryName = currentHref.split("/")[5]; + const currentHref = unescape(window.location.href) + const serieName = decodeURIComponent(escape(currentHref.split("/")[4])) + const libraryName = decodeURIComponent(escape(currentHref.split("/")[5])) return (
diff --git a/src/Header.js b/src/Header.js index 71ce7ba..39c96b3 100644 --- a/src/Header.js +++ b/src/Header.js @@ -23,6 +23,26 @@ function Header() { return cookieValue; } + function checkAccType() { + const cookie = getCookie("token"); + let chocolateServerAdress = getCookie("serverAdress"); + fetch(`${chocolateServerAdress}checkAccType`, { + credentials: "same-origin", + method: "POST", + body: JSON.stringify({token: cookie}), + headers: { + "Content-Type": "application/json" + } + }) + .then(response => response.json()) + .then(data => { + if (data !== "Admin") { + let settings = document.getElementById("settings"); + settings.remove(); + } + }) + } + useEffect(() => { let username = getCookie("username"); @@ -40,6 +60,7 @@ function Header() { console.error("Error:", error); }); } + checkAccType(); }, []); const language = JSON.parse(localStorage.getItem("languageFile")) @@ -68,7 +89,7 @@ function Header() {
- +
diff --git a/src/Login.js b/src/Login.js index 486bdae..6083ae5 100644 --- a/src/Login.js +++ b/src/Login.js @@ -106,7 +106,15 @@ function Login() { }) .then(response => response.json()) .then(data => { - setAllUsers(data) + console.log(data) + setAllUsers(data.users) + console.log(data.users) + if (data.users.length === 0 && data.status === "ok") { + console.log("redirecting") + if (window.location.pathname === "/login" || window.location.pathname === "/") { + window.location.href = "/createAccount" + } + } }) }, []) diff --git a/src/Movie.js b/src/Movie.js index b307725..b33c501 100644 --- a/src/Movie.js +++ b/src/Movie.js @@ -33,7 +33,7 @@ function Movie() { console.log("setUrl",setUrl) let currentTime = playerRef.current.currentTime() currentTime = parseInt(currentTime) - if (currentTime === lastPush+1) { + if (currentTime >= lastPush+1) { console.log("pushing new timecode",currentTime+" for movie "+movieID+" to server "+setUrl) fetch(setUrl, { method: "POST", @@ -52,6 +52,23 @@ function Movie() { } }; + const ambientMode = (player) => { + const canvas = document.createElement("canvas"); + const ctx = canvas.getContext("2d"); + const video = player.el().getElementsByTagName("video")[0]; + + canvas.width = video.videoWidth; + canvas.height = video.videoHeight; + + ctx.drawImage(video, 0, 0, canvas.width, canvas.height); + + const base64 = canvas.toDataURL("image/jpeg", 0.5); + + const ambientModeBackground = document.getElementById("ambientModeBackground"); + ambientModeBackground.style.backgroundImage = `url(${base64})`; + + } + const movieID = window.location.href.split("/")[4]; const chocolateServerAdress = getCookie("serverAdress"); const sourceURL = `${chocolateServerAdress}mainMovie/${movieID}`; @@ -79,6 +96,7 @@ function Movie() { }); player.on("timeupdate", () => { handleTimeUpdate() + //ambientMode(player) }); /* player.maxQualitySelector({ @@ -99,6 +117,7 @@ function Movie() { return (
+
); diff --git a/src/Movies.js b/src/Movies.js index bec824c..197b3aa 100644 --- a/src/Movies.js +++ b/src/Movies.js @@ -2,10 +2,22 @@ import "./App.css"; import Header from "./Header"; import Popup from "./Popup"; import { IoRefreshOutline, IoFunnelOutline, IoPlayOutline, IoDownloadOutline, IoPencilOutline } from "react-icons/io5"; -import { useEffect } from "react"; +import { useEffect, useState } from "react"; import Loading from "./Loading"; function Movies() { + + function checkCanDownload() { + let chocolateServerAdress = getCookie("serverAdress"); + fetch(`${chocolateServerAdress}checkDownload`, { + credentials: "same-origin" + }) + .then(response => response.json()) + .then(data => { + console.log(data) + return data + }) + } function getCookie(name) { let cookieValue = null; @@ -54,7 +66,7 @@ function Movies() { let movieUrl = data.slug let movieID = data.id movieUrl = "/movie/" + movieID - let movieDownloadURL = chocolateServerAdress+"download/" + movieID + let movieDownloadURL = chocolateServerAdress+"downloadMovie/" + movieID let movieYear = data.date let movieTrailer = data.bandeAnnonceUrl let movieSimilar = data.similarMovies @@ -181,7 +193,13 @@ function Movies() { playButton.setAttribute("href", movieUrl); let downloadButton = document.getElementsByClassName("downloadPopup")[0] - downloadButton.setAttribute("href", movieDownloadURL); + let canDownload = checkCanDownload() + console.log(canDownload) + if (canDownload === false) { + downloadButton.remove() + } else { + downloadButton.setAttribute("href", movieDownloadURL); + } }) }) @@ -412,9 +430,11 @@ function Movies() { let titleBanner = document.getElementsByClassName("bannerTitle")[0] let descriptionBanner = document.getElementsByClassName("bannerDescription")[0] let watchNow = document.getElementsByClassName("watchNowA")[0] + let downloadNowA = document.getElementsByClassName("downloadNowA")[0] let movie = data[i] let id = movie.id - let slug = "/movie/" + id + let movieUrl = "/movie/" + id + let downloadMovie = chocolateServerAdress + "downloadMovie/" + id let bannerImage = movie.banner let cssBigBanner = `background-image: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(24, 24, 24, 0.85) 77.08%, #1D1D1D 100%), linear-gradient(95.97deg, #000000 0%, rgba(0, 0, 0, 0.25) 100%, #000000 100%), url("${chocolateServerAdress}${bannerImage}")` imageBanner.setAttribute("style", cssBigBanner) @@ -431,8 +451,14 @@ function Movies() { }) genreBanner.innerHTML = JSON.parse(movie.genre).join(", ") - let movieUrl = slug watchNow.setAttribute("href", movieUrl) + let canDownload = checkCanDownload() + console.log(canDownload) + if (canDownload === false) { + downloadNowA.remove() + } else { + downloadNowA.setAttribute("href", downloadMovie) + } } } @@ -444,21 +470,48 @@ function Movies() { let bannerTitle = document.getElementsByClassName("bannerTitle")[0] let bannerDescription = document.getElementsByClassName("bannerDescription")[0] let watchNow = document.getElementsByClassName("watchNowA")[0] - let downloadA = document.getElementById("downloadNowA") + let downloadNowA = document.getElementsByClassName("downloadNowA")[0] let rescanButton = document.getElementById("rescanButton") let selectA = document.getElementsByClassName("selectA")[0] let sortA = document.getElementsByClassName("sortA")[0] + + bannerGenre.setAttribute("style", "top: 46vh;") + bannerTitle.setAttribute("style", "top: 47.5vh;") + bannerDescription.setAttribute("style", "top: 55vh;") + watchNow.setAttribute("style", "top: 65vh;") + downloadNowA.setAttribute("style", "top: 65vh;") + rescanButton.setAttribute("style", "margin-top: 65vh;") + + selectA.setAttribute("style", "display: none;") + sortA.setAttribute("style", "display: none;") + } else { + let bigBackground = document.getElementsByClassName("bannerCover")[0] + bigBackground.style.height = "50vh" - bannerGenre.style.top = "46vh" - bannerTitle.style.top = "47.5vh" - bannerDescription.style.top = "55vh" - watchNow.style.top = "65vh" - downloadA.style.top = "65vh" - rescanButton.style.marginTop = "65vh" + let bannerGenre = document.getElementsByClassName("bannerGenre")[0] + let bannerTitle = document.getElementsByClassName("bannerTitle")[0] + let bannerDescription = document.getElementsByClassName("bannerDescription")[0] + let watchNow = document.getElementsByClassName("watchNowA")[0] + let downloadNowA = document.getElementsByClassName("downloadNowA")[0] + let rescanButton = document.getElementById("rescanButton") + + let selectA = document.getElementsByClassName("selectA")[0] + let sortA = document.getElementsByClassName("sortA")[0] + + bannerGenre.removeAttribute("style") + bannerTitle.removeAttribute("style") + bannerDescription.removeAttribute("style") + watchNow.removeAttribute("style") + try { + downloadNowA.removeAttribute("style") + } catch (error) { + console.log(error) + } + rescanButton.removeAttribute("style") - selectA.style.display = "none" - sortA.style.display = "none" + selectA.removeAttribute("style") + sortA.removeAttribute("style") } //order allGenres by alphabetical order diff --git a/src/Season.js b/src/Season.js index 3277ee3..0661b33 100644 --- a/src/Season.js +++ b/src/Season.js @@ -6,6 +6,20 @@ import Header from "./Header"; function App() { const language = JSON.parse(localStorage.getItem("languageFile")); + function checkCanDownload() { + let theResponse = "ratio"; + let chocolateServerAdress = getCookie("serverAdress"); + fetch(`${chocolateServerAdress}checkDownload`, { + credentials: "same-origin" + }) + .then(response => response.json()) + .then(data => { + console.log(data) + theResponse = data + return theResponse + }) +} + function getCookie(name) { let cookieValue = null; if (document.cookie && document.cookie !== "") { @@ -38,12 +52,8 @@ function App() { }).then(function(data) { let episodes = data["episodes"] episodes = Object.entries(episodes) - let canDownloadDiv = document.getElementById("canDownloadDiv") - let canDownload = canDownloadDiv.getAttribute("data-candownload") === "True" - canDownload = true let watchNowLanguage = document.getElementsByClassName("watchNowA")[0].innerHTML while (watchNowLanguage === "") { - //sleep 0.1 seconds setTimeout(function(){}, 100); } for (let i = 0; i < episodes.length; i++) { @@ -112,6 +122,7 @@ function App() { let episodeButtons = document.createElement("div") episodeButtons.className = "episodeButtons" episodeButtons.appendChild(watchNowButton) + let canDownload = checkCanDownload() if (canDownload) { let downloadNowButton = document.createElement("a") downloadNowButton.className = "downloadNowSeason" @@ -133,14 +144,17 @@ function App() { let watchNow = document.getElementsByClassName("watchNowA")[0] let downloadNowA = document.getElementById("downloadNowA") - canDownloadDiv = document.getElementById("canDownloadDiv") - canDownload = canDownloadDiv.getAttribute("data-candownload") === "True" - canDownload = true + let canDownload = checkCanDownload() + console.log(canDownload) if (canDownload) { let chocolateServerAdress2 = getCookie("serverAdress") downloadNowA.setAttribute("href", chocolateServerAdress2+"downloadEpisode/" + episodeId) + downloadNowA.style.display = "block" } else { - downloadNowA.remove() + try { + downloadNowA.remove() + } catch (error) { + } } @@ -156,7 +170,7 @@ function App() { let cssBigBanner = `background-image: linear-gradient(to bottom, rgb(255 255 255 / 0%), rgb(29 29 29)), url("${imageSrc}")` imageBanner.setAttribute("style", cssBigBanner) - titleBanner.innerHTML = "EP 1 - " + episode.episodeName + titleBanner.innerHTML = `EP${episode["episodeNumber"]} - ${episode["episodeName"]}` let description = episode.episodeDescription descriptionBanner.innerHTML = description descriptionBanner.innerHTML = descriptionBanner.innerHTML.substring(0, 200) + "..." @@ -191,13 +205,12 @@ function App() { {language["watchNow"] } - + {language["downloadButton"]}
-
); } diff --git a/src/SetServerAdress.js b/src/SetServerAdress.js index 650181d..3af65c2 100644 --- a/src/SetServerAdress.js +++ b/src/SetServerAdress.js @@ -17,14 +17,32 @@ function SetServerAdress() { } } - function setServerAdress() { + function getCookie(name) { + let cookieValue = null; + if (document.cookie && document.cookie !== "") { + const cookies = document.cookie.split(";"); + for (let i = 0; i < cookies.length; i++) { + const cookie = cookies[i].trim(); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) === (name + "=")) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; + } + function setServerAdress() { let serverAdress = document.getElementById("serverAdress").value; - serverAdress.replace("https://", ""); - serverAdress.replace("http://", ""); - + while ("https://" === serverAdress.substring(0, 8)) { + serverAdress = serverAdress.substring(8); + } + while ("http://" === serverAdress.substring(0, 7)) { + serverAdress = serverAdress.substring(7); + } serverAdress = getStart(serverAdress) if (serverAdress.endsWith("/") === false) { serverAdress = serverAdress + "/"; @@ -44,12 +62,11 @@ function SetServerAdress() { setServerAdress(); } } - return (

Set server adress

- +
diff --git a/src/Settings.js b/src/Settings.js index 70a5ce4..ea0b438 100644 --- a/src/Settings.js +++ b/src/Settings.js @@ -4,13 +4,96 @@ import Header from "./Header"; import { IoTrashOutline, IoPersonOutline, IoMoveOutline, IoAddCircleOutline, IoCloseOutline, IoFilmOutline, IoVideocamOutline, IoBookOutline, IoGameControllerOutline, IoTvOutline, IoDesktopOutline, IoRefreshOutline } from "react-icons/io5"; -function EditMovie() { +function Settings() { + + useEffect(() => { + let allLabels = document.querySelectorAll("label"); + for (let i = 0; i < allLabels.length; i++) { + allLabels[i].onclick = function() { + let id = this.getAttribute("for"); + let theIonIcon = this.querySelector('svg'); + theIonIcon.classList.add('selected'); + let otherRadios = document.getElementsByClassName("input-hidden") + for (let j = 0; j < otherRadios.length; j++) { + let otherId = otherRadios[j].id; + console.log(`The otherId is ${otherId} and the id is ${id}`) + if (otherId !== id) { + let otherLabel = document.querySelector('label[for="' + otherId + '"]'); + let otherIonIcon = otherLabel.querySelector('svg'); + otherIonIcon.classList.remove('selected'); + } else { + let otherLabel = document.querySelector('label[for="' + otherId + '"]'); + let otherIonIcon = otherLabel.querySelector('svg'); + otherIonIcon.classList.add('selected'); + } + } + + if (id === "tv") { + let pathLabel = document.querySelector('#popupLibrary > div.settingsLibrary > div.libraryPath > label') + pathLabel.innerHTML = "M3U Path:" + + let libraryPathInput = document.querySelector('#popupLibrary > div.settingsLibrary > div.libraryPath > input') + libraryPathInput.placeholder = "M3U Path" + } else { + let pathLabel = document.querySelector('#popupLibrary > div.settingsLibrary > div.libraryPath > label') + pathLabel.innerHTML = language["path"]+":" + + let libraryPathInput = document.querySelector('#popupLibrary > div.settingsLibrary > div.libraryPath > input') + libraryPathInput.placeholder = language["libraryPath"] + } + } + } + + let chocolateServerAdress = getCookie("serverAdress"); + let personIcon = document.querySelector("#root > div > header > div.headerBottomIcons > a:nth-child(3) > svg").innerHTML; + fetch(`${chocolateServerAdress}getAllUsers`, { + credentials: "same-origin" + }) + .then(response => response.json()) + .then(data => { + let users = data.users; + for (let user of users) { + let exist = document.querySelector(`input[username="${user.name}"]`); + if (exist) { + continue; + } + let userDiv = document.createElement("div"); + userDiv.classList.add("user"); + + let svg = document.createElement("svg"); + svg.classList.add("userIcon"); + svg.innerHTML = personIcon; + + let name = document.createElement("span"); + name.textContent = user.name; + + let checkbox = document.createElement("input"); + checkbox.setAttribute("type", "checkbox"); + checkbox.setAttribute("id", "settingsCheckbox") + checkbox.setAttribute("username", user.name); + checkbox.classList.add("settingsCheckbox"); + + userDiv.appendChild(svg); + userDiv.appendChild(name); + userDiv.appendChild(checkbox); + + let usersDiv = document.querySelector(".libraryUsers"); + usersDiv.appendChild(userDiv); + } + }); + + }, []) function addLibrary() { const popupLibrary = document.getElementById("popupLibrary") popupLibrary.style.display = "block" } + function hidePopup() { + const popupLibrary = document.getElementById("popupLibrary") + popupLibrary.style.display = "none" + } + function createAccount() { let name = document.getElementById("name").value; let password = document.getElementById("password").value; @@ -69,17 +152,15 @@ function EditMovie() { .then(response => response.json()) .then(data => { let users = data.users; - let libraries = data.libraries; - let libraryUsers = document.getElementsByClassName("allLibraries")[0] - - if (libraryUsers.childElementCount > 0) { - return - } - // Récupération de l"élément parent pour toutes les bibliothèques + let libraries = data.libraries; // Récupération de l"élément parent pour toutes les bibliothèques const allLibrariesDiv = document.querySelector(".allLibraries"); // Boucle à travers toutes les bibliothèques libraries.forEach(theLibrary => { + let exist = document.getElementById(theLibrary.libName); + if (exist) { + return; + } // Création de la div pour chaque bibliothèque const libraryDiv = document.createElement("div"); libraryDiv.classList.add("librarySetting"); @@ -190,6 +271,9 @@ function EditMovie() { deleteButton.appendChild(trashIcon); deleteButton.innerHTML += "Delete"; deleteButton.classList.add("deleteLibButton"); + deleteButton.addEventListener("click", () => { + deleteLib(theLibrary.libName); + }); const saveButton = document.createElement("button"); saveButton.textContent = "Save changes" @@ -320,8 +404,79 @@ function EditMovie() { allLibrariesDiv.appendChild(div); }) } - - function newLib() {} + function showErrorMessage(message, type) { + //if there's already an alert, return + if (document.getElementsByClassName("alert").length > 0) { + return; + } + let alert = document.createElement("div"); + alert.className = "alert"; + alert.setAttribute("role", "alert"); + alert.innerHTML = message; + document.body.appendChild(alert); + setTimeout(function() { + alert.className = "alert alert-fade-in alert-" + type; + }, 100); + + setTimeout(function() { + alert.classList.add("alert-fade-out"); + setTimeout(function() { + alert.remove(); + }, 500); + }, 4000); + } + function newLib(){ + let libType = document.getElementsByClassName("selected")[0] + let libTypeParent = libType.parentElement + libType = libTypeParent.getAttribute("for") + const libName = document.getElementById("libraryName").value + const libPath = document.getElementById("libraryPath").value + const libUsers = document.getElementsByClassName("settingsCheckbox") + let defaultUsers = "" + for (let i = 0; i < libUsers.length; i++) { + if (libUsers[i].checked) { + defaultUsers += ","+libUsers[i].getAttribute("username") + } + } + + if (defaultUsers.startsWith(",")) { + defaultUsers = defaultUsers.substring(1) + } + + if (libName === "") { + showErrorMessage("Please enter a library name !", "alert") + } + if (libPath === "") { + showErrorMessage("Please enter a library path !", "alert") + } + + let chocolateServerAdress = getCookie("serverAdress") + + if (libName !== "" && libPath !== "") { + fetch(chocolateServerAdress+"createLib", { + method: "POST", + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify({ + libName: libName, + libPath: libPath, + libType: libType, + libUsers: defaultUsers + }) + }).then(res => { + return res.json() + }).then(data => { + let error = data.error + if (error === "worked") { + showErrorMessage("The library has been created !", "success") + setTimeout(function() { + window.location.reload() + }, 5000); + } else { + showErrorMessage("The library already exists !\nPlease choose another name.", "alert") + } + }) + } + } function saveSettings() { let languageInp = document.getElementById("language").value; @@ -394,12 +549,63 @@ function EditMovie() { } }) } - - function rescanAll() {} + function deleteLib(libName) { + //create a popup to confirm the deletion + const popupLibrary = document.createElement("div") + document.body.appendChild(popupLibrary) + let chocolateServerAdress = getCookie("serverAdress") + fetch(`${chocolateServerAdress}deleteLib/${libName}`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + //set the form + body: JSON.stringify({ + libName: libName + }) + }) +} + +function rescanAll() { + let chocolateServerAdress = getCookie("serverAdress") + let url = `${chocolateServerAdress}rescanAll` + let button = document.getElementById("rescanAllButton") + let texts = ["Scanning", "Scanning.", "Scanning..", "Scanning..."] + let svg = button.innerHTML.split("")[0] + "" + button.disabled = true + + //setInterval + var i = 0 + var interval = setInterval(function() { + i++ + if (i === 4) { + i = 0 + } + button.innerHTML = `${svg}${texts[i]}` + }, 500) + + //fetch with get + fetch(url, { + method: "GET", + headers: { + "Content-Type": "application/json" + }}).then(function(response) { + return response.json() + }).then(function(data) { + console.log(data) + if (data === true) { + clearInterval(interval) + button.innerHTML = 'Done' + } else { + clearInterval(interval) + button.innerHTML = 'Error' + button.classList.add("error") + } + }) +} const language = JSON.parse(localStorage.getItem("languageFile")); - console.log(language) useEffect(() => { getSettings(); @@ -409,7 +615,7 @@ function EditMovie() {
- +
@@ -695,4 +901,4 @@ function EditMovie() { ); } -export default EditMovie; \ No newline at end of file +export default Settings; \ No newline at end of file diff --git a/src/index.js b/src/index.js index 7d8f74f..fe0395d 100644 --- a/src/index.js +++ b/src/index.js @@ -32,6 +32,8 @@ import Actor from "./Actor"; import EditMovie from "./EditMovie"; import EditSerie from "./EditSerie"; +import AddMedia from "./AddMedia"; + import SetServerAdress from "./SetServerAdress"; import reportWebVitals from "./reportWebVitals"; @@ -40,6 +42,8 @@ import { RouterProvider, } from "react-router-dom"; +import CreateAccount from "./CreateAccount"; + const BrowserRouter = createBrowserRouter([ { path: "/", @@ -132,6 +136,14 @@ const BrowserRouter = createBrowserRouter([ { path: "/settings", element: , + }, + { + path: "/createAccount", + element: , + }, + { + path: "/addMedia", + element: , } ]); @@ -242,23 +254,15 @@ if (serverCookie === null) { }) .then(response => response.json()) .then(data => { - console.log(data) - if (data === false) { - const root = ReactDOM.createRoot(document.getElementById("root")); - root.render( - - - - - ); - } else if (cookie === "false" || cookie === null) { - const root = ReactDOM.createRoot(document.getElementById("root")); - root.render( - - - - - ); + //if there's no data, and the path doesn't contain /createAccount, render the login page + if ((data === false || cookie === "false" || cookie === null) && !window.location.href.includes("/createAccount")) { + const root = ReactDOM.createRoot(document.getElementById("root")); + root.render( + + + + + ); } else { const root = ReactDOM.createRoot(document.getElementById("root")); root.render( diff --git a/src/static/js/actor.js b/src/static/js/actor.js deleted file mode 100644 index 417b207..0000000 --- a/src/static/js/actor.js +++ /dev/null @@ -1,474 +0,0 @@ - -function goToSeason(id) { - let href = "/season/" + id - window.location.href = href -} - -function setPopup() { - let contents = document.getElementsByClassName("content") - Array.from(contents).forEach(function(content) { - content.addEventListener("click", function() { - let mediaType = content.getAttribute("mediaType") - let popup = document.getElementById("popup") - popup.style.display = "block" - document.body.style.overflow = "hidden" - let image = content.children[0].children[0] - let movieId = image.getAttribute("data-id") - if (mediaType === "movie") { - fetch("/getMovieData/" + movieId).then(function(response) { - return response.json() - }).then(function(data) { - let movieTitle = data.realTitle - let movieCast = JSON.parse(data.cast) - let movieDescription = data.description - let movieDuration = data.duration - let movieGenre = JSON.parse(data.genre) - let movieNote = data.note - let moviePoster = data.cover - let movieUrl = data.slug - let movieID = data.id - movieUrl = "/movie/" + movieID - let movieYear = data.date - let movieTrailer = data.bandeAnnonce - let movieSimilar = data.similarMovies - let containerSimilar = document.getElementsByClassName("containerSimilar")[0] - - if (movieSimilar.length === 0) { - containerSimilar.style.display = "none" - - } else { - containerSimilar.style.display = "inline-grid" - } - - for (let i = 0; i < movieSimilar.length; i++) { - let movie = movieSimilar[i] - let imageUrl = movie.cover - let movieName = movie.realTitle - movieId = movie.id - let similar = document.getElementsByClassName("containerSimilar")[0] - movie = document.createElement("div") - movie.setAttribute("class", "movie") - let image = document.createElement("img") - image.setAttribute("class", "movieImage") - image.setAttribute("src", imageUrl) - image.setAttribute("alt", movieName) - image.setAttribute("title", movieName) - let title = document.createElement("p") - title.setAttribute("class", "movieTitle") - title.innerHTML = movieName - - movie.appendChild(image) - movie.appendChild(title) - similar.appendChild(movie) - } - - let childs = document.getElementsByClassName("movie") - let childsLength = childs.length - let similar = document.getElementsByClassName("containerSimilar")[0] - similar.style.gridTemplateColumns = "repeat(" + childsLength + ", 1fr)" - - - let imagePopup = document.getElementsByClassName("coverPopup")[0] - imagePopup.setAttribute("src", moviePoster); - if (imagePopup.src === "https://image.tmdb.org/t/p/originalNone") { - imagePopup.src = "/images/broken.webp" - } - imagePopup.setAttribute("alt", movieTitle); - imagePopup.setAttribute("title", movieTitle); - - let titlePopup = document.getElementsByClassName("titlePopup")[0] - titlePopup.innerHTML = movieTitle; - - let descriptionPopup = document.getElementsByClassName("descriptionPopup")[0] - descriptionPopup.innerHTML = movieDescription; - - let notePopup = document.getElementsByClassName("notePopup")[0] - notePopup.innerHTML = `Note : ${movieNote}/10`; - - let yearPopup = document.getElementsByClassName("yearPopup")[0] - yearPopup.innerHTML = `Date : ${movieYear}`; - - let genrePopup = document.getElementsByClassName("genrePopup")[0] - let genreList = movieGenre - let genreString = "" - for (let i = 0; i < genreList.length; i++) { - genreString += genreList[i] - if (i !== genreList.length - 1) { - genreString += ", " - } - } - genrePopup.innerHTML = `Genre : ${genreString}`; - - let durationPopup = document.getElementsByClassName("durationPopup")[0] - durationPopup.innerHTML = `Durée : ${movieDuration}`; - for (let i = 0; i < movieCast.length; i++) { - let castMember = document.createElement("div") - castMember.className = "castMember" - let castImage = document.createElement("img") - castImage.className = "castImage" - let castImageUrl = movieCast[i][2] - let castRealName = movieCast[i][0] - let castId = movieCast[i][3] - let castCharacterName = movieCast[i][1] - castImage.setAttribute("src", castImageUrl) - castImage.setAttribute("alt", castId) - castImage.setAttribute("title", castRealName) - castMember.appendChild(castImage) - let castName = document.createElement("p") - castName.className = "castName" - castName.innerHTML = castRealName - castMember.appendChild(castName) - let castCharacter = document.createElement("p") - castCharacter.className = "castCharacter" - castCharacter.innerHTML = castCharacterName - castMember.appendChild(castCharacter) - let castPopup = document.getElementById("castPopup") - castPopup.appendChild(castMember) - } - - let castMembers = document.getElementsByClassName("castMember") - for (let i = 0; i < castMembers.length; i++) { - castMembers[i].addEventListener("click", function() { - let castImage = this.children[0] - let castId = castImage.getAttribute("alt") - let castUrl = "/actor/" + castId - window.location.href = castUrl - }) - } - - let trailer = document.getElementsByClassName("containerTrailer")[0] - if (movieTrailer === "") { - trailer.style.display = "none" - } else { - trailer.style.display = "block" - let trailerVideo = document.createElement("iframe") - let regex = /^(http|https):\/\//g - if (regex.test(movieTrailer)) { - movieTrailer.replace(regex, "") - } - trailerVideo.setAttribute("src", movieTrailer) - trailerVideo.setAttribute("class", "trailerVideo") - trailerVideo.setAttribute("id", "trailerVideo") - trailer.appendChild(trailerVideo) - } - - let playButton = document.getElementsByClassName("playPopup")[0] - playButton.setAttribute("href", movieUrl); - }) - } else { - fetch("/getSerieData/" + movieId).then(function(response) { - return response.json() - }).then(function(data) { - let serieTitle = data.originalName - let serieCast = data.cast - let serieDescription = data.description - let serieDuration = data.duration - let serieGenre = data.genre - let serieNote = data.note - let seriePoster = data.serieCoverPath - let serieUrl = data.slug - let serieYear = data.date - let serieTrailer = data.bandeAnnonceUrl - let serieSimilar = data.similarSeries - let serieSeasons = data.seasons - let containerSimilar = document.getElementsByClassName("containerSimilar")[0] - let containerSeasons = document.getElementsByClassName("containerSeasons")[0] - - if (serieSimilar === undefined || serieSimilar.length === 0) { - containerSimilar.style.display = "none" - - } else { - containerSimilar.style.display = "inline-grid" - - - for (let i = 0; i < serieSimilar.length; i++) { - if (i < 4) { - let serie = serieSimilar[i] - let imageUrl = serie.cover - let serieName = serie.realTitle - let similar = document.getElementsByClassName("containerSimilar")[0] - serie = document.createElement("div") - serie.setAttribute("class", "serie") - let image = document.createElement("img") - image.setAttribute("class", "serieImage") - image.setAttribute("src", imageUrl) - image.setAttribute("alt", serieName) - image.setAttribute("title", serieName) - let title = document.createElement("p") - title.setAttribute("class", "serieTitle") - title.innerHTML = serieName - - serie.appendChild(image) - serie.appendChild(title) - similar.appendChild(serie) - } - } - } - serieSeasons = Object.values(serieSeasons) - for (let season of serieSeasons) { - let seasonCover = season.seasonCoverPath - let seasonDescription = season.seasonDescription - let seasonName = season.seasonName - let seasonEpisodesNumber = season.episodesNumber - let seasonNumber = season.seasonNumber - let seasonUrl = "/serie/" + serieTitle + "/" + seasonNumber - let seasonRelease = season.release - let seasonId = season.seasonId - let seasonDiv = document.createElement("div") - seasonDiv.className = "season" - seasonDiv.setAttribute("id", seasonNumber) - seasonDiv.setAttribute("onclick", `goToSeason("${seasonId}")`) - - let seasonCoverImage = document.createElement("img") - seasonCoverImage.className = "seasonCoverImage" - seasonCoverImage.setAttribute("src", seasonCover) - seasonCoverImage.setAttribute("alt", seasonName) - seasonCoverImage.setAttribute("title", seasonName) - seasonCoverImage.setAttribute("onclick", `goToSeason("${seasonId}")`) - - let seasonNameP = document.createElement("p") - seasonNameP.className = "seasonTitle" - seasonNameP.innerHTML = seasonName - seasonNameP.setAttribute("onclick", `goToSeason("${seasonId}")`) - - seasonDiv.appendChild(seasonCoverImage) - seasonDiv.appendChild(seasonNameP) - containerSeasons.appendChild(seasonDiv) - } - - let childs = document.getElementsByClassName("serie") - let childsLength = childs.length - let similar = document.getElementsByClassName("containerSimilar")[0] - similar.style.gridTemplateColumns = "repeat(" + childsLength + ", 1fr)" - - - let imagePopup = document.getElementsByClassName("coverPopup")[0] - imagePopup.setAttribute("src", seriePoster); - if (imagePopup.src === "https://image.tmdb.org/t/p/originalNone") { - imagePopup.src = "/images/broken.webp" - } - imagePopup.setAttribute("alt", serieTitle); - imagePopup.setAttribute("title", serieTitle); - - let titlePopup = document.getElementsByClassName("titlePopup")[0] - titlePopup.innerHTML = serieTitle; - - let descriptionPopup = document.getElementsByClassName("descriptionPopup")[0] - descriptionPopup.innerHTML = serieDescription; - - let notePopup = document.getElementsByClassName("notePopup")[0] - notePopup.innerHTML = `Note : ${serieNote}/10`; - - let yearPopup = document.getElementsByClassName("yearPopup")[0] - yearPopup.innerHTML = `Date : ${serieYear}`; - - let genrePopup = document.getElementsByClassName("genrePopup")[0] - let genreList = JSON.parse(serieGenre) - let genreString = genreList.join(", ") - genrePopup.innerHTML = `Genre : ${genreString}`; - - let durationPopup = document.getElementsByClassName("durationPopup")[0] - durationPopup.innerHTML = `Durée : ${serieDuration}`; - - serieCast = JSON.parse(serieCast) - for (let i = 0; i < serieCast.length; i++) { - let cast = serieCast[i] - - let castMember = document.createElement("div") - castMember.className = "castMember" - let castImage = document.createElement("img") - castImage.className = "castImage" - let castImageUrl = cast[2] - if (castImageUrl === "None") { - castImage.src = "/images/broken.webp" - } - let castRealName = cast[0] - let castCharacterName = cast[1] - castImage.setAttribute("src", castImageUrl) - castImage.setAttribute("alt", cast[3]) - castImage.setAttribute("title", castRealName) - castMember.appendChild(castImage) - let castName = document.createElement("p") - castName.className = "castName" - castName.innerHTML = castRealName - castMember.appendChild(castName) - let castCharacter = document.createElement("p") - castCharacter.className = "castCharacter" - castCharacter.innerHTML = castCharacterName - castMember.appendChild(castCharacter) - let castPopup = document.getElementById("castPopup") - castPopup.appendChild(castMember) - } - - let castMembers = document.getElementsByClassName("castMember") - for (let i = 0; i < castMembers.length; i++) { - castMembers[i].addEventListener("click", function() { - let castImage = this.children[0] - let castId = castImage.getAttribute("alt") - let castUrl = "/actor/" + castId - window.location.href = castUrl - }) - } - - let trailer = document.getElementsByClassName("containerTrailer")[0] - if (serieTrailer === "") { - trailer.style.display = "none" - } else { - trailer.style.display = "block" - let trailerVideo = document.createElement("iframe") - let regex = /^(http|https):\/\//g - if (regex.test(serieTrailer)) { - serieTrailer.replace(regex, "") - } - trailerVideo.setAttribute("src", serieTrailer) - trailerVideo.setAttribute("class", "trailerVideo") - trailerVideo.setAttribute("id", "trailerVideo") - trailer.appendChild(trailerVideo) - } - - let playButton = document.getElementsByClassName("playPopup")[0] - playButton.setAttribute("href", serieUrl); - }) - } - }) - }) - let moviesTitleH2 = document.getElementsByClassName("moviesTitle")[0] - let seriesTitleH2 = document.getElementsByClassName("seriesTitle")[0] - let actorMovieDiv = document.getElementsByClassName("actorMoviesList")[0] - let actorSerieDiv = document.getElementsByClassName("actorSeriesList")[0] - - let numberOfMovies = actorMovieDiv.children.length - let numberOfSeries = actorSerieDiv.children.length - - if (numberOfSeries === 0) { - seriesTitleH2.style.display = "none" - actorSerieDiv.style.display = "none" - } else if (numberOfSeries <= 3) { - seriesTitleH2.style.display = "block" - actorSerieDiv.style.gridTemplateColumns = "repeat(" + numberOfSeries + ", 1fr)" - actorSerieDiv.style.display = "grid" - } else { - seriesTitleH2.style.display = "block" - actorSerieDiv.style.gridTemplateColumns = "repeat(3, 1fr)" - actorSerieDiv.style.display = "grid" - } - - if (numberOfMovies === 0) { - moviesTitleH2.style.display = "none" - actorMovieDiv.style.display = "none" - } else if (numberOfMovies <= 3) { - moviesTitleH2.style.display = "block" - actorMovieDiv.style.gridTemplateColumns = "repeat(" + numberOfMovies + ", 1fr)" - actorMovieDiv.style.display = "grid" - } else { - moviesTitleH2.style.display = "block" - actorMovieDiv.style.gridTemplateColumns = "repeat(3, 1fr)" - actorMovieDiv.style.display = "grid" - } -} - -function getActorMovies() { - let href = window.location.href - let actorId = href.split("/") - actorId = actorId[actorId.length - 1] - fetch(`/getActorData/${actorId}`).then(function(response) { - return response.json() - }).then(function(data) { - - let actorName = data.actorName - let actorImageLink = data.actorImage - let actorDescriptionText = data.actorDescription - let actorBirthday = data.actorBirthday - let actorBirthplace = data.actorBirthplace - let actorMovies = data.actorMovies - let actorSeries = data.actorSeries - - let actorNameTitle = document.getElementsByClassName("actorName")[0] - actorNameTitle.innerHTML = actorName - - let actorMovieDiv = document.getElementsByClassName("actorMoviesList")[0] - let actorSerieDiv = document.getElementsByClassName("actorSeriesList")[0] - let seriesTitleH2 = document.getElementsByClassName("seriesTitle")[0] - - let actorImage = document.getElementsByClassName("actorPicture")[0] - actorImage.setAttribute("src", actorImageLink) - actorImage.setAttribute("alt", actorName) - actorImage.setAttribute("title", actorName) - - let actorDescription = document.getElementsByClassName("actorBiography")[0] - actorDescription.innerHTML = actorDescriptionText - if (actorDescription.length > 1100) { - actorDescription.innerHTML = actorDescription.innerHTML.substring(0, 1100) + "..." - actorDescription.innerHTML += " Lire la suite" - let lireLaSuite = document.getElementById("lireLaSuite") - lireLaSuite.addEventListener("click", function() { - actorDescription.innerHTML = actorDescriptionText - let actorInformation = document.getElementById("actorInformations") - actorInformation.style.overflow = "scroll" - }) - } - - - - for (let i = 0; i < actorMovies.length; i++) { - let realTitle = actorMovies[i].realTitle - let cover = actorMovies[i].cover - let actorMovie = document.createElement("div") - actorMovie.setAttribute("class", "actorMovie cover") - actorMovie.setAttribute("id", "cover") - - let actorMovieContent = document.createElement("div") - actorMovieContent.setAttribute("class", "actorMovieContent content") - actorMovieContent.setAttribute("mediaType", "movie") - - let actorMoviePicture = document.createElement("img") - actorMoviePicture.setAttribute("class", "actorMoviePicture cover_movie") - actorMoviePicture.setAttribute("src", cover) - actorMoviePicture.setAttribute("alt", realTitle) - actorMoviePicture.setAttribute("title", realTitle) - actorMoviePicture.setAttribute("data-id", actorMovies[i].id) - let actorMovieTitle = document.createElement("p") - actorMovieTitle.setAttribute("class", "actorMovieTitle") - actorMovieTitle.innerHTML = realTitle - - actorMovie.appendChild(actorMoviePicture) - actorMovie.appendChild(actorMovieTitle) - actorMovieContent.appendChild(actorMovie) - actorMovieDiv.appendChild(actorMovieContent) - } - - for (let i = 0; i < actorSeries.length; i++) { - let realTitle = actorSeries[i].name - let cover = actorSeries[i].serieCoverPath - let actorSerie = document.createElement("div") - actorSerie.setAttribute("class", "actorSerie cover") - actorSerie.setAttribute("id", "cover") - - let actorSerieContent = document.createElement("div") - actorSerieContent.setAttribute("class", "actorSerieContent content") - actorSerieContent.setAttribute("mediaType", "serie") - - let actorSeriePicture = document.createElement("img") - actorSeriePicture.setAttribute("class", "actorSeriePicture cover_movie") - actorSeriePicture.setAttribute("src", cover) - actorSeriePicture.setAttribute("alt", realTitle) - actorSeriePicture.setAttribute("title", realTitle) - actorSeriePicture.setAttribute("data-id", actorSeries[i].id) - let actorSerieTitle = document.createElement("p") - actorSerieTitle.setAttribute("class", "actorSerieTitle") - actorSerieTitle.innerHTML = realTitle - - actorSerie.appendChild(actorSeriePicture) - actorSerie.appendChild(actorSerieTitle) - actorSerieContent.appendChild(actorSerie) - actorSerieDiv.appendChild(actorSerieContent) - } - - setPopup() - }) -} - - -window.onload = function() { - getActorMovies() -} \ No newline at end of file diff --git a/src/static/js/addMedia.js b/src/static/js/addMedia.js deleted file mode 100644 index 1ba7bc2..0000000 --- a/src/static/js/addMedia.js +++ /dev/null @@ -1,238 +0,0 @@ -// fetch à /listQualities, et ajoute les options dans le select -function addQualities() { - let mediaType = document.querySelector(`#mediaType option[value="${document.getElementById("mediaTypeInput").value}"]`).getAttribute("data-value") - console.log(mediaType) - fetch('/listQualities/'+mediaType).then(response => response.json()).then(data => { - let select = document.getElementById("allQualities"); - select.innerHTML = ""; - for (let i = 0; i < data.length; i++) { - let option = document.createElement("option"); - option.value = data[i]["name"]; - option.setAttribute("data-value", data[i]["id"]); - document.getElementById("allQualities").appendChild(option); - } - }) - .catch(error => console.error(error)); -} - -function showErrorMessage(message, type) { - let classes = { - "alert": "solid red", - "info": "solid yellow", - "success": "solid green", - } - let errorBlock = document.createElement("div"); - errorBlock.classList.add("alert"); - errorBlock.classList.add("alert-danger"); - errorBlock.setAttribute("role", "alert"); - let messageBlock = document.createElement("p"); - messageBlock.innerHTML = message; - messageBlock.classList.add("alert-message"); - messageBlock.style.borderTop = classes[type]; - errorBlock.appendChild(messageBlock); - document.body.appendChild(errorBlock); - //sleep 1 second - setTimeout(function() { - errorBlock.style.opacity = "1"; - }, 1000); - - // Remove error message after 5 seconds - - setTimeout(function() { - errorBlock.style.opacity = "0"; - setTimeout(function() { - errorBlock.remove(); - }, 1000); - }, 5000); -} - -function searchForMedia() { - let mediaType = document.querySelector(`#mediaType option[value="${document.getElementById("mediaTypeInput").value}"]`) - if (mediaType === null) { - showErrorMessage("Please select a media type", "alert") - return; - } else { - mediaType = mediaType.getAttribute("data-value") - } - let title = document.getElementById("title").value - fetch('/lookup', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - mediaType: mediaType, - query: title - }) - }) - .then(response => response.json()) - .then(data => { - let results = document.getElementById("results"); - results.innerHTML = ""; - for (let i = 0; i < data.length; i++) { - let file = data[i]; - let type = undefined - let ID = file["tmdbId"] - if (mediaType === "serie") { - ID = file["tvdbId"]; - } - let poster = file["remotePoster"]; - let title = file["title"]; - - if (mediaType === "music") { - console.log(file); - ID = file["foreignId"]; - if (file["artist"] !== undefined) { - file = file["artist"]; - poster = file["remotePoster"]; - title = file["artistName"]; - ID = title - type = "artist"; - } else if (file["album"] !== undefined) { - file = file["album"]; - poster = file["remoteCover"]; - title = file["title"]; - ID = title - type = "album"; - } - } - if (poster === undefined) { - poster = "/static/img/broken.webp"; - } - if (poster.includes("thetvdb.com")) { - fetch('/getIMDBPoster', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - imdbId: file["imdbId"] - }) - }) - .then(response => response.json()) - .then(data => { - console.log(data); - poster = data["url"]; - setCard(poster, file["tvdbId"], title, type, i); - }) - } else { - setCard(poster, ID, title, type, i); - } - } - }) -} - -function setCard(url, ID, title=undefined, type=undefined, uniqueID) { - let card = document.createElement("div"); - card.classList.add("coverAddMedia"); - card.setAttribute("data-id", ID); - card.setAttribute("data-type", type); - card.setAttribute("data-uniqueID", uniqueID); - - // Create the image - let image = document.createElement("img"); - image.classList.add("cover-image"); - image.setAttribute("src", url); - - card.appendChild(image); - - // Create the title if it exists - if (title !== undefined) { - let titleBlock = document.createElement("p"); - titleBlock.classList.add("cover-title"); - titleBlock.innerHTML = title; - card.appendChild(titleBlock); - } - - - card.addEventListener("click", function() { - setMovie(uniqueID); - }); - let results = document.getElementById("results"); - results.appendChild(card); - } - - -function addMedia(qualityID) { - let mediaType = document.querySelector(`#mediaType option[value="${document.getElementById("mediaTypeInput").value}"]`).getAttribute("data-value") - let type; - try { - type = document.querySelector(".coverAddMedia").getAttribute("data-type"); - } catch { - showErrorMessage("Please select a media", "alert"); - return; - } - let ID = document.querySelector(".coverAddMedia").getAttribute("data-id"); - fetch('/addMedia', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - mediaType: mediaType, - ID: ID, - qualityID: qualityID, - type: type - }) - }) - .then(response => response.json()) - .then(data => { - console.log(data); - if (data["status"] === "ok") { - showErrorMessage("Media added successfully", "success"); - setTimeout(function() { - window.location.reload(); - }, 9000); - } else { - showErrorMessage("Error adding media", "alert"); - } - }) -} - - -function showButton(qualityID) { - let addButton = document.createElement("button"); - addButton.classList.add("addMovieButton"); - - addButton.innerHTML = "Add"; - addButton.addEventListener("click", function() { - addMedia(qualityID); - }); - document.body.appendChild(addButton); -} - -function setMovie(ID) { - // remove all the other cards - let cards = document.getElementsByClassName("coverAddMedia"); - while (cards.length > 1) { - for (let i = 0; i < cards.length; i++) { - if (cards[i].getAttribute("data-uniqueID") !== ID) { - console.log(`Removing ${cards[i].getAttribute("data-uniqueID")}, cause it's not ${ID}`) - cards[i].remove(); - } - } - } -} - -window.addEventListener('load', function() { - let mediaTypeInput = document.getElementById("mediaTypeInput"); - mediaTypeInput.addEventListener('change', function() { - addQualities(); - }); - document.getElementById("qualityInput").addEventListener("change", function() { - var selectedOption = this.value; - let qualityID = document.querySelector('#allQualities option[value="' + selectedOption + '"]').getAttribute("data-value"); - showButton(qualityID) - }); - - let timeoutId = null; - - const input = document.querySelector('#title'); - input.addEventListener('input', function() { - clearTimeout(timeoutId); - timeoutId = setTimeout(function() { - console.log('No change for 2 seconds'); - searchForMedia() - }, 1500); - }); -}); \ No newline at end of file diff --git a/src/static/js/book.js b/src/static/js/book.js deleted file mode 100644 index 8f1d21e..0000000 --- a/src/static/js/book.js +++ /dev/null @@ -1,84 +0,0 @@ -var currentPage = 0; -var maxPages; -var bookDiv = document.getElementById("bookDiv"); -url = window.location.href; -let zoomed = false; -bookId = url.substring(url.lastIndexOf('/') + 1); - -fetch(`/bookData/${bookId}`).then(function(response) { - return response.json(); -}).then(function(json) { - maxPages = json.nbPages; -}); - -let nextImage; -let previousImage; -let previsousPage = 0; - -// Function to load an image from the server -function loadImage(pageNumber) { - fetch(`/bookUrl/${bookId}/${pageNumber}`) - .then(response => response.text()).then(response => { - var img = document.getElementById("bookImage"); - img.src = "data:image/png;base64," + response; - }); -} - -// Function to go to the next page -function nextPage() { - previousPage = currentPage; - currentPage++; - loadImage(currentPage); -} - -// Function to go to the previous page -function previousPage() { - previousPage = currentPage; - currentPage--; - loadImage(currentPage); -} - -// Function to zoom the book -function zoomBook() { - bookDiv.classList.toggle("bigBookDiv"); - document.getElementById("expandBook").classList.toggle("buttonFullScreenClicked"); - document.getElementById("previous-page").classList.toggle("bigArrowPrev"); - document.getElementById("next-page").classList.toggle("bigArrowNext"); - - if (!zoomed) { - if (bookDiv.requestFullscreen) { - bookDiv.requestFullscreen(); - zoomed = true; - } else if (bookDiv.mozRequestFullScreen) { /* Firefox */ - bookDiv.mozRequestFullScreen(); - zoomed = true; - } else if (bookDiv.webkitRequestFullscreen) { /* Chrome, Safari and Opera */ - bookDiv.webkitRequestFullscreen(); - zoomed = true; - } else if (bookDiv.msRequestFullscreen) { /* IE/Edge */ - bookDiv.msRequestFullscreen(); - zoomed = true; - } - } else { - if (document.exitFullscreen) { - document.exitFullscreen(); - zoomed = false; - } else if (document.mozCancelFullScreen) { /* Firefox */ - document.mozCancelFullScreen(); - zoomed = false; - } else if (document.webkitExitFullscreen) { /* Chrome, Safari and Opera */ - document.webkitExitFullscreen(); - zoomed = false; - } else if (document.msExitFullscreen) { /* IE/Edge */ - document.msExitFullscreen(); - zoomed = false; - } - } -} -// Add event listeners to the buttons -document.getElementById("next-page").addEventListener("click", nextPage); -document.getElementById("previous-page").addEventListener("click", previousPage) - -document.getElementById("expandBook").addEventListener("click", zoomBook); -// Load the first page -window.onload = loadImage(currentPage); \ No newline at end of file diff --git a/src/static/js/books.js b/src/static/js/books.js deleted file mode 100644 index 94617b7..0000000 --- a/src/static/js/books.js +++ /dev/null @@ -1,48 +0,0 @@ -function hideLoader() { - spinner = document.getElementById("spinner") - backgroundSpinner = document.getElementById("loaderBackground") - spinner.style.visibility = "hidden" - backgroundSpinner.style.display = "none" -} - -function getAllBooks() { - var url = window.location.href - var library = url.split("/")[4] - let booksRoute = document.getElementsByClassName("booksRoute")[0]; - let bookUrlRoute = booksRoute.id - fetch(bookUrlRoute).then(function(response) { - return response.json(); - }).then(function(json) { - books = json - var bookList = document.getElementById("bookList"); - for (book of books) { - const bookID = book.id - var bookDiv = document.createElement("div"); - bookDiv.className = "bookDiv"; - var bookNameDiv = document.createElement("div"); - bookNameDiv.className = "bookNameDiv"; - var bookImageDiv = document.createElement("div"); - bookImageDiv.className = "bookImageDiv"; - var bookImage = document.createElement("img"); - bookImage.src = book.cover; - bookImage.className = "bookImage"; - bookImage.loading = "lazy"; - var bookName = document.createElement("p"); - bookName.className = "bookName"; - bookName.innerHTML = book.title; - bookImageDiv.appendChild(bookImage); - bookNameDiv.appendChild(bookName); - bookDiv.appendChild(bookImageDiv); - bookDiv.appendChild(bookNameDiv); - bookImageDiv.addEventListener("click", function() { - window.location.href = `/book/${bookID}`; - }); - bookNameDiv.addEventListener("click", function() { - window.location.href = `/book/${bookID}`; - }); - bookList.appendChild(bookDiv); - } - }) -} -getAllBooks() -hideLoader() diff --git a/src/static/js/channel.js b/src/static/js/channel.js deleted file mode 100644 index 93113a1..0000000 --- a/src/static/js/channel.js +++ /dev/null @@ -1,34 +0,0 @@ -options = { - controls: true, - preload: 'none', - techOrder: ['chromecast', 'html5'], - html5: { - vhs: { - overrideNative: !videojs.browser.IS_SAFARI, - }, - }, - controlBar: { - children: [ - 'playToggle', - 'volumePanel', - 'currentTimeDisplay', - 'progressControl', - 'remainingTimeDisplay', - 'chromecastButton', - 'airPlayButton', - 'pictureInPictureToggle', - 'fullscreenToggle', - ], - }, -} - -//add the quality selector -var player = videojs('movie', options); - -//when the player is ready, show the progress bar and set the visibility to hidden -player.ready(function() { - progressBar = document.querySelector('.vjs-progress-control'); - progressBar.style.visibility = 'hidden'; - progressBar.style.display = 'block'; - -}); \ No newline at end of file diff --git a/src/static/js/consoles.js b/src/static/js/consoles.js deleted file mode 100644 index d133a60..0000000 --- a/src/static/js/consoles.js +++ /dev/null @@ -1,47 +0,0 @@ -function hideLoader() { - spinner = document.getElementById("spinner") - backgroundSpinner = document.getElementById("loaderBackground") - spinner.style.visibility = "hidden" - backgroundSpinner.style.display = "none" -} - -function getAllConsoles() { - var url = window.location.href - var library = url.split("/")[4] - fetch(`/getAllConsoles/${library}`).then(function(response) { - return response.json(); - }).then(function(json) { - var systems = json; - systems = systems.sort() - var systemList = document.getElementById("systemList"); - for (system of systems) { - fetch("/getConsoleData/" + system).then(function(response) { - return response.json(); - }).then(function(json) { - var system = json; - var systemDiv = document.createElement("div"); - systemDiv.className = "systemDiv"; - var systemNameDiv = document.createElement("div"); - systemNameDiv.className = "systemNameDiv"; - var systemImageDiv = document.createElement("div"); - systemImageDiv.className = "systemImageDiv"; - var systemImage = document.createElement("img"); - systemImage.className = "systemImage"; - systemImage.src = system.image; - var systemName = document.createElement("p"); - systemName.className = "systemName"; - systemName.innerHTML = system.name; - systemImageDiv.appendChild(systemImage); - systemNameDiv.appendChild(systemName); - systemDiv.appendChild(systemImageDiv); - systemDiv.appendChild(systemNameDiv); - systemDiv.addEventListener("click", function() { - window.location.href = `/console/${library}/${system.name}`; - }); - systemList.appendChild(systemDiv); - }) - } - }) -} -getAllConsoles() -hideLoader() \ No newline at end of file diff --git a/src/static/js/createAccount.js b/src/static/js/createAccount.js deleted file mode 100644 index 4a94b01..0000000 --- a/src/static/js/createAccount.js +++ /dev/null @@ -1,7 +0,0 @@ -header = document.getElementsByTagName("header")[0]; -searchForm -header.remove() -searchForm = document.getElementById("searchForm"); -searchForm.remove() -settings = document.getElementsByClassName("settings")[0] -settings.remove() \ No newline at end of file diff --git a/src/static/js/editMovie.js b/src/static/js/editMovie.js deleted file mode 100644 index a3b8c08..0000000 --- a/src/static/js/editMovie.js +++ /dev/null @@ -1,35 +0,0 @@ -let movieFindedDivs = document.getElementsByClassName("movieFinded") -let originalMovieID = window.location.href.split("/")[4] -let realName = document.getElementById("realName").innerHTML -let libraryName = document.getElementById("library").innerHTML -for (let i = 0; i < movieFindedDivs.length; i++) { - let movieFindedDiv = movieFindedDivs[i] - movieFindedDiv.addEventListener("click", function() { - let movieID = movieFindedDiv.id - let form = document.createElement("form"); - form.method = "POST"; - form.action = `/editMovie/${realName}/${libraryName}`; - let input = document.createElement("input"); - input.type = "hidden"; - input.name = "newMovieID"; - input.value = `${movieID}`; - form.appendChild(input); - document.body.appendChild(form); - form.submit(); - }) -} - -let customIDButton = document.getElementById("customMovieButton") -customIDButton.addEventListener("click", function() { - let movieID = document.getElementById("movieID").value - let form = document.createElement("form"); - form.method = "POST"; - form.action = `/editMovie/${realName}/${libraryName}`; - let input = document.createElement("input"); - input.type = "hidden"; - input.name = "newMovieID"; - input.value = `${movieID}`; - form.appendChild(input); - document.body.appendChild(form); - form.submit(); -}) \ No newline at end of file diff --git a/src/static/js/editSerie.js b/src/static/js/editSerie.js deleted file mode 100644 index 9b5ff18..0000000 --- a/src/static/js/editSerie.js +++ /dev/null @@ -1,35 +0,0 @@ -let serieFindedDivs = document.getElementsByClassName("serieFinded") -let originalSerieID = window.location.href.split("/")[4] -let realName = document.getElementById("realName").innerHTML -let libraryName = document.getElementById("library").innerHTML -for (let i = 0; i < serieFindedDivs.length; i++) { - let serieFindedDiv = serieFindedDivs[i] - serieFindedDiv.addEventListener("click", function() { - let serieID = serieFindedDiv.id - let form = document.createElement("form"); - form.method = "POST"; - form.action = `/editSerie/${realName}/${libraryName}`; - let input = document.createElement("input"); - input.type = "hidden"; - input.name = "newSerieID"; - input.value = `${serieID}`; - form.appendChild(input); - document.body.appendChild(form); - form.submit(); - }) -} - -let customIDButton = document.getElementById("customSerieButton") -customIDButton.addEventListener("click", function() { - let serieID = document.getElementById("serieID").value - let form = document.createElement("form"); - form.method = "POST"; - form.action = `/editSerie/${realName}/${libraryName}`; - let input = document.createElement("input"); - input.type = "hidden"; - input.name = "newSerieID"; - input.value = `${serieID}`; - form.appendChild(input); - document.body.appendChild(form); - form.submit(); -}) \ No newline at end of file diff --git a/src/static/js/game.js b/src/static/js/game.js deleted file mode 100644 index 943c056..0000000 --- a/src/static/js/game.js +++ /dev/null @@ -1,4 +0,0 @@ -backButton = document.getElementById("backButton") -backButton.addEventListener("click", function() { - window.history.back(); -}); diff --git a/src/static/js/games.js b/src/static/js/games.js deleted file mode 100644 index 9390426..0000000 --- a/src/static/js/games.js +++ /dev/null @@ -1,45 +0,0 @@ -function getAllGames() { - var title = document.getElementsByTagName("title")[0].innerHTML; - console = title.split(" | ")[0] - fetch(`/getGames/${console}`).then(function(response) { - return response.json(); - }).then(function(json) { - var games = json; - for (game of games) { - var gameDiv = document.createElement("div"); - gameDiv.className = "gameDiv"; - var gameImageDiv = document.createElement("div"); - gameImageDiv.className = "gameImageDiv"; - var gameImage = document.createElement("img"); - gameImage.className = "gameImage"; - gameImage.src = game.cover; - var gameName = document.createElement("p"); - gameName.className = "gameName"; - gameName.innerHTML = game.title; - gameImageDiv.appendChild(gameImage); - gameDiv.appendChild(gameImageDiv); - gameDiv.appendChild(gameName); - let realTitle = game.realTitle; - gameDiv.addEventListener("click", function() { - window.location.href = `/game/${console}/${realTitle}`; - }); - var gameList = document.getElementById("gameList"); - gameList.appendChild(gameDiv); - }; - }); -} - -backButton = document.getElementById("backButton") -backButton.addEventListener("click", function() { - window.history.back(); -}); - -function hideLoader() { - spinner = document.getElementById("spinner") - backgroundSpinner = document.getElementById("loaderBackground") - spinner.style.visibility = "hidden" - backgroundSpinner.style.display = "none" -} - -getAllGames() -hideLoader() \ No newline at end of file diff --git a/src/static/js/main.js b/src/static/js/main.js deleted file mode 100644 index 47007b5..0000000 --- a/src/static/js/main.js +++ /dev/null @@ -1,42 +0,0 @@ -let homeButton = document.getElementById("goHome") -let logo = document.getElementById("logo") - -logo.addEventListener("click", function() { - window.location.href = "/home" -}) - -homeButton.addEventListener("click", function() { - window.location.href = "/home" -}) - -function search() { - var search = document.getElementById("search").value - let actualHref = window.location.href - let libraryName = actualHref.split("/")[4].replace("#", "") - if (search !== "" && actualHref.split("/").length >= 5) { - window.location.href = `/search/${libraryName}/${search}` - } -} - -let searchForm = document.getElementById("searchForm") -searchForm.addEventListener("submit", function(event) { - event.preventDefault() - search() -}) - -// Register Service Worker -if ('serviceWorker' in navigator) { - navigator.serviceWorker - .register('/service-worker.js') - .then(function(registration) { - console.log('Service Worker Registered'); - return registration; - }) - .catch(function(err) { - console.error('Unable to register service worker.', err); - }); -} - -window.addEventListener('online', function(e) { - console.log("You are online"); -}, false); diff --git a/src/static/js/other.js b/src/static/js/other.js deleted file mode 100644 index b6022d8..0000000 --- a/src/static/js/other.js +++ /dev/null @@ -1,166 +0,0 @@ -function getCookie(name) { - const value = `; ${document.cookie}`; - const parts = value.split(`; ${name}=`); - if (parts.length === 2) return parts.pop().split(';').shift(); -} - -function editMovie(title, library) { - window.location.href = `/editMovie/${title}/${library}` -} - -const createObjectFromString = (str) => { - return eval(`(function () { return ${str}; })()`); -} - -function svgEl(name, attrs) { - const el = document.createElementNS("http://www.w3.org/2000/svg", name) - for ( const [ k, v ] of Object.entries(attrs) ){ - el.setAttribute(k, v); - } - return el -} - -function removeLoader(){ - const imgs = document.images - const imgsArray = Array.prototype.slice.call(document.images) - imgs.length = 32 - imgsArray.splice(36, imgsArray.length - 1) - imgsArray.splice(0, 4) - if (imgsArray.length == 0) { - spinner = document.getElementsByClassName("spinner")[0] - backgroundSpinner = document.getElementById("loaderBackground") - spinner.style.opacity = "0" - spinner.style.display = "none" - backgroundSpinner.style.display = "none" - } - - for (img of imgsArray) { - const acutalIndex = imgsArray.indexOf(img) - img = imgs.item(acutalIndex) - img.addEventListener("load", function() { - const imagesLenght = imgsArray.length - 1 - console.log(`${acutalIndex}/${imagesLenght-4}`) - if (acutalIndex == (imagesLenght-4)) { - spinner = document.getElementsByClassName("spinner")[0] - backgroundSpinner = document.getElementById("loaderBackground") - spinner.style.opacity = "0" - spinner.style.display = "none" - backgroundSpinner.style.display = "none" - } - }) - } -} - -function getFirstMovies() { - movies = document.getElementsByClassName("movies")[0] - routeToUse = movies.getAttribute("id") - movies.id = "movies" - let username = "" - fetch("/whoami").then(function(response) { - return response.json() - }).then(function(data) { - username = data.name - accountType = data.accountType - }).then(function() { - fetch(routeToUse).then(function(response) { - return response.json() - }).then(function(data) { - for (let i = 0; i < data.length; i++) { - data[i] - if (i > 0) { - movies = document.getElementsByClassName("movies")[0] - let movie = data[i] - let movieID = movie.videoHash - let cover = document.createElement("div") - cover.className = "cover" - cover.style.marginBottom = "2vh" - let content = document.createElement("div") - content.className = "content" - let image = document.createElement("img") - image.className = "cover_movie" - image.src = movie.banner - if (image.src == "https://image.tmdb.org/t/p/originalNone") { - image.src = brokenPath - } - image.title = movie.title - image.alt = movie.title - image.setAttribute("data-id", movieID) - image.setAttribute("loading", "lazy") - - vues = movie.vues - - - vues = createObjectFromString(vues) - timeCode = vues[username] - let timeLineBackground = document.createElement("div") - timeLineBackground.className = "timeLineBackground" - let timeLine = document.createElement("div") - timeLine.className = "timeLine" - let watchedTime = vues[username] - let movieDuration = movie.duration - //it's a timecode, convert it to seconds - movieDuration = movieDuration.split(":") - movieDuration = parseInt(movieDuration[0]) * 3600 + parseInt(movieDuration[1]) * 60 + parseInt(movieDuration[2]) - if ((watchedTime / movieDuration) * 100 <= 100) { - timeLine.style.width = `${(watchedTime / movieDuration) * 100}%` - } else if ((watchedTime / movieDuration) * 100 > 100) { - timeLine.style.width = "100%" - } else { - timeLine.style.width = "0%" - } - timeLineBackground.appendChild(timeLine) - content.appendChild(timeLineBackground) - - cover.addEventListener("click", function() { - window.location.href = "/otherVideo/" + movieID - }) - - content.appendChild(image) - cover.appendChild(content) - movies.appendChild(cover) - - } else { - bigBanner = document.getElementsByClassName("bigBanner")[0] - imageBanner = document.getElementsByClassName("bannerCover")[0] - titleBanner = document.getElementsByClassName("bannerTitle")[0] - watchNow = document.getElementsByClassName("watchNowA")[0] - movie = data[i] - let id = movie.videoHash - slug = "/otherVideo/" + id - bannerImage = movie.banner - cssBigBanner = `background-image: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(24, 24, 24, 0.85) 77.08%, #1D1D1D 100%), linear-gradient(95.97deg, #000000 0%, rgba(0, 0, 0, 0.25) 100%, #000000 100%), url("${bannerImage}")` - imageBanner.setAttribute('style', cssBigBanner) - - titleBanner.innerHTML = movie.title - - movieUrl = slug - watchNow.setAttribute("href", movieUrl) - } - } - - removeLoader(data) - - if (data.length == 1) { - let bigBackground = document.getElementsByClassName("bannerCover")[0] - bigBackground.style.height = "100vh" - - let bannerTitle = document.getElementsByClassName("bannerTitle")[0] - let bannerDescription = document.getElementsByClassName("bannerDescription")[0] - let watchNow = document.getElementsByClassName("watchNowA")[0] - - bannerGenre.style.top = "46vh" - bannerTitle.style.top = "47.5vh" - bannerDescription.style.top = "55vh" - watchNow.style.top = "65vh" - } - }) - }) -} - -window.onload = function() { - brokenPathDiv = document.getElementsByClassName("brokenPath")[0] - brokenPath = brokenPathDiv.getAttribute("id") - brokenPathDiv.parentNode.removeChild(brokenPathDiv) - getFirstMovies() - removeLoader() -} \ No newline at end of file diff --git a/src/static/js/otherVideo.js b/src/static/js/otherVideo.js deleted file mode 100644 index 90a8944..0000000 --- a/src/static/js/otherVideo.js +++ /dev/null @@ -1,163 +0,0 @@ -const createObjectFromString = (str) => { - return eval(`(function () { return ${str}; })()`); -} - -function getCookie(name) { - var cookieValue = null; - if (document.cookie && document.cookie !== '') { - var cookies = document.cookie.split(';'); - for (var i = 0; i < cookies.length; i++) { - var cookie = cookies[i].trim(); - // Does this cookie string begin with the name we want? - if (cookie.substring(0, name.length + 1) === (name + '=')) { - cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); - break; - } - } - } - return cookieValue; -} - -function getElementByXpath(path) { - return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; - } - -window.onload = function() { - let lastPush = 0 - let options; - - var path = window.location.pathname - movieID = window.location.href.split("/")[4] - - - options = { - controls: true, - preload: 'none', - techOrder: ['chromecast', 'html5'], - html5: { - vhs: { - overrideNative: !videojs.browser.IS_SAFARI, - }, - }, - controlBar: { - children: [ - 'playToggle', - 'volumePanel', - 'currentTimeDisplay', - 'progressControl', - 'remainingTimeDisplay', - 'captionsButton', - 'audioTrackButton', - 'chromecastButton', - 'airPlayButton', - 'pictureInPictureToggle', - 'fullscreenToggle', - ], - }, - } - - //add the quality selector - var player = videojs('movie', options); - player.maxQualitySelector({ - 'defaultQuality': 2, - 'displayMode': 0 - }) - - player.hotkeys({ - volumeStep: 0.1, - seekStep: 5, - enableModifiersForNumbers: false - }) - - player.mobileUi() - - - value = {false: "is not", true: "is"} - - console.log(`User ${value[videojs.browser.IS_IOS]} on IOS\nUser ${value[videojs.browser.IS_SAFARI]} on Safari\nUser ${value[videojs.browser.IS_ANDROID]} on Android\nUser ${value[videojs.browser.IS_CHROME]} on Chrome`) - - if (videojs.browser.IS_IOS || videojs.browser.IS_SAFARI) { - player.airPlay(); - let airPlayButton = getElementByXpath("//*[@id='movie']/div[4]/button[3]") - airPlayButton.classList.remove("vjs-hidden") - } else { - player.chromecast(); - let chromecastButton = getElementByXpath("//*[@id='movie']/div[4]/button[2]") - chromecastButton.classList.remove("vjs-hidden") - } - - - var video = document.getElementById("movie_html5_api") - video.addEventListener("timeupdate", function() { - let href = window.location.href - movieID = href.split("/")[4] - let currentTime = video.currentTime - currentTime = parseInt(currentTime) - if (currentTime == lastPush+1) { - fetch(`/setVuesOtherTimeCode/`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - //set the form - body: JSON.stringify({ - movieHASH: movieID, - timeCode: currentTime - }) - }) - lastPush = currentTime - } - }) - - - let username = "" - fetch("/whoami").then(function(response) { - return response.json() - }).then(function(data) { - username = data.name - }).then(function() { - fetch(`/getOtherData/${movieID}`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }).then(response => response.json()) - .then(data => { - vues = data.vues - //vues is a string representing an array convert it to an array - vues = createObjectFromString(vues) - if (vues[username] !== undefined){ - timeCode = vues[username] - timeCode = parseInt(timeCode) - var popup = document.getElementById("popup") - popup.style.display = "block" - - buttonYes = document.getElementById("buttonYes") - buttonYes.addEventListener("click", function() { - popup.style.display = "none" - document.body.style.overflow = "auto" - video = document.getElementById("movie_html5_api") - video.currentTime = timeCode - lastPush = timeCode - try { - video.play() - } catch (error) { - console.log(error) - } - }) - - buttonNo = document.getElementById("buttonNo") - buttonNo.addEventListener("click", function() { - popup.style.display = "none" - document.body.style.overflow = "auto" - video = document.getElementById("movie_html5_api") - }) - } - }) - }) - - var path = window.location.pathname - var slug = path.split("/") - slug = slug[2] - -} \ No newline at end of file diff --git a/src/static/js/profil.js b/src/static/js/profil.js deleted file mode 100644 index a60cea8..0000000 --- a/src/static/js/profil.js +++ /dev/null @@ -1,38 +0,0 @@ -profilePictureImg = document.getElementById("profilePictureImg") -editProfilePicture = document.getElementsByClassName("editProfilePicture")[0] -profilePictureInput = document.getElementById("profilePicture") -profilePictureImg.addEventListener("mouseover", function() { - editProfilePicture.style.display = "block" -}) -editProfilePicture.addEventListener("mouseover", function() { - editProfilePicture.style.display = "block" -}) -editProfilePicture.addEventListener("mouseout", function() { - editProfilePicture.style.display = "none" -}) -profilePictureImg.addEventListener("mouseout", function() { - editProfilePicture.style.display = "none" -}) - -editProfilePicture.addEventListener("click", function() { - profilePictureInput.click() -}) - -profilePictureInput.addEventListener("change", function() { - var file = document.getElementById("profilePicture").files[0]; - getBase64(file) -}) - - -function getBase64(file) { - var reader = new FileReader(); - reader.readAsDataURL(file); - reader.onload = function() { - resultat = reader.result; - profilePictureImg = document.getElementById("profilePictureImg") - profilePictureImg.setAttribute('src', resultat) - }; - reader.onerror = function(error) { - console.log('Error: ', error); - }; -} \ No newline at end of file diff --git a/src/static/js/service-worker.js b/src/static/js/service-worker.js deleted file mode 100644 index 20877ed..0000000 --- a/src/static/js/service-worker.js +++ /dev/null @@ -1,107 +0,0 @@ -importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js'); - -const cacheName = 'ChocolatePWACache'; - -const offlineFallbackPage = '/offline'; - -const filesToCache = [ - '/', - - '/static/css/style.css', - - '/static/js/actor.js', - '/static/js/allFilms.js', - '/static/js/allSeries.js', - '/static/js/consoles.js', - '/static/js/createAccount.js', - '/static/js/game.js', - '/static/js/games.js', - '/static/js/login.js', - '/static/js/main.js', - '/static/js/movie.js', - '/static/js/profil.js', - '/static/js/season.js', - '/static/js/serie.js', - '/static/js/settings.js', - - - '/templates/index.html', - '/templates/actor.html', - '/templates/allFilms.html', - '/templates/allSeries.html', - '/templates/consoles.html', - '/templates/createAccount.html', - '/templates/film.html', - '/templates/game.html', - '/templates/games.html', - '/templates/header.html', - '/templates/index.html', - '/templates/login.html', - '/templates/popup.html', - '/templates/profil.html', - '/templates/season.html', - '/templates/serie.html', - '/templates/settings.html', - - '/static/images/broken.png', - '/static/images/brokenBanner.png', - '/static/images/defaultUserProfilePic.png', - '/static/images/loader.gif', - '/static/images/logo.ico', - '/static/images/logo.png', -]; - - -self.addEventListener("message", (event) => { - if (event.data && event.data.type === "SKIP_WAITING") { - self.skipWaiting(); - } -}); - -self.addEventListener('install', async (event) => { - event.waitUntil( - caches.open(CACHE) - .then((cache) => cache.add(offlineFallbackPage)) - ); -}); - -if (workbox.navigationPreload.isSupported()) { - workbox.navigationPreload.enable(); -} - -self.addEventListener('activate', function(e) { - console.log('[ServiceWorker] Activate'); - e.waitUntil( - caches.keys().then(function(keyList) { - return Promise.all(keyList.map(function(key) { - if (key !== cacheName) { - console.log('[ServiceWorker] Removing old cache', key); - return caches.delete(key); - } - })); - }) - ); - return self.clients.claim(); -}); - -self.addEventListener('fetch', (event) => { - if (event.request.mode === 'navigate') { - event.respondWith((async () => { - try { - const preloadResp = await event.preloadResponse; - - if (preloadResp) { - return preloadResp; - } - - const networkResp = await fetch(event.request); - return networkResp; - } catch (error) { - - const cache = await caches.open(CACHE); - const cachedResp = await cache.match(offlineFallbackPage); - return cachedResp; - } - })()); - } -}); \ No newline at end of file diff --git a/src/static/js/settings.js b/src/static/js/settings.js deleted file mode 100644 index ac248ad..0000000 --- a/src/static/js/settings.js +++ /dev/null @@ -1,260 +0,0 @@ -function closePopup(){ - popup = document.getElementById("popupLibrary") - popup.style.display = "none" -} - -function saveSettings(event) { - event.preventDefault() - language = document.getElementById("language").value - document.cookie = "language=" + language + "; path=/"; - port = document.getElementById("port").value - document.cookie = "port=" + port + "; path=/"; - - form = document.getElementById("saveSettingsForm") - form.action = "/saveSettings" - form.submit() -} - -function createAccount(event) { - type = document.getElementById("type").value - password = document.getElementById("password").value - if (type == "Admin" && password == "") { - alert("You need to enter a password for an Admin account") - } else { - form = document.getElementById("createAccount") - form.action = "/createAccount" - form.submit() - } -} - -function getCookie(name) { - const value = `; ${document.cookie}`; - const parts = value.split(`; ${name}=`); - if (parts.length === 2) return parts.pop().split(';').shift(); -} - -function addLibrary() { - const popupLibrary = document.getElementById("popupLibrary") - popupLibrary.style.display = "block" -} - -function editLib(libName) { - //get the div with the libName - let libDiv = document.getElementById(libName) - libTypeInput = libDiv.children[1] - libType = libTypeInput.value - libPathInput = libDiv.children[3] - libPath = libPathInput.value - allUsers = [] - users = libDiv.children[4].children - for (user of users) { - //get the 4th child of the user div - userCheckbox = user.children[2] - if (userCheckbox.checked) { - allUsers.push(userCheckbox.getAttribute("username")) - } - } - allUsers = allUsers.join(",") - fetch(`/editLib/${libName}`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - //set the form - body: JSON.stringify({ - libType: libType, - libPath: libPath, - libUsers: allUsers - }) - }).then(function() { - location.reload() - }) -} - -function deleteLib(libName) { - //create a popup to confirm the deletion - const popupLibrary = document.createElement("div") - document.body.appendChild(popupLibrary) - fetch(`/deleteLib/${libName}`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - //set the form - body: JSON.stringify({ - libName: libName - }) - }).then(function() { - location.reload() - }) -} - -window.onload = function() { - portCookie = getCookie("port") - if (portCookie !== undefined) { - document.getElementById("port").value = portCookie - } - typeInputList = document.getElementById("type") - typeInputList.addEventListener("change", function() { - if (typeInputList.value == "Kid") { - passwordAccountCreator = document.getElementsByClassName("passwordAccountCreator")[0] - passwordAccountCreator.style.display = "none" - } else { - passwordAccountCreator = document.getElementsByClassName("passwordAccountCreator")[0] - passwordAccountCreator.style.display = "block" - } - }) - - let allowDownloadDiv = document.getElementById("allowDownloadsDiv") - let allowDownloadCheckbox = document.getElementById("allowDownloadsCheckbox") - allowDownloadValue = allowDownloadDiv.getAttribute("data-value") - if (allowDownloadValue == "true") { - allowDownloadCheckbox.checked = true - } else { - allowDownloadCheckbox.checked = false - } - - setLibraryMenu() -} - -var crossPopup = document.getElementById("crossPopup") -crossPopup.addEventListener("click", function() { - closePopup() -}) - -var allRadios = document.getElementsByName('libType'); -for (var i = 0; i < allRadios.length; i++) { - allRadios[i].addEventListener('change', function() { - var id = this.id; - var theLabel = document.querySelector('label[for="' + id + '"]'); - var theIonIcon = theLabel.querySelector('ion-icon'); - theIonIcon.classList.add('selected'); - otherRadios = document.getElementsByName('libType'); - for (var j = 0; j < otherRadios.length; j++) { - var otherId = otherRadios[j].id; - if (otherId !== id) { - var otherLabel = document.querySelector('label[for="' + otherId + '"]'); - var otherIonIcon = otherLabel.querySelector('ion-icon'); - otherIonIcon.classList.remove('selected'); - }} - - if (id == "tv") { - pathLabel = document.querySelector('#popupLibrary > div.settingsLibrary > div.libraryPath > label') - pathLabel.innerHTML = "M3U Path:" - - libraryPathInput = document.querySelector('#popupLibrary > div.settingsLibrary > div.libraryPath > input') - libraryPathInput.placeholder = "M3U Path" - } else { - pathLabel = document.querySelector('#popupLibrary > div.settingsLibrary > div.libraryPath > label') - pathLabel.innerHTML = "Path:" - - libraryPathInput = document.querySelector('#popupLibrary > div.settingsLibrary > div.libraryPath > input') - libraryPathInput.placeholder = "Library path" - } - }); -} - - -function setLibraryMenu() { - const libraryName = document.getElementById("libraryName") - libraryName.addEventListener("change", function() { - if (libraryName.value === "") { - const errorMessagesText = document.createElement("p") - errorMessagesText.classList.add("errorMessagesText") - errorMessagesText.innerHTML = "Please enter a library name !" - libraryNameDiv = document.getElementsByClassName("libraryName")[0] - libraryNameDiv.appendChild(errorMessagesText) - } else { - const errorMessages = document.getElementsByClassName("errorMessages")[0] - errorMessages.remove() - } - }) -} - -function newLib(){ - let libType - var allRadios = document.getElementsByName('libType'); - for (var i = 0; i < allRadios.length; i++) { - if (allRadios[i].checked) { - libType = allRadios[i].getAttribute("libType") - } - } - const libName = document.getElementById("libraryName").value - const libPath = document.getElementById("libraryPath").value - const libUsers = document.getElementsByClassName("settingsCheckbox") - let defaultUsers = "" - for (let i = 0; i < libUsers.length; i++) { - if (libUsers[i].checked) { - defaultUsers += ","+libUsers[i].getAttribute("username") - } - } - - if (defaultUsers.startsWith(",")) { - defaultUsers = defaultUsers.substring(1) - } - - if (libName === "") { - alert("Please enter a library name !") - } - if (libPath === "") { - alert("Please enter a library path !") - } - - - if (libName !== "" && libPath !== "") { - fetch("/createLib", { - method: "POST", - headers: {'Content-Type': 'application/json'}, - body: JSON.stringify({ - libName: libName, - libPath: libPath, - libType: libType, - libUsers: defaultUsers - }) - }).then(res => { - let routeStatus = res.status - - if (routeStatus == 200) { - location.reload() - } else { - alert("The library already exists !\nPlease choose another name.") - } - }) - } -} - -function rescanAll() { - url = "/rescanAll" - button = document.getElementById("rescanAllButton") - texts = ["Scanning", "Scanning.", "Scanning..", "Scanning..."] - button.disabled = true - - //setInterval - var i = 0 - var interval = setInterval(function() { - i++ - if (i == 4) { - i = 0 - } - button.innerHTML = `${texts[i]}` - }, 500) - - //fetch with get - fetch(url, { - method: "GET", - headers: { - "Content-Type": "application/json" - }}).then(function(response) { - return response.json() - }).then(function(data) { - console.log(data) - if (data == true) { - clearInterval(interval) - button.innerHTML = 'Done' - } else { - clearInterval(interval) - button.innerHTML = 'Error' - button.classList.add("error") - } - }) -} \ No newline at end of file diff --git a/src/static/js/tv.js b/src/static/js/tv.js deleted file mode 100644 index ddc688b..0000000 --- a/src/static/js/tv.js +++ /dev/null @@ -1,71 +0,0 @@ -function main() { - url = window.location.href - library = url.split("/")[4] - fetch(`/getChannels/${library}`).then(function(response) { - return response.json(); - }).then(function(channels) { - for (channel of channels) { - let channelRealName = encode_utf8(channel.name).replace(/\(.*?\)|\[.*?\]/g, "") - let channelID = channel.channelID - - let channelDiv = document.createElement("div") - channelDiv.className = "channelDiv" - let channelImage = document.createElement("img") - channelImage.className = "channelImage" - channelImage.src = channel.logo - channelImage.setAttribute("loading", "lazy") - let channelName = document.createElement("p") - channelName.className = "channelName" - channelName.innerHTML = channelRealName - channelDiv.appendChild(channelImage) - channelDiv.appendChild(channelName) - channelDiv.addEventListener("click", function() { - window.location.href = `/tv/${library}/${channelID}` - }) - document.getElementById("tvChannels").appendChild(channelDiv) - } - removeLoader(channels) - }) -} - - -function removeLoader(data){ - if (data.length <= 1) { - spinner = document.getElementsByClassName("spinner")[0] - backgroundSpinner = document.getElementById("loaderBackground") - spinner.style.opacity = "0" - spinner.style.display = "none" - backgroundSpinner.style.display = "none" - } else { - - const imgs = document.images - const imgsArray = Array.prototype.slice.call(document.images) - imgs.length = 32 - imgsArray.splice(36, imgsArray.length - 1) - imgsArray.splice(0, 4) - for (img of imgsArray) { - const acutalIndex = imgsArray.indexOf(img) - img = imgs.item(acutalIndex) - img.addEventListener("load", function() { - const imagesLenght = imgsArray.length - 1 - //console.log(`${acutalIndex}/${imagesLenght-4}`) - if (acutalIndex == (imagesLenght-4)) { - spinner = document.getElementsByClassName("spinner")[0] - backgroundSpinner = document.getElementById("loaderBackground") - spinner.style.opacity = "0" - spinner.style.display = "none" - backgroundSpinner.style.display = "none" - } - }) - }} -} - -function encode_utf8(s) { - try { - return decodeURIComponent(escape(s)); - } catch (e) { - return s; - } - } - -main() \ No newline at end of file