diff --git a/backend/app/controllers/channel.controller.js b/backend/app/controllers/channel.controller.js index 046f7c0..e10941e 100644 --- a/backend/app/controllers/channel.controller.js +++ b/backend/app/controllers/channel.controller.js @@ -236,7 +236,7 @@ export async function getStats(req, res) { client.release(); res.status(200).json(result.rows[0]); } catch (error) { - console.log(error); + res.status(500).json({error: error.message}); } diff --git a/backend/app/controllers/media.controller.js b/backend/app/controllers/media.controller.js index ae047aa..33aa8bc 100644 --- a/backend/app/controllers/media.controller.js +++ b/backend/app/controllers/media.controller.js @@ -15,12 +15,13 @@ export async function getProfilePicture(req, res) { path.join('/app/uploads/profiles', file) ]; - console.log('Possible paths:', possiblePaths); - console.log('Current working directory:', process.cwd()); - console.log('__dirname:', __dirname); + + + // Try the most likely path first (based on your volume mapping) - const filePath = path.join(__dirname, '../../uploads/profiles', file); + console.log(path.join(__dirname, '../uploads/profiles', file)) + const filePath = path.join(__dirname, '../uploads/profiles', file); try { res.sendFile(filePath, (err) => { @@ -28,7 +29,7 @@ export async function getProfilePicture(req, res) { console.error("Error sending profile picture:", err); res.status(404).json({ error: "Profile picture not found." }); } else { - console.log("Profile picture sent successfully."); + } }); } catch (error) { @@ -47,7 +48,7 @@ export async function getThumbnail(req, res) { console.error("Error sending thumbnail:", err); res.status(404).json({ error: "Thumbnail not found." }); } else { - console.log("Thumbnail sent successfully."); + } }); } catch (error) { @@ -65,7 +66,7 @@ export async function getVideo(req, res) { if (err) { console.error("Error sending video:", err); } else { - console.log("Video sent successfully."); + } }); } catch (error) { diff --git a/backend/app/controllers/oauth.controller.js b/backend/app/controllers/oauth.controller.js index 36bdaa9..742d3c1 100644 --- a/backend/app/controllers/oauth.controller.js +++ b/backend/app/controllers/oauth.controller.js @@ -26,7 +26,7 @@ export async function callback(req, res, next) { const avatarUrl = user.photos && user.photos[0] ? user.photos[0].value : null; const displayName = user.displayName || username; - console.log(user); + console.log("GitHub user info:", { githubId, diff --git a/backend/app/controllers/search.controller.js b/backend/app/controllers/search.controller.js index 9b3a947..5de99fb 100644 --- a/backend/app/controllers/search.controller.js +++ b/backend/app/controllers/search.controller.js @@ -2,7 +2,7 @@ import {getClient} from "../utils/database.js"; export async function search(req, res) { try { - console.log(req.query); + const query = req.query.q; const type = req.query.type || 'all'; const offset = parseInt(req.query.offset) || 0; diff --git a/backend/app/controllers/user.controller.js b/backend/app/controllers/user.controller.js index 79e30ad..7bf317a 100644 --- a/backend/app/controllers/user.controller.js +++ b/backend/app/controllers/user.controller.js @@ -111,7 +111,7 @@ export async function register(req, res) { `; - console.log("Sending email to:", user.email); + await sendEmail(user.email, "🎬 Bienvenue sur Freetube - VĂ©rifiez votre email", textMessage, htmlMessage); @@ -122,11 +122,11 @@ export async function register(req, res) { const insertQuery = `INSERT INTO email_verification (email, token, expires_at) VALUES ($1, $2, $3)`; await client.query(insertQuery, [user.email, token, expirationDate]); - console.log("Successfully registered"); + logger.write("successfully registered", 200); res.status(200).send({ user: user }); } catch (err) { - console.log(err); + logger?.write("failed to register user", 500); res.status(500).json({ error: "Internal server error" }); } finally { @@ -217,7 +217,7 @@ export async function login(req, res) { logger.write("Successfully logged in", 200); res.status(200).json({ token: token, user: userData }); } catch (err) { - console.log(err); + logger?.write("failed to login", 500); res.status(500).json({ error: "Internal server error" }); } finally { @@ -317,7 +317,7 @@ export async function update(req, res) { let __filename = fileURLToPath(import.meta.url); let __dirname = dirname(__filename); - console.log(__dirname); + let profilePicture = userInBase.picture.split("/").pop(); fs.rename( @@ -338,7 +338,7 @@ export async function update(req, res) { client.release(); res.status(200).json(result.rows[0]); } catch (err) { - console.log(err); + client.release() res.status(500).json({ error: err }); } diff --git a/backend/app/controllers/video.controller.js b/backend/app/controllers/video.controller.js index 2c134d8..3d56644 100644 --- a/backend/app/controllers/video.controller.js +++ b/backend/app/controllers/video.controller.js @@ -74,7 +74,7 @@ export async function upload(req, res) { if (Array.isArray(authorizedUsers) && authorizedUsers.length > 0) { for (let i = 0; i < authorizedUsers.length; i++) { const user = authorizedUsers[i]; - console.log("authorized user", user); + const query = `INSERT INTO video_authorized_users (video_id, user_id) VALUES ($1, $2)`; // SEND EMAIL TO AUTHORIZED USER @@ -565,7 +565,7 @@ export async function getLikesPerDay(req, res) { const resultLikes = await client.query(likeQuery, [id]); response.likes = resultLikes.rows; - console.log(response); + logger.write("successfully retrieved likes per day", 200); res.status(200).json(response); @@ -607,14 +607,14 @@ export async function updateAuthorizedUsers(req, res) { const { authorizedUsers } = req.body; - console.log(authorizedUsers); + const client = await getClient(); try { // Remove all existing authorized users const deleteQuery = `DELETE FROM video_authorized_users WHERE video_id = $1`; - console.log(`DELETE FROM video_authorized_users WHERE video_id = ${id}`); + await client.query(deleteQuery, [id]); // Add new authorized users diff --git a/backend/app/middlewares/error.middleware.js b/backend/app/middlewares/error.middleware.js index 5a45084..f7e717b 100644 --- a/backend/app/middlewares/error.middleware.js +++ b/backend/app/middlewares/error.middleware.js @@ -6,7 +6,7 @@ export default async function validator(req, res, next) { if (!errors.isEmpty()) { const logger = req.body.logger; logger.write("failed due to invalid values", 400); - console.log(req.body); + return res.status(400).json({ errors: errors.array() }); } else { next() diff --git a/backend/app/middlewares/video.middleware.js b/backend/app/middlewares/video.middleware.js index 120956e..2f17c99 100644 --- a/backend/app/middlewares/video.middleware.js +++ b/backend/app/middlewares/video.middleware.js @@ -150,7 +150,7 @@ export async function hasAccess(req, res, next) { const videoResult = await client.query(videoQuery, [videoId]); const video = videoResult.rows[0]; - console.log(video); + if (video.visibility === 'private') { const token = req.headers.authorization?.split(" ")[1]; diff --git a/backend/app/uploads/profiles/astri6.jpg b/backend/app/uploads/profiles/astri6.jpg deleted file mode 100644 index 1dad29c..0000000 Binary files a/backend/app/uploads/profiles/astri6.jpg and /dev/null differ diff --git a/backend/app/uploads/profiles/astri7.jpg b/backend/app/uploads/profiles/astri7.jpg deleted file mode 100644 index 1dad29c..0000000 Binary files a/backend/app/uploads/profiles/astri7.jpg and /dev/null differ diff --git a/backend/app/uploads/profiles/astria.png b/backend/app/uploads/profiles/astria.png deleted file mode 100644 index f1a0670..0000000 Binary files a/backend/app/uploads/profiles/astria.png and /dev/null differ diff --git a/backend/app/uploads/profiles/astria2.jpg b/backend/app/uploads/profiles/astria2.jpg deleted file mode 100644 index d49bc22..0000000 Binary files a/backend/app/uploads/profiles/astria2.jpg and /dev/null differ diff --git a/backend/app/uploads/profiles/astria3.jpg b/backend/app/uploads/profiles/astria3.jpg deleted file mode 100644 index d49bc22..0000000 Binary files a/backend/app/uploads/profiles/astria3.jpg and /dev/null differ diff --git a/backend/app/uploads/profiles/default.png b/backend/app/uploads/profiles/default.png deleted file mode 100644 index 7a8a843..0000000 Binary files a/backend/app/uploads/profiles/default.png and /dev/null differ diff --git a/backend/app/utils/database.js b/backend/app/utils/database.js index 35260bf..417bf94 100644 --- a/backend/app/utils/database.js +++ b/backend/app/utils/database.js @@ -22,7 +22,7 @@ export async function getClient() { // Graceful shutdown process.on('SIGINT', () => { pool.end(() => { - console.log('Pool has ended'); + process.exit(0); }); }); @@ -151,7 +151,7 @@ export async function initDb() { await client.query(`ALTER TABLE users ALTER COLUMN email DROP NOT NULL`); await client.query(`ALTER TABLE users ALTER COLUMN password DROP NOT NULL`); } catch (e) { - console.log("OAuth columns already exist or error adding them:", e.message); + } } catch (e) { diff --git a/backend/logs/access.log b/backend/logs/access.log index 1ea8d58..0294c29 100644 --- a/backend/logs/access.log +++ b/backend/logs/access.log @@ -12162,3 +12162,75 @@ [2025-09-06 10:23:54.352] [undefined] GET(/:id): Successfully get channel with id 2 with status 200 [2025-09-06 10:23:54.364] [undefined] GET(/:id/channel/subscribed): check if user 1 is subscribed to channel 2 [2025-09-06 10:23:54.370] [undefined] GET(/:id/channel/subscribed): user 1 is not subscribed to channel 2 with status 200 +[2025-09-08 16:38:02.990] [undefined] POST(/): failed because email already exists with status 400 +[2025-09-08 16:38:11.467] [undefined] POST(/): failed because email already exists with status 400 +[2025-09-08 16:38:28.340] [undefined] POST(/): failed because email already exists with status 400 +[2025-09-08 16:39:29.271] [undefined] POST(/): try to register a user with username: astria and email: sachaguerin.sg@gmail.com +[2025-09-08 16:39:31.245] [undefined] POST(/): successfully registered with status 200 +[2025-09-08 16:39:43.524] [undefined] POST(/verify-email): try to verify email for sachaguerin.sg@gmail.com with token 86155 +[2025-09-08 16:39:43.543] [undefined] POST(/verify-email): successfully verified email for sachaguerin.sg@gmail.com with status 200 +[2025-09-08 16:39:50.092] [undefined] POST(/login): try to login with username 'astria' +[2025-09-08 16:39:50.164] [undefined] POST(/login): Successfully logged in with status 200 +[2025-09-08 16:39:50.339] [undefined] GET(/see-later): 'See Later' playlist retrieved for user with id 1 with status 200 +[2025-09-08 16:39:53.065] [undefined] GET(/:id/history): try to retrieve history of user 1 +[2025-09-08 16:39:53.069] [undefined] GET(/:id/channel): try to retrieve channel of user 1 +[2025-09-08 16:39:53.077] [undefined] GET(/:id/history): failed to retrieve history of user 1 because it doesn't exist with status 404 +[2025-09-08 16:39:53.084] [undefined] GET(/:id/channel): failed to retrieve channel of user 1 because it doesn't exist with status 404 +[2025-09-08 16:39:53.095] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200 +[2025-09-08 16:43:38.736] [undefined] POST(/): try to register a user with username: sacha and email: thelolshow974@gmail.com +[2025-09-08 16:43:40.388] [undefined] POST(/): successfully registered with status 200 +[2025-09-08 16:43:55.477] [undefined] POST(/verify-email): try to verify email for thelolshow974@gmail.com with token dd574 +[2025-09-08 16:43:55.494] [undefined] POST(/verify-email): successfully verified email for thelolshow974@gmail.com with status 200 +[2025-09-08 16:44:02.186] [undefined] POST(/login): try to login with username 'sacha' +[2025-09-08 16:44:02.255] [undefined] POST(/login): Successfully logged in with status 200 +[2025-09-08 16:44:02.388] [undefined] GET(/see-later): 'See Later' playlist retrieved for user with id 2 with status 200 +[2025-09-08 16:44:04.504] [undefined] GET(/:id/channel): try to retrieve channel of user 2 +[2025-09-08 16:44:04.508] [undefined] GET(/:id/channel): failed to retrieve channel of user 2 because it doesn't exist with status 404 +[2025-09-08 16:44:04.517] [undefined] GET(/:id/history): try to retrieve history of user 2 +[2025-09-08 16:44:04.523] [undefined] GET(/:id/history): failed to retrieve history of user 2 because it doesn't exist with status 404 +[2025-09-08 16:44:04.537] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200 +[2025-09-08 16:45:13.811] [undefined] GET(/:id/channel): try to retrieve channel of user 2 +[2025-09-08 16:45:13.816] [undefined] GET(/:id/channel): failed to retrieve channel of user 2 because it doesn't exist with status 404 +[2025-09-08 16:45:13.824] [undefined] GET(/:id/history): try to retrieve history of user 2 +[2025-09-08 16:45:13.829] [undefined] GET(/:id/history): failed to retrieve history of user 2 because it doesn't exist with status 404 +[2025-09-08 16:45:13.838] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200 +[2025-09-08 16:46:03.637] [undefined] GET(/:id/channel): try to retrieve channel of user 2 +[2025-09-08 16:46:03.643] [undefined] GET(/:id/channel): failed to retrieve channel of user 2 because it doesn't exist with status 404 +[2025-09-08 16:46:03.650] [undefined] GET(/:id/history): try to retrieve history of user 2 +[2025-09-08 16:46:03.656] [undefined] GET(/:id/history): failed to retrieve history of user 2 because it doesn't exist with status 404 +[2025-09-08 16:46:03.666] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200 +[2025-09-08 16:46:17.413] [undefined] GET(/:id/history): try to retrieve history of user 2 +[2025-09-08 16:46:17.417] [undefined] GET(/:id/channel): try to retrieve channel of user 2 +[2025-09-08 16:46:17.426] [undefined] GET(/:id/channel): failed to retrieve channel of user 2 because it doesn't exist with status 404 +[2025-09-08 16:46:17.431] [undefined] GET(/:id/history): failed to retrieve history of user 2 because it doesn't exist with status 404 +[2025-09-08 16:46:17.442] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200 +[2025-09-08 16:46:35.561] [undefined] GET(/:id/channel): try to retrieve channel of user 2 +[2025-09-08 16:46:35.567] [undefined] GET(/:id/channel): failed to retrieve channel of user 2 because it doesn't exist with status 404 +[2025-09-08 16:46:35.576] [undefined] GET(/:id/history): try to retrieve history of user 2 +[2025-09-08 16:46:35.583] [undefined] GET(/:id/history): failed to retrieve history of user 2 because it doesn't exist with status 404 +[2025-09-08 16:46:35.595] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200 +[2025-09-08 16:47:27.440] [undefined] GET(/:id/channel): try to retrieve channel of user 2 +[2025-09-08 16:47:27.445] [undefined] GET(/:id/channel): failed to retrieve channel of user 2 because it doesn't exist with status 404 +[2025-09-08 16:47:27.454] [undefined] GET(/:id/history): try to retrieve history of user 2 +[2025-09-08 16:47:27.459] [undefined] GET(/:id/history): failed to retrieve history of user 2 because it doesn't exist with status 404 +[2025-09-08 16:47:27.469] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200 +[2025-09-08 16:47:49.574] [undefined] POST(/login): try to login with username 'sacha' +[2025-09-08 16:47:49.634] [undefined] POST(/login): Successfully logged in with status 200 +[2025-09-08 16:47:49.727] [undefined] GET(/see-later): 'See Later' playlist retrieved for user with id 2 with status 200 +[2025-09-08 16:47:51.469] [undefined] GET(/:id/channel): try to retrieve channel of user 2 +[2025-09-08 16:47:51.474] [undefined] GET(/:id/channel): failed to retrieve channel of user 2 because it doesn't exist with status 404 +[2025-09-08 16:47:51.482] [undefined] GET(/:id/history): try to retrieve history of user 2 +[2025-09-08 16:47:51.492] [undefined] GET(/:id/history): failed to retrieve history of user 2 because it doesn't exist with status 404 +[2025-09-08 16:47:51.503] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200 +[2025-09-08 16:48:31.139] [undefined] GET(/:id/channel): try to retrieve channel of user 2 +[2025-09-08 16:48:31.145] [undefined] GET(/:id/channel): failed to retrieve channel of user 2 because it doesn't exist with status 404 +[2025-09-08 16:48:31.153] [undefined] GET(/:id/history): try to retrieve history of user 2 +[2025-09-08 16:48:31.160] [undefined] GET(/user/:id): failed because user doesn't exists with status 404 +[2025-09-08 16:48:31.165] [undefined] GET(/:id/history): failed to retrieve history of user 2 because it doesn't exist with status 404 +[2025-09-08 16:49:08.966] [undefined] POST(/): try to register a user with username: astria and email: sachaguerin.sg@gmail.com +[2025-09-08 16:49:10.628] [undefined] POST(/): successfully registered with status 200 +[2025-09-08 16:49:20.080] [undefined] POST(/verify-email): try to verify email for sachaguerin.sg@gmail.com with token fe65c +[2025-09-08 16:49:20.097] [undefined] POST(/verify-email): successfully verified email for sachaguerin.sg@gmail.com with status 200 +[2025-09-08 16:49:30.515] [undefined] POST(/login): try to login with username 'astria' +[2025-09-08 16:49:30.577] [undefined] POST(/login): Successfully logged in with status 200 +[2025-09-08 16:49:30.682] [undefined] GET(/see-later): 'See Later' playlist retrieved for user with id 1 with status 200 diff --git a/backend/server.js b/backend/server.js index b01631f..c6b9728 100644 --- a/backend/server.js +++ b/backend/server.js @@ -22,7 +22,7 @@ import { Strategy as GitHubStrategy } from "passport-github2"; console.clear(); dotenv.config(); -console.log(process.env) + const app = express(); @@ -96,10 +96,11 @@ const port = process.env.BACKEND_PORT; if (process.env.NODE_ENV !== "test") { const server = http.createServer(app); server.listen(port, '0.0.0.0', async () => { - console.log("Server's listening on port " + port); - console.log("Initializing database..."); + + console.log(`Server started on port ${port}`); await initDb(); console.log("Database initialized successfully."); + }); } diff --git a/backend/test/playlist.test.js b/backend/test/playlist.test.js index 0c9a347..a5ac3e7 100644 --- a/backend/test/playlist.test.js +++ b/backend/test/playlist.test.js @@ -53,7 +53,7 @@ describe('ADD VIDEO TO PLAYLIST', () => { it("Should return 404 if playlist does not exist", async () => { const req = await request(app).post(`/api/playlists/${falseplaylistId}`).set("Authorization", `Bearer ${token}`).send({ video: videoId }); - console.log(req.body); + expect(req.statusCode).toBe(404); }) diff --git a/backend/tools.js b/backend/tools.js index bea73a3..d4389b9 100644 --- a/backend/tools.js +++ b/backend/tools.js @@ -1,6 +1,6 @@ import pg from "pg"; -console.log(process.argv[2]); + if (process.argv[2] === "flush") { @@ -20,7 +20,7 @@ async function flushDatabase() { try { await client.connect(); await client.query('TRUNCATE TABLE users CASCADE'); - console.log('Database flushed successfully.'); + } catch (err) { console.error('Error flushing database:', err); } finally { diff --git a/developpement.yaml b/developpement.yaml index 35ed232..dbf6e8f 100644 --- a/developpement.yaml +++ b/developpement.yaml @@ -15,7 +15,7 @@ services: POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} JWT_SECRET: ${JWT_SECRET} LOG_FILE: ${LOG_FILE} - PORT: ${BACKEND_PORT} + BACKEND_PORT: ${BACKEND_PORT} GMAIL_USER: ${GMAIL_USER} GMAIL_PASSWORD: ${GMAIL_PASSWORD} GITHUB_ID: ${GITHUB_ID} diff --git a/docker-compose.yaml b/docker-compose.yaml index 9a54746..f281c99 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -15,7 +15,7 @@ services: POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} JWT_SECRET: ${JWT_SECRET} LOG_FILE: ${LOG_FILE} - PORT: ${BACKEND_PORT} + BACKEND_PORT: ${BACKEND_PORT} GMAIL_USER: ${GMAIL_USER} GMAIL_PASSWORD: ${GMAIL_PASSWORD} GITHUB_ID: ${GITHUB_ID} @@ -23,7 +23,7 @@ services: FRONTEND_URL: ${FRONTEND_URL} volumes: - ./backend/logs:/var/log/freetube - - upload:/app/backend/app/uploads + - ./uploads:/app/app/uploads/ depends_on: db: condition: service_healthy diff --git a/frontend/src/components/CreatorCard.jsx b/frontend/src/components/CreatorCard.jsx index bdb0a06..04f7733 100644 --- a/frontend/src/components/CreatorCard.jsx +++ b/frontend/src/components/CreatorCard.jsx @@ -5,7 +5,7 @@ export default function CreatorCard({ creator }) { window.location.href = `/channel/${creator.channel_id}`; }; - console.log(creator); + return (
diff --git a/frontend/src/components/Recommendations.jsx b/frontend/src/components/Recommendations.jsx index d59b791..2491063 100644 --- a/frontend/src/components/Recommendations.jsx +++ b/frontend/src/components/Recommendations.jsx @@ -1,7 +1,7 @@ import VideoCard from "./VideoCard"; export default function Recommendations({videos}) { - console.log(videos); + return (

Recommandations

diff --git a/frontend/src/modals/CreateChannelModal.jsx b/frontend/src/modals/CreateChannelModal.jsx index 8c2019e..45300e6 100644 --- a/frontend/src/modals/CreateChannelModal.jsx +++ b/frontend/src/modals/CreateChannelModal.jsx @@ -22,7 +22,7 @@ export default function CreateChannelModal({isOpen, onClose, addAlert}) { const data = await createChannel(body, token, addAlert); - console.log(data); + onClose(); } diff --git a/frontend/src/modals/EmailVerificationModal.jsx b/frontend/src/modals/EmailVerificationModal.jsx index e2f78e1..d943628 100644 --- a/frontend/src/modals/EmailVerificationModal.jsx +++ b/frontend/src/modals/EmailVerificationModal.jsx @@ -17,7 +17,7 @@ export default function EmailVerificationModal({ isOpen, onSubmit, onClose }) { onChange={(e) => setVerificationCode(e.target.value)} />
diff --git a/frontend/src/pages/AddVideo.jsx b/frontend/src/pages/AddVideo.jsx index 511d06e..f5364e1 100644 --- a/frontend/src/pages/AddVideo.jsx +++ b/frontend/src/pages/AddVideo.jsx @@ -35,7 +35,7 @@ export default function AddVideo() { const fetchChannel = async () => { const fetchedChannel = await getChannel(user.id, token, addAlert); setChannel(fetchedChannel.channel); - console.log(fetchedChannel.channel); + } const handleTagKeyDown = (e) => { @@ -123,7 +123,7 @@ export default function AddVideo() { // Call the API to search for users searchByUsername(searchUser, token, addAlert) .then((results) => { - console.log(results); + setSearchResults(results); }) .catch((error) => { diff --git a/frontend/src/pages/LoginSuccess.jsx b/frontend/src/pages/LoginSuccess.jsx index a70848a..065e6d0 100644 --- a/frontend/src/pages/LoginSuccess.jsx +++ b/frontend/src/pages/LoginSuccess.jsx @@ -15,14 +15,14 @@ export default function LoginSuccess() { const token = searchParams.get('token'); const userParam = searchParams.get('user'); - console.log('Processing OAuth callback:', { token: !!token, userParam: !!userParam }); + if (token && userParam) { try { hasProcessed.current = true; const userData = JSON.parse(decodeURIComponent(userParam)); - console.log('Parsed user data:', userData); + // Use the OAuth login method to update auth context loginWithOAuth(userData, token); @@ -40,7 +40,7 @@ export default function LoginSuccess() { }, 100); } } else { - console.log('Missing token or user data'); + hasProcessed.current = true; setTimeout(() => { navigate('/login?error=missing_data', { replace: true }); diff --git a/frontend/src/pages/ManageVideo.jsx b/frontend/src/pages/ManageVideo.jsx index 24479ca..bb4ef75 100644 --- a/frontend/src/pages/ManageVideo.jsx +++ b/frontend/src/pages/ManageVideo.jsx @@ -173,7 +173,7 @@ export default function ManageVideo() { channel: video.channel }; - console.log("Sending to API:", body); // Debug log + // Debug log const request = await updateAuthorizedUsers(id, body, token, addAlert); @@ -188,7 +188,7 @@ export default function ManageVideo() { } const onRemoveAuthorizedUser = async (user) => { - console.log("Êtes-vous sĂ»r de vouloir supprimer cet utilisateur autorisĂ© ?", user.id); + const body = { authorizedUsers: video.authorizedUsers.filter(u => u.id !== user.id), channel: video.channel diff --git a/frontend/src/pages/Register.jsx b/frontend/src/pages/Register.jsx index 8b1ae64..9a230f7 100644 --- a/frontend/src/pages/Register.jsx +++ b/frontend/src/pages/Register.jsx @@ -77,7 +77,7 @@ export default function Register() { const onVerificationSubmit = async (token) => { - console.log("Submitting email verification with token:", token); + const response = await verifyEmail(formData.email, token, addAlert); diff --git a/frontend/src/pages/Video.jsx b/frontend/src/pages/Video.jsx index 7a4c081..860fb58 100644 --- a/frontend/src/pages/Video.jsx +++ b/frontend/src/pages/Video.jsx @@ -84,32 +84,32 @@ export default function Video() { const token = localStorage.getItem('token'); if (!token) return; - console.log("Fetching next video"); - console.log("currentPlaylist", currentPlaylist); - console.log("current video id from params:", id, "type:", typeof id); - console.log("playlist videos:", currentPlaylist?.videos?.map(v => ({ id: v.id, type: typeof v.id }))); + + + + //Find position of current video id in currentPlaylist.videos const currentIndex = currentPlaylist?.videos.findIndex(video => { - console.log(`Comparing video.id: ${video.id} (${typeof video.id}) with id: ${id} (${typeof id})`); + return video.id.toString() === id.toString(); }); - console.log("currentIndex", currentIndex); + if (currentIndex !== -1) { if (currentPlaylist?.videos[currentIndex + 1]) { setNextVideo(currentPlaylist.videos[currentIndex + 1]); - console.log("nextVideo", currentPlaylist.videos[currentIndex + 1]); + } } } const passToNextVideo = () => { if (!nextVideo) { - console.log("No next video available"); + return; } - console.log("Passing to next video:", nextVideo); + // Navigate to the next video with playlist context if (playlistId) { @@ -209,7 +209,7 @@ export default function Video() { const handlePlaying = () => { if (videoRef.current) { - console.log(`Video is playing at ${videoRef.current.currentTime} seconds`); + } } @@ -249,7 +249,7 @@ export default function Video() { const response = await subscribe(video.creator.id, addAlert); - console.log('Subscription successful:', response); + const subscriptionCount = response.subscriptions || 0; setVideo((prevVideo) => { diff --git a/frontend/src/services/channel.service.js b/frontend/src/services/channel.service.js index 1c76eb7..cfb3642 100644 --- a/frontend/src/services/channel.service.js +++ b/frontend/src/services/channel.service.js @@ -56,7 +56,7 @@ export async function updateChannel(channelId, data, token, addAlert) { export async function subscribe(channelId, addAlert) { const token = localStorage.getItem('token'); const user = JSON.parse(localStorage.getItem('user')); - console.log("Subscribing to channel with ID:", channelId, "for user:", user.id); + return fetch(`/api/channels/${channelId}/subscribe`, { method: 'POST', headers: { diff --git a/frontend/src/services/user.service.js b/frontend/src/services/user.service.js index 3ffd8c7..e71f735 100644 --- a/frontend/src/services/user.service.js +++ b/frontend/src/services/user.service.js @@ -11,7 +11,7 @@ export async function isSubscribed(channelId, addAlert) { const request = await fetch(`/api/users/${channelId}/channel/subscribed`, { headers }) const result = await request.json(); - console.log("Subscription status for channel ID", channelId, ":", result); + return result.subscribed; } @@ -140,7 +140,7 @@ export async function searchByUsername(username, token, addAlert) { }); if (!response.ok) { const errorData = await response.json().catch(() => ({})); - console.log(errorData); + throw new Error(errorData.error || "Failed to search user"); } const data = await response.json(); diff --git a/uploads/profiles/sacha.jpg b/uploads/profiles/sacha.jpg new file mode 100644 index 0000000..240e539 Binary files /dev/null and b/uploads/profiles/sacha.jpg differ