Browse Source

ADD comments hot relaod

fix/clean
Astri4-4 5 months ago
parent
commit
412e64d0b2
  1. 26
      backend/app/controllers/comment.controller.js
  2. 242
      backend/logs/access.log
  3. 16
      frontend/src/components/Comment.jsx
  4. 34
      frontend/src/pages/Video.jsx

26
backend/app/controllers/comment.controller.js

@ -17,10 +17,30 @@ export async function upload(req, res) {
logger.action("try to post comment");
const client = await getClient();
const query = `INSERT INTO comments (content, author, video, created_at) VALUES ($1, $2, $3, $4)`;
await client.query(query, [comment.content, comment.author, comment.video, comment.createdAt]);
const query = `INSERT INTO comments (content, author, video, created_at) VALUES ($1, $2, $3, $4) RETURNING id, created_at`;
const result = await client.query(query, [comment.content, comment.author, comment.video, comment.createdAt]);
logger.write("successfully post comment", 200);
res.status(200).send("successfully post comment");
const createdAt = result.rows[0].created_at;
comment.id = result.rows[0].id;
// Send back the comment
// Get the author's name and profile picture
const authorQuery = `SELECT username, picture FROM users WHERE id = $1`;
const authorResult = await client.query(authorQuery, [comment.author]);
const author = authorResult.rows[0];
const responseComment = {
id: comment.id,
content: comment.content,
video: comment.video,
username: author.username,
picture: author.picture,
createdAt: createdAt
}
res.status(200).json(responseComment);
}

242
backend/logs/access.log

