From 5c4366a9e7ed2849322d840a246f91fce9248724 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 20 Dec 2025 21:30:09 +0000 Subject: [PATCH 1/2] Add timestamps to Movie model Co-authored-by: mathieumoran1 --- models/Movie.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/Movie.js b/models/Movie.js index 010246d..9a81bdf 100644 --- a/models/Movie.js +++ b/models/Movie.js @@ -9,6 +9,6 @@ const movieSchema = new mongoose.Schema({ category: { type: String, required: true }, vod_link: { type: String, required: true }, watchedBy: [{ type: mongoose.Schema.Types.ObjectId, ref: 'User' }] -}); +}, { timestamps: true }); module.exports = mongoose.model("Movie", movieSchema); From 0d35a19cc51cb7943d1e0bd2c35cb65125e93f8e Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 20 Dec 2025 21:31:35 +0000 Subject: [PATCH 2/2] Add endpoint to get last movie update timestamp Co-authored-by: mathieumoran1 --- public/movies.html | 2 +- routes/movies.js | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/public/movies.html b/public/movies.html index 67e429b..fb1ec57 100644 --- a/public/movies.html +++ b/public/movies.html @@ -98,7 +98,7 @@ diff --git a/routes/movies.js b/routes/movies.js index a07501e..1794197 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -38,6 +38,33 @@ router.get("/", async (req, res) => { } }); +// Get latest movie update/add timestamp +router.get("/last-update", async (req, res) => { + const token = req.headers.authorization?.split(" ")[1]; + if (!token) return res.status(401).json({ message: "Token is required" }); + + try { + jwt.verify(token, process.env.JWT_SECRET); + + const latestMovie = await Movie.findOne().sort({ updatedAt: -1, createdAt: -1, _id: -1 }); + if (!latestMovie) { + return res.status(200).json({ lastUpdated: null }); + } + + const lastUpdated = + latestMovie.updatedAt || + latestMovie.createdAt || + (typeof latestMovie._id?.getTimestamp === "function" ? latestMovie._id.getTimestamp() : null); + + return res.status(200).json({ lastUpdated: lastUpdated ? new Date(lastUpdated).toISOString() : null }); + } catch (error) { + if (error instanceof jwt.JsonWebTokenError) { + return res.status(401).json({ message: "Invalid or expired token" }); + } + return res.status(500).json({ error: error.message }); + } +}); + // Get watched movies for the user router.get("/watchedMovies", async (req, res) => { const token = req.headers.authorization?.split(" ")[1]; // Get token from header