diff --git a/backend/routes/apiRoutes.js b/backend/routes/apiRoutes.js index 43af070..42ccc7c 100644 --- a/backend/routes/apiRoutes.js +++ b/backend/routes/apiRoutes.js @@ -907,6 +907,29 @@ router.put('/me/profile', protect, async (req, res) => { } }); +/** + * @route GET /api/assets/view_avatar/:filename + * @desc Securely stream user avatar images + * @access Public (No auth needed for avatars) + */ +router.get('/assets/view_avatar/:filename', (req, res) => { + try { + const filename = req.params.filename; + const avatarPath = path.join(uploadDir, filename); + + if (!fs.existsSync(avatarPath)) { + return res.status(404).json({ message: 'Avatar not found' }); + } + + res.sendFile(avatarPath, { + maxAge: 2592000000, // 30 ngày + headers: { 'Content-Type': 'image/jpeg' } + }); + } catch (error) { + res.status(500).json({ message: error.message }); + } +}); + /** * @route GET /api/me/scenes * @desc Lấy danh sách các cảnh mẹ do người dùng tạo diff --git a/frontend/css/style.css b/frontend/css/style.css index ca413dc..ea10c07 100644 --- a/frontend/css/style.css +++ b/frontend/css/style.css @@ -422,6 +422,49 @@ html, body { color: #ccc; } +/* Profile Styles */ +.profile-header-edit { + display: flex; + justify-content: center; + margin-bottom: 25px; +} + +.avatar-edit-container { + position: relative; + width: 100px; + height: 100px; +} + +.avatar-edit-container img, #profile-avatar-placeholder { + width: 100%; + height: 100%; + border-radius: 50%; + object-fit: cover; + border: 3px solid #007bff; +} + +.avatar-upload-label { + position: absolute; + bottom: 0; + right: 0; + background: #007bff; + color: white; + width: 32px; + height: 32px; + border-radius: 50%; + display: flex; + align-items: center; + justify-content: center; + cursor: pointer; + font-size: 12px; + border: 2px solid #1e1e1e; + transition: transform 0.2s; +} + +.avatar-upload-label:hover { + transform: scale(1.1); +} + /* Storage Progress Bar */ .storage-info { margin-top: 25px; diff --git a/frontend/index.html b/frontend/index.html index 3ad2811..ee547e7 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -93,8 +93,26 @@