Skip to content

Commit

Permalink
Clear console.log, add meaningful comment and variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
Afsha10 committed Nov 1, 2023
1 parent f7ed0b9 commit e4f65f8
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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])
Expand Down

0 comments on commit e4f65f8

Please sign in to comment.