diff --git a/index.js b/index.js index 6a82d19..f0a5f43 100644 --- a/index.js +++ b/index.js @@ -19,10 +19,12 @@ mongoose // Routes const userRoutes = require("./routes/users"); const movieRoutes = require("./routes/movies"); +const versionRoutes = require("./routes/version"); app.use(express.static('public')); app.use("/api/users", userRoutes); app.use("/api/movies", movieRoutes); +app.use("/api/version", versionRoutes); // Start Server const PORT = process.env.PORT || 5000; diff --git a/public/checklist.html b/public/checklist.html index 927aa1c..9099866 100644 --- a/public/checklist.html +++ b/public/checklist.html @@ -119,203 +119,7 @@ - - const targetDate = new Date('March 2, 2025'); - const currentDate = new Date(); - const timeDifference = targetDate - currentDate; - const daysLeft = Math.floor(timeDifference / (1000 * 60 * 60 * 24)); - document.getElementById('time-left').textContent = `${daysLeft} jours`; - - if (token) { - try { - const decoded = JSON.parse(atob(token.split('.')[1])); - const userName = decoded.name; - document.getElementById('user-name').textContent = userName; - const currentTime = Math.floor(Date.now() / 1000); - if (decoded.exp && decoded.exp < currentTime) { - localStorage.removeItem('auth_token'); - window.location.href = '/'; - } - } catch (error) { - localStorage.removeItem('auth_token'); - window.location.href = '/'; - } - } else { - window.location.href = '/'; - } - - const res = await fetch('/api/movies', { - method: 'GET', - headers: { 'Authorization': `Bearer ${token}` } - }); - - if (!res.ok) { - localStorage.removeItem('auth_token'); - window.location.href = '/'; - return; - } - - const movies = await res.json(); - - // Sort movies alphabetically by title - movies.sort((a, b) => a.title.localeCompare(b.title, 'fr', { sensitivity: 'base' })); - - const watchedRes = await fetch('/api/movies/watchedMovies', { - method: 'GET', - headers: { 'Authorization': `Bearer ${token}` } - }); - - let watchedMovies = []; - if (watchedRes.ok) { - watchedMovies = await watchedRes.json(); - } - - const totalMoviesCount = movies.length; - const watchedMoviesCount = watchedMovies.length; - document.getElementById('watched-ratio').innerText = `Vu: ${watchedMoviesCount} / ${totalMoviesCount} (${((watchedMoviesCount / totalMoviesCount) * 100).toFixed(1)}%)`; - - function launchConfetti() { - const duration = 3 * 1000; // 3 seconds - const animationEnd = Date.now() + duration; - const colors = ['#bb0000', '#ffffff', '#FFD700']; - - function frame() { - const timeLeft = animationEnd - Date.now(); - if (timeLeft <= 0) return; - confetti({ - particleCount: 5, - angle: 60, - spread: 55, - origin: { x: 0 } - }); - confetti({ - particleCount: 5, - angle: 120, - spread: 55, - origin: { x: 1 } - }); - requestAnimationFrame(frame); - } - frame(); - } - - function updateProgressBar(watchedCount, totalCount) { - const progressBar = document.getElementById('progress-bar'); - const percentage = (watchedCount / totalCount) * 100; - console.log(percentage); - progressBar.style.width = `${percentage}%`; - - if (percentage <= 50) { - progressBar.style.backgroundColor = `rgb(${255}, ${Math.floor((percentage / 50) * 255)}, 0)`; - } else { - progressBar.style.backgroundColor = `rgb(${Math.floor(255 - ((percentage - 50) / 50) * 255)}, 255, 0)`; - } - - progressBar.setAttribute('aria-valuenow', Math.round(percentage)); - - const videoModal = new bootstrap.Modal(document.getElementById("videoModal")); - - if (percentage === 100) { - videoModal.show(); - launchConfetti(); - document.getElementById("rewardVideo").play(); - } - } - - updateProgressBar(watchedMoviesCount, totalMoviesCount); - - const movieTableBody = document.getElementById('movie-table-body'); - movies.forEach(movie => { - const watchedMovie = watchedMovies.find(wm => wm.imdb_id === movie.imdb_id); - const watchedDate = watchedMovie ? new Date(watchedMovie.watchedDate).toLocaleString() : ''; - const movieRow = document.createElement('tr'); - movieRow.innerHTML = ` -