From 82a71b5e77f3ca6f86d9107d4fb4d29512d6f9fc Mon Sep 17 00:00:00 2001 From: Astri4-4 Date: Mon, 21 Jul 2025 19:03:32 +0000 Subject: [PATCH 1/2] FINISH profile page --- backend/app/controllers/user.controller.js | 6 +- backend/logs/access.log | 70 ++++++++++++++++++++++ frontend/src/pages/Account.jsx | 8 ++- 3 files changed, 78 insertions(+), 6 deletions(-) diff --git a/backend/app/controllers/user.controller.js b/backend/app/controllers/user.controller.js index 8a67a8f..e218810 100644 --- a/backend/app/controllers/user.controller.js +++ b/backend/app/controllers/user.controller.js @@ -189,19 +189,19 @@ export async function update(req, res) { console.log(__dirname); let profilePicture = userInBase.picture.split("/").pop(); - fs.rename(__dirname + "../uploads/profiles/" + profilePicture, __dirname + "../uploads/profiles/" + user.username + "." + profilePicture.split(".").pop(), (err) => { + fs.rename(__dirname + "/../uploads/profiles/" + profilePicture, __dirname + "/../uploads/profiles/" + user.username + "." + profilePicture.split(".").pop(), (err) => { if (err) { logger.write("failed to update profile picture", 500); console.error("Error renaming file:", err); throw err; } }); - profilePicture = user.username + "." + profilePicture.split(".").pop(); + profilePicture = "/api/media/profile/" + user.username + "." + profilePicture.split(".").pop(); const updateQuery = `UPDATE users SET email = $1, username = $2, password = $3, picture = $4 WHERE id = $5 RETURNING id, email, username, picture`; const result = await client.query(updateQuery, [user.email, user.username, user.password, profilePicture, id]); logger.write("successfully updated user " + id, 200); - res.status(200).send({user: result.rows[0]}); + res.status(200).json(result.rows[0]); } catch (err) { console.log(err); res.status(500).json({error: err}); diff --git a/backend/logs/access.log b/backend/logs/access.log index 3c1fee3..77eb18e 100644 --- a/backend/logs/access.log +++ b/backend/logs/access.log @@ -1393,3 +1393,73 @@ [2025-07-21 15:23:44.537] [undefined] GET(/user/:id): Playlists retrieved for user with id 6 with status 200 [2025-07-21 15:23:49.626] [undefined] PUT(/:id): try to update user 6 [2025-07-21 15:23:49.633] [undefined] PUT(/:id): failed to update profile picture with status 500 +[2025-07-21 18:55:14.850] [undefined] POST(/login): try to login with username 'astria' +[2025-07-21 18:55:14.865] [undefined] POST(/login): failed to login with status 401 +[2025-07-21 18:55:26.093] [undefined] POST(/login): try to login with username 'sacha' +[2025-07-21 18:55:26.145] [undefined] POST(/login): Successfully logged in with status 200 +[2025-07-21 18:56:09.969] [undefined] GET(/:id/channel): try to retrieve channel of user 1 +[2025-07-21 18:56:09.970] [undefined] GET(/:id/history): try to retrieve history of user 1 +[2025-07-21 18:56:09.971] [undefined] GET(/:id/channel): successfully retrieved channel of user 1 with status 200 +[2025-07-21 18:56:09.973] [undefined] GET(/:id/history): successfully retrieved history of user 1 with status 200 +[2025-07-21 18:56:09.983] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200 +[2025-07-21 18:56:30.328] [undefined] GET(/:id/channel): try to retrieve channel of user 1 +[2025-07-21 18:56:30.331] [undefined] GET(/:id/channel): successfully retrieved channel of user 1 with status 200 +[2025-07-21 18:56:30.332] [undefined] GET(/:id/history): try to retrieve history of user 1 +[2025-07-21 18:56:30.335] [undefined] GET(/:id/history): successfully retrieved history of user 1 with status 200 +[2025-07-21 18:56:30.340] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200 +[2025-07-21 18:56:37.069] [undefined] POST(/login): try to login with username 'sacha' +[2025-07-21 18:56:37.118] [undefined] POST(/login): Successfully logged in with status 200 +[2025-07-21 18:56:51.114] [undefined] GET(/:id/channel): try to retrieve channel of user 1 +[2025-07-21 18:56:51.115] [undefined] GET(/:id/channel): successfully retrieved channel of user 1 with status 200 +[2025-07-21 18:56:51.116] [undefined] GET(/:id/history): try to retrieve history of user 1 +[2025-07-21 18:56:51.118] [undefined] GET(/:id/history): successfully retrieved history of user 1 with status 200 +[2025-07-21 18:56:51.126] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200 +[2025-07-21 18:57:46.290] [undefined] GET(/:id/channel): try to retrieve channel of user 1 +[2025-07-21 18:57:46.293] [undefined] GET(/:id/channel): successfully retrieved channel of user 1 with status 200 +[2025-07-21 18:57:46.295] [undefined] GET(/:id/history): try to retrieve history of user 1 +[2025-07-21 18:57:46.299] [undefined] GET(/:id/history): successfully retrieved history of user 1 with status 200 +[2025-07-21 18:57:46.303] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200 +[2025-07-21 18:57:52.156] [undefined] PUT(/:id): try to update user 1 +[2025-07-21 18:57:52.158] [undefined] PUT(/:id): successfully updated user 1 with status 200 +[2025-07-21 18:58:05.603] [undefined] GET(/:id/channel): failed due to invalid values with status 400 +[2025-07-21 18:58:05.608] [undefined] GET(/:id/history): failed due to invalid values with status 400 +[2025-07-21 18:58:05.610] [undefined] GET(/user/:id): failed due to invalid values with status 400 +[2025-07-21 18:58:52.332] [undefined] GET(/:id/channel): failed due to invalid values with status 400 +[2025-07-21 18:58:52.339] [undefined] GET(/:id/history): failed due to invalid values with status 400 +[2025-07-21 18:58:52.341] [undefined] GET(/user/:id): failed due to invalid values with status 400 +[2025-07-21 18:58:57.222] [undefined] GET(/:id/channel): failed due to invalid values with status 400 +[2025-07-21 18:58:57.225] [undefined] GET(/:id/history): failed due to invalid values with status 400 +[2025-07-21 18:58:57.228] [undefined] GET(/user/:id): failed due to invalid values with status 400 +[2025-07-21 19:00:00.868] [undefined] GET(/:id/channel): failed due to invalid values with status 400 +[2025-07-21 19:00:00.875] [undefined] GET(/:id/history): failed due to invalid values with status 400 +[2025-07-21 19:00:00.878] [undefined] GET(/user/:id): failed due to invalid values with status 400 +[2025-07-21 19:00:07.728] [undefined] PUT(/:id): failed due to invalid values with status 400 +[2025-07-21 19:00:22.072] [undefined] POST(/login): try to login with username 'astria' +[2025-07-21 19:00:22.123] [undefined] POST(/login): Successfully logged in with status 200 +[2025-07-21 19:00:31.149] [undefined] GET(/:id/channel): try to retrieve channel of user 1 +[2025-07-21 19:00:31.150] [undefined] GET(/:id/channel): successfully retrieved channel of user 1 with status 200 +[2025-07-21 19:00:31.151] [undefined] GET(/:id/history): try to retrieve history of user 1 +[2025-07-21 19:00:31.154] [undefined] GET(/:id/history): successfully retrieved history of user 1 with status 200 +[2025-07-21 19:00:31.161] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200 +[2025-07-21 19:00:37.082] [undefined] PUT(/:id): try to update user 1 +[2025-07-21 19:00:37.085] [undefined] PUT(/:id): successfully updated user 1 with status 200 +[2025-07-21 19:00:41.130] [undefined] GET(/:id/channel): try to retrieve channel of user 1 +[2025-07-21 19:00:41.131] [undefined] GET(/:id/history): try to retrieve history of user 1 +[2025-07-21 19:00:41.132] [undefined] GET(/:id/channel): successfully retrieved channel of user 1 with status 200 +[2025-07-21 19:00:41.134] [undefined] GET(/:id/history): successfully retrieved history of user 1 with status 200 +[2025-07-21 19:00:41.142] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200 +[2025-07-21 19:01:27.664] [undefined] GET(/:id/channel): try to retrieve channel of user 1 +[2025-07-21 19:01:27.665] [undefined] GET(/:id/history): try to retrieve history of user 1 +[2025-07-21 19:01:27.672] [undefined] GET(/:id/channel): successfully retrieved channel of user 1 with status 200 +[2025-07-21 19:01:27.674] [undefined] GET(/:id/history): successfully retrieved history of user 1 with status 200 +[2025-07-21 19:01:27.682] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200 +[2025-07-21 19:03:09.269] [undefined] GET(/:id/channel): try to retrieve channel of user 1 +[2025-07-21 19:03:09.269] [undefined] GET(/:id/history): try to retrieve history of user 1 +[2025-07-21 19:03:09.271] [undefined] GET(/:id/channel): successfully retrieved channel of user 1 with status 200 +[2025-07-21 19:03:09.274] [undefined] GET(/:id/history): successfully retrieved history of user 1 with status 200 +[2025-07-21 19:03:09.282] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200 +[2025-07-21 19:03:11.312] [undefined] GET(/:id/channel): try to retrieve channel of user 1 +[2025-07-21 19:03:11.314] [undefined] GET(/:id/channel): successfully retrieved channel of user 1 with status 200 +[2025-07-21 19:03:11.316] [undefined] GET(/:id/history): try to retrieve history of user 1 +[2025-07-21 19:03:11.318] [undefined] GET(/:id/history): successfully retrieved history of user 1 with status 200 +[2025-07-21 19:03:11.323] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200 diff --git a/frontend/src/pages/Account.jsx b/frontend/src/pages/Account.jsx index 2931bf2..206e8b1 100644 --- a/frontend/src/pages/Account.jsx +++ b/frontend/src/pages/Account.jsx @@ -2,6 +2,7 @@ import Navbar from "../components/Navbar.jsx"; import {useEffect, useState} from "react"; import PlaylistCard from "../components/PlaylistCard.jsx"; import VideoCard from "../components/VideoCard.jsx"; +import {useNavigate} from "react-router-dom"; export default function Account() { @@ -16,9 +17,10 @@ export default function Account() { const [isPictureEditActive, setIsPictureEditActive] = useState(false); const [userHistory, setUserHistory] = useState([]); const [userPlaylists, setUserPlaylists] = useState([]); - const [userChannel, setUserChannel] = useState(null); + const navigation = useNavigate(); + const fetchUserChannel = async () => { try { const response = await fetch(`/api/users/${user.id}/channel`, { @@ -93,7 +95,7 @@ export default function Account() { const editModeClasses = nonEditModeClasses + " glassmorphism"; const handlePlaylistClick = (playlistId) => { - + navigation(`/playlist/${playlistId}`); } const handleUpdateUser = async () => { @@ -253,7 +255,7 @@ export default function Account() {

{userChannel.channel.name}

From 1cb49e04b44ee2ad5f83a1905eefc7847a84ad1a Mon Sep 17 00:00:00 2001 From: Astri4-4 Date: Mon, 21 Jul 2025 19:15:59 +0000 Subject: [PATCH 2/2] REFACTOR path handling + more consistent navigation --- backend/app/controllers/user.controller.js | 5 ++++- frontend/src/pages/Account.jsx | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/app/controllers/user.controller.js b/backend/app/controllers/user.controller.js index e218810..4843587 100644 --- a/backend/app/controllers/user.controller.js +++ b/backend/app/controllers/user.controller.js @@ -189,7 +189,10 @@ export async function update(req, res) { console.log(__dirname); let profilePicture = userInBase.picture.split("/").pop(); - fs.rename(__dirname + "/../uploads/profiles/" + profilePicture, __dirname + "/../uploads/profiles/" + user.username + "." + profilePicture.split(".").pop(), (err) => { + fs.rename( + path.join(__dirname, "..", "uploads", "profiles", profilePicture), + path.join(__dirname, "..", "uploads", "profiles", user.username + "." + profilePicture.split(".").pop()), + (err) => { if (err) { logger.write("failed to update profile picture", 500); console.error("Error renaming file:", err); diff --git a/frontend/src/pages/Account.jsx b/frontend/src/pages/Account.jsx index 206e8b1..e0cbe80 100644 --- a/frontend/src/pages/Account.jsx +++ b/frontend/src/pages/Account.jsx @@ -255,9 +255,9 @@ export default function Account() {

{userChannel.channel.name}

) : (