@ -831,3 +831,245 @@
[2025-07-19 23:05:34.319] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-19 23:05:34.328] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-19 23:05:34.333] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:17:13.385] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:17:13.394] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:17:13.404] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:17:13.412] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:17:13.428] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:17:13.435] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:17:15.012] [undefined] GET(/:id): try to get video 2
[2025-07-20 08:17:15.020] [undefined] GET(/:id): successfully get video 2 with status 200
[2025-07-20 08:17:15.030] [undefined] GET(/:id/similar): try to get similar videos for video 2
[2025-07-20 08:17:15.037] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 2 with status 200
[2025-07-20 08:17:15.048] [undefined] GET(/:id/views): try to add views for video 2
[2025-07-20 08:17:15.053] [undefined] GET(/:id/views): successfully added views for video 2 with status 200
[2025-07-20 08:17:15.577] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:17:15.585] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:17:15.593] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:17:15.600] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:17:15.610] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:17:15.615] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:17:22.613] [undefined] DELETE(/:id): try to delete comment 1
[2025-07-20 08:17:22.619] [undefined] DELETE(/:id): successfully deleted comment with status 200
[2025-07-20 08:17:24.642] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:17:24.650] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:17:24.661] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:17:24.671] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:17:24.683] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:17:24.699] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:19:39.097] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:19:39.106] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:19:39.118] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:19:39.129] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:19:39.143] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:19:39.151] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:19:43.001] [undefined] POST(/): try to post comment
[2025-07-20 08:19:43.008] [undefined] POST(/): successfully post comment with status 200
[2025-07-20 08:19:44.352] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:19:44.360] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:19:44.369] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:19:44.381] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:19:44.412] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:19:44.419] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:19:45.960] [undefined] DELETE(/:id): try to delete comment 5
[2025-07-20 08:19:45.967] [undefined] DELETE(/:id): successfully deleted comment with status 200
[2025-07-20 08:20:16.598] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:20:16.606] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:20:16.615] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:20:16.626] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:20:16.649] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:20:16.657] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:20:20.460] [undefined] POST(/): try to post comment
[2025-07-20 08:20:20.467] [undefined] POST(/): successfully post comment with status 200
[2025-07-20 08:20:21.812] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:20:21.819] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:20:21.830] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:20:21.840] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:20:21.858] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:20:21.865] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:20:23.080] [undefined] DELETE(/:id): try to delete comment 6
[2025-07-20 08:20:23.085] [undefined] DELETE(/:id): successfully deleted comment with status 200
[2025-07-20 08:20:23.093] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:20:23.101] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:20:23.110] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:20:23.117] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:20:23.126] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:20:23.132] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:20:59.078] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:20:59.087] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:20:59.095] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:20:59.105] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:20:59.121] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:20:59.129] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:21:02.851] [undefined] POST(/): try to post comment
[2025-07-20 08:21:02.860] [undefined] POST(/): successfully post comment with status 200
[2025-07-20 08:21:04.022] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:21:04.030] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:21:04.043] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:21:04.052] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:21:04.066] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:21:04.076] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:22:32.802] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:22:32.810] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:22:32.819] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:22:32.830] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:22:32.850] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:22:32.857] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:22:36.610] [undefined] POST(/): try to post comment
[2025-07-20 08:22:36.617] [undefined] POST(/): successfully post comment with status 200
[2025-07-20 08:23:17.340] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:23:17.350] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:23:17.360] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:23:17.371] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:23:17.390] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:23:17.397] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:23:19.938] [undefined] POST(/): try to post comment
[2025-07-20 08:23:19.944] [undefined] POST(/): successfully post comment with status 200
[2025-07-20 08:23:31.546] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:24:03.520] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:24:03.531] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:24:03.542] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:24:03.555] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:24:03.571] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:24:03.578] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:24:06.139] [undefined] DELETE(/:id): try to delete comment 7
[2025-07-20 08:24:06.144] [undefined] DELETE(/:id): successfully deleted comment with status 200
[2025-07-20 08:24:06.152] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:24:06.160] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:24:06.168] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:24:06.175] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:24:06.184] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:24:06.190] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:24:06.902] [undefined] DELETE(/:id): try to delete comment 8
[2025-07-20 08:24:06.907] [undefined] DELETE(/:id): successfully deleted comment with status 200
[2025-07-20 08:24:06.915] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:24:06.923] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:24:06.931] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:24:06.938] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:24:06.946] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:24:06.952] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:24:07.728] [undefined] DELETE(/:id): try to delete comment 9
[2025-07-20 08:24:07.733] [undefined] DELETE(/:id): successfully deleted comment with status 200
[2025-07-20 08:24:07.741] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:24:07.748] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:24:07.756] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:24:07.764] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:24:07.773] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:24:07.779] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:24:54.566] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:24:54.574] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:24:54.584] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:24:54.594] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:24:54.610] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:24:54.617] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:25:46.381] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:25:46.391] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:25:46.405] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:25:46.417] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:25:46.433] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:25:46.442] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:25:50.563] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:25:50.572] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:25:50.581] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:25:50.592] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:25:50.610] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:25:50.618] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:25:54.456] [undefined] POST(/): try to post comment
[2025-07-20 08:25:54.463] [undefined] POST(/): successfully post comment with status 200
[2025-07-20 08:25:55.690] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:25:55.697] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:25:55.706] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:25:55.716] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:25:55.731] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:25:55.738] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:29:04.387] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:29:04.395] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:29:04.403] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:29:04.413] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:29:04.427] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:29:04.435] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:29:06.717] [undefined] POST(/): try to post comment
[2025-07-20 08:29:06.724] [undefined] POST(/): successfully post comment with status 200
[2025-07-20 08:29:49.666] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:29:49.674] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:29:49.684] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:29:49.694] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:29:49.706] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:29:49.714] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:29:52.277] [undefined] POST(/): try to post comment
[2025-07-20 08:29:52.283] [undefined] POST(/): successfully post comment with status 200
[2025-07-20 08:29:57.910] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:29:57.919] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:29:57.931] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:29:57.940] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:29:57.965] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:29:57.971] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:30:02.939] [undefined] POST(/): try to post comment
[2025-07-20 08:30:02.945] [undefined] POST(/): successfully post comment with status 200
[2025-07-20 08:30:38.602] [undefined] DELETE(/:id): try to delete comment 10
[2025-07-20 08:30:38.608] [undefined] DELETE(/:id): successfully deleted comment with status 200
[2025-07-20 08:30:38.616] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:30:38.623] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:30:38.631] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:30:38.639] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:30:38.648] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:30:38.653] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:30:39.035] [undefined] DELETE(/:id): try to delete comment 11
[2025-07-20 08:30:39.040] [undefined] DELETE(/:id): successfully deleted comment with status 200
[2025-07-20 08:30:39.048] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:30:39.055] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:30:39.063] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:30:39.071] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:31:14.966] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:31:14.978] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:31:14.991] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:31:15.002] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:31:15.021] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:31:15.029] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:31:16.736] [undefined] DELETE(/:id): try to delete comment 12
[2025-07-20 08:31:16.742] [undefined] DELETE(/:id): successfully deleted comment with status 200
[2025-07-20 08:31:16.750] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:31:16.758] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:31:16.766] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:31:16.774] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:31:16.783] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:31:16.789] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:31:17.876] [undefined] DELETE(/:id): try to delete comment 13
[2025-07-20 08:31:17.882] [undefined] DELETE(/:id): successfully deleted comment with status 200
[2025-07-20 08:31:17.890] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:31:17.897] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:31:17.906] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:31:17.914] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:31:17.924] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:31:17.930] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:33:16.918] [undefined] POST(/): try to post comment
[2025-07-20 08:33:16.925] [undefined] POST(/): successfully post comment with status 200
[2025-07-20 08:33:18.845] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:33:18.854] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:33:18.864] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:33:18.873] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:33:18.912] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:33:18.921] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:35:42.164] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:35:42.175] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:35:42.190] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:35:42.201] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:35:42.228] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:35:42.236] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:35:45.179] [undefined] POST(/): try to post comment
[2025-07-20 08:35:45.185] [undefined] POST(/): successfully post comment with status 200
[2025-07-20 08:35:46.285] [undefined] GET(/video/:id): Invalid token with status 401
[2025-07-20 08:36:01.025] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:36:01.034] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:36:01.044] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:36:01.053] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:36:01.089] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:36:01.098] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:37:01.957] [undefined] GET(/:id): try to get video 3
[2025-07-20 08:37:01.965] [undefined] GET(/:id): successfully get video 3 with status 200
[2025-07-20 08:37:01.975] [undefined] GET(/:id/similar): try to get similar videos for video 3
[2025-07-20 08:37:01.986] [undefined] GET(/:id/similar): successfully retrieved similar videos for video 3 with status 200
[2025-07-20 08:37:02.019] [undefined] GET(/:id/views): try to add views for video 3
[2025-07-20 08:37:02.029] [undefined] GET(/:id/views): successfully added views for video 3 with status 200
[2025-07-20 08:37:03.963] [undefined] POST(/): try to post comment
[2025-07-20 08:37:03.970] [undefined] POST(/): successfully post comment with status 200

