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