Merge branch 'develop' of Software_Engineering_I/greenvironment-server into master

pull/5/head
Trivernis 5 years ago committed by Gitea
commit d6164c10f9

@ -112,11 +112,13 @@ export class UploadRoute extends Route {
.toFile(filePath); .toFile(filePath);
fileName = `/${dataDirName}/${fileBasename}`; fileName = `/${dataDirName}/${fileBasename}`;
const user = await User.findByPk(request.session.userId); const user = await User.findByPk(request.session.userId);
const oldProfilePicture = path.join(this.dataDir, path.basename(user.profilePicture)); if (user.profilePicture) {
if (await fsx.pathExists(oldProfilePicture)) { const oldProfilePicture = path.join(this.dataDir, path.basename(user.profilePicture));
await fsx.unlink(oldProfilePicture); if (await fsx.pathExists(oldProfilePicture)) {
} else { await fsx.unlink(oldProfilePicture);
globals.logger.warn(`Could not delete ${oldProfilePicture}: Not found!`); } else {
globals.logger.warn(`Could not delete ${oldProfilePicture}: Not found!`);
}
} }
user.profilePicture = fileName; user.profilePicture = fileName;
await user.save(); await user.save();

Loading…
Cancel
Save