V1.0.0-beta.15 Update 2
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Note: We appreciate your feedback and bug reports to continue improving our platform. Thank you for your continued support!
This commit is contained in:
46
routes/Dpanel/API/ProfilPicture.js
Normal file
46
routes/Dpanel/API/ProfilPicture.js
Normal file
@@ -0,0 +1,46 @@
|
||||
const express = require('express');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const router = express.Router();
|
||||
|
||||
router.use(express.json());
|
||||
|
||||
router.post('/', (req, res) => {
|
||||
const userId = req.body.userId;
|
||||
const profilePictureUrl = req.body.profilePictureUrl;
|
||||
|
||||
if (!profilePictureUrl) {
|
||||
return res.status(400).send('No profile picture URL provided.');
|
||||
}
|
||||
|
||||
updateUserProfilePicture(userId, profilePictureUrl, res);
|
||||
});
|
||||
|
||||
const updateUserProfilePicture = (userId, profilePictureUrl, res) => {
|
||||
const userFilePath = path.join(__dirname, '../../../data', 'user.json');
|
||||
|
||||
fs.readFile(userFilePath, 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
return res.status(500).send('Error reading the file');
|
||||
}
|
||||
|
||||
let users = JSON.parse(data);
|
||||
|
||||
const userIndex = users.findIndex(u => u.id === userId);
|
||||
|
||||
if (userIndex !== -1) {
|
||||
users[userIndex].profilePicture = profilePictureUrl;
|
||||
|
||||
fs.writeFile(userFilePath, JSON.stringify(users, null, 2), err => {
|
||||
if (err) {
|
||||
return res.status(500).send('Error writing to the file');
|
||||
}
|
||||
res.json({ profilePicture: profilePictureUrl });
|
||||
});
|
||||
} else {
|
||||
res.status(404).send('User not found');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user