add video backend server, fix styling and more #54

Merged
quoije merged 131 commits from 2026-video.backend into prod 2025-12-22 05:42:04 -05:00
2 changed files with 53 additions and 15 deletions
Showing only changes of commit d0edfe9278 - Show all commits
+34 -7
View File
@@ -45,7 +45,12 @@ function hasAnySource({ vod_link, video_src, embed_src }) {
// Fetch movie details from OMDb API // Fetch movie details from OMDb API
async function fetchMovieDetailsFromOmdb(imdb_id) { async function fetchMovieDetailsFromOmdb(imdb_id) {
const apiKey = process.env.OMDB_API; // Replace with your actual OMDb API key const apiKey = typeof process.env.OMDB_API === "string" ? process.env.OMDB_API.trim() : "";
if (!apiKey) {
const err = new Error("OMDb n'est pas configuré (env OMDB_API manquante).");
err.code = "OMDB_NOT_CONFIGURED";
throw err;
}
const omdbUrl = `https://www.omdbapi.com/?i=${encodeURIComponent(imdb_id)}&apikey=${apiKey}`; const omdbUrl = `https://www.omdbapi.com/?i=${encodeURIComponent(imdb_id)}&apikey=${apiKey}`;
try { try {
@@ -204,7 +209,22 @@ router.post("/add", async (req, res) => {
} }
// Fetch movie details from OMDb API // Fetch movie details from OMDb API
const movieDetails = await fetchMovieDetailsFromOmdb(imdb_id); let movieDetails;
try {
movieDetails = await fetchMovieDetailsFromOmdb(imdb_id);
} catch (err) {
// If OMDb isn't configured, keep the feature usable: add with placeholders so admin can fill manually later.
if (err?.code === "OMDB_NOT_CONFIGURED") {
movieDetails = {
title: String(imdb_id || "").trim() || "Untitled",
description: "",
rating: "",
poster: ""
};
} else {
throw err;
}
}
// Proceed with adding the movie // Proceed with adding the movie
const movie = new Movie({ const movie = new Movie({
@@ -363,11 +383,18 @@ router.put("/:id", async (req, res) => {
// If refreshOmdb is true, overwrite OMDb-derived fields from the imdb_id // If refreshOmdb is true, overwrite OMDb-derived fields from the imdb_id
if (refreshOmdb) { if (refreshOmdb) {
const details = await fetchMovieDetailsFromOmdb(movie.imdb_id); try {
movie.title = details.title; const details = await fetchMovieDetailsFromOmdb(movie.imdb_id);
movie.description = details.description; movie.title = details.title;
movie.rating = details.rating; movie.description = details.description;
movie.poster = details.poster; movie.rating = details.rating;
movie.poster = details.poster;
} catch (err) {
if (err?.code === "OMDB_NOT_CONFIGURED") {
return res.status(503).json({ message: "OMDb n'est pas configuré (env OMDB_API manquante)." });
}
throw err;
}
} else { } else {
if (title !== undefined) movie.title = title; if (title !== undefined) movie.title = title;
if (description !== undefined) movie.description = description; if (description !== undefined) movie.description = description;
+19 -8
View File
@@ -11,13 +11,21 @@ const router = express.Router();
// Set password for verification // Set password for verification
const woof = process.env.DOG_NAMES ? process.env.DOG_NAMES.split(",") : []; const woof =
typeof process.env.DOG_NAMES === "string"
? process.env.DOG_NAMES.split(",").map((s) => s.trim()).filter(Boolean)
: [];
const ACTIVE_YEAR_KEY = "active_oscar_year"; const ACTIVE_YEAR_KEY = "active_oscar_year";
// Fetch movie details from OMDb API // Fetch movie details from OMDb API
async function fetchMovieDetailsFromOmdb(imdb_id) { async function fetchMovieDetailsFromOmdb(imdb_id) {
const apiKey = process.env.OMDB_API; // Replace with your actual OMDb API key const apiKey = typeof process.env.OMDB_API === "string" ? process.env.OMDB_API.trim() : "";
if (!apiKey) {
const err = new Error("OMDb n'est pas configuré (env OMDB_API manquante).");
err.code = "OMDB_NOT_CONFIGURED";
throw err;
}
const omdbUrl = `https://www.omdbapi.com/?i=${encodeURIComponent(imdb_id)}&apikey=${apiKey}`; const omdbUrl = `https://www.omdbapi.com/?i=${encodeURIComponent(imdb_id)}&apikey=${apiKey}`;
try { try {
@@ -161,7 +169,11 @@ router.get("/stats", verifyToken, async (req, res) => {
// Register User // Register User
router.post("/register", async (req, res) => { router.post("/register", async (req, res) => {
const { name, email, password, role, verifoof } = req.body; const { name, email, password, role, verifoof } = req.body;
const dogCheckEnabled = woof.length > 0;
function registerVerification() { function registerVerification() {
// If DOG_NAMES isn't configured, skip the "dog name" verification entirely.
if (!dogCheckEnabled) return true;
return woof.includes(verifoof); return woof.includes(verifoof);
} }
@@ -169,16 +181,16 @@ router.post("/register", async (req, res) => {
if (!password) { if (!password) {
throw new Error("Le mot de passe est obligatoire et ne peut être indéfini"); throw new Error("Le mot de passe est obligatoire et ne peut être indéfini");
} }
if (!verifoof) { if (dogCheckEnabled && !verifoof) {
throw new Error("Le nom du chien doit être défini" ); throw new Error("Le nom du chien doit être défini");
} }
if (!registerVerification()) { if (!registerVerification()) {
return res.status(201).json({ message: "Mauvais nom de chien" }); return res.status(400).json({ message: "Mauvais nom de chien" });
} }
const existingUser = await User.findOne({ email }); const existingUser = await User.findOne({ email });
if (existingUser) { if (existingUser) {
return res.status(201).json({ message: "L'email existe déjà, veuillez en choisir un autre." }); return res.status(409).json({ message: "L'email existe déjà, veuillez en choisir un autre." });
} }
// Hash password and create user // Hash password and create user
@@ -188,8 +200,7 @@ router.post("/register", async (req, res) => {
res.status(201).json({ message: "L'utilisateur s'est enregistré avec succès !" }); res.status(201).json({ message: "L'utilisateur s'est enregistré avec succès !" });
} catch (err) { } catch (err) {
res.status(400).json({ error: err.message }); return res.status(400).json({ message: err?.message || "Erreur interne" });
res.status(403).json({ message: "Erreur interne lmao" });
} }
}); });