From e4f65f8b0a9f8224b7f31720e6a05b709804ba40 Mon Sep 17 00:00:00 2001 From: Afsha10 Date: Wed, 1 Nov 2023 11:02:11 +0000 Subject: [PATCH] Clear console.log, add meaningful comment and variable name --- server/server.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/server.js b/server/server.js index 63de6db37b..be0466418b 100644 --- a/server/server.js +++ b/server/server.js @@ -79,9 +79,7 @@ app.post("/videos", (req, res) => { !url.startsWith("https://m.youtube.com") && !url.startsWith("https://youtube.com/")) ) { - console.log({ url }); - // https://youtu.be/n3JNtfi4Vb0?si=dRx5CJJctB6P_yVR - // https://www.youtube.com/watch?v=n3JNtfi4Vb0 + res.status(400).json({ result: "failure", message: "Video could not be saved", @@ -90,11 +88,13 @@ app.post("/videos", (req, res) => { const query = `INSERT INTO videos (title, url, rating, createdAt) VALUES ($1, $2, 0, now());`; +// converting mobile YouTube links like this https://youtu.be/n3JNtfi4Vb0?si=dRx5CJJctB6P_yVR to this https://www.youtube.com/watch?v=n3JNtfi4Vb0 + let formattedUrl; if (url.startsWith("https://youtu.be")) { const [_, rest] = url.split("https://youtu.be/"); - const [id] = rest.split("?"); - formattedUrl = `https://www.youtube.com/watch?v=${id}`; + const [videoId] = rest.split("?"); + formattedUrl = `https://www.youtube.com/watch?v=${videoId}`; } db.query(query, [title, formattedUrl || url])