16
frontend/src/components/Comment.jsx

@ -2,7 +2,7 @@ import {useAuth} from "../contexts/AuthContext.jsx";
import {useRef, useState} from "react";
export default function Comment({ comment, index, videoId }) {
export default function Comment({ comment, index, videoId, refetchVideo }) {
let {user, isAuthenticated} = useAuth();
let commentRef = useRef();
@ -15,15 +15,25 @@ export default function Comment({ comment, index, videoId }) {
const commentElement = commentRef.current;
commentElement.contentEditable = true;
}
const handleDelete = async (id) => {
try {
const token = localStorage.getItem('token');
await fetch(`/api/comments/${id}`, {
const response = await fetch(`/api/comments/${id}`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
}
})
});
if (response.ok) {
// Refresh the video data to update the comments list
refetchVideo();
}
} catch (error) {
console.error('Error deleting comment:', error);
}
}
const handleEditSubmit = async (id, content) => {

34
frontend/src/pages/Video.jsx

@ -1,5 +1,5 @@
import {useNavigate, useParams} from "react-router-dom";
import {useEffect, useState, useRef} from "react";
import {useEffect, useState, useRef, useCallback} from "react";
import Navbar from "../components/Navbar.jsx";
import { useAuth } from "../contexts/AuthContext.jsx";
import Comment from "../components/Comment.jsx";
@ -22,8 +22,7 @@ export default function Video() {
const [showControls, setShowControls] = useState(false);
const [comment, setComment] = useState("");
useEffect(() => {
const fetchVideo = async () => {
const fetchVideo = useCallback(async () => {
// Fetch video data and similar videos based on the video ID from the URL
try {
const response = await fetch(`/api/videos/${id}`);
@ -63,10 +62,29 @@ export default function Video() {
} catch (error) {
console.error('Error adding views:', error);
}
}, [id, navigation]);
const fetchComments = useCallback(async () => {
// Fetch comments for the video
try {
const response = await fetch(`/api/comments/video/${id}`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const commentsData = await response.json();
setVideo((prevVideo) => ({
...prevVideo,
comments: commentsData
}));
} catch (error) {
console.error('Error fetching comments:', error);
}
fetchVideo();
}, [id]);
useEffect(() => {
fetchVideo();
}, [fetchVideo]);
const handlePlayPause = () => {
if (videoRef.current) {
if (videoRef.current.paused) {
@ -260,6 +278,12 @@ export default function Video() {
console.log('Comment posted successfully:', data);
setComment(""); // Clear the comment input
setVideo((prevVideo) => ({
...prevVideo,
comments: [...(prevVideo.comments || []), data] // Add the new comment to the existing comments
}));
} catch (error) {
console.error('Error posting comment:', error);
}
@ -387,7 +411,7 @@ export default function Video() {
<div className="mt-4">
{video.comments && video.comments.length > 0 ? (
video.comments.map((comment, index) => (
<Comment comment={comment} index={index} videoId={id} />
<Comment comment={comment} index={index} videoId={id} key={index} refetchVideo={fetchVideo} />
))
) : (
<p className="text-gray-400">Aucun commentaire pour le moment. Soyez le premier à en publier !</p>

Loading…
Cancel
Save