This commit is contained in:
Erik 2023-02-07 23:15:13 +02:00
parent 90a2f48102
commit 28cbe48793
Signed by: Navy.gif
GPG Key ID: 2532FBBB61C65A68

View File

@ -72,13 +72,15 @@ class UserEndpoint extends ApiEndpoint {
const x = file.name.split('.');
const fileName = `${user.id}.${x[x.length - 1]}`;
const avatarsDir = path.resolve(this.server.serveFiles, 'avatars');
const oldAvatar = path.join(avatarsDir, user.avatar);
if (!fs.statSync(avatarsDir))
fs.mkdirSync(avatarsDir);
// Delete old avatar
if (fs.statSync(oldAvatar))
fs.unlinkSync(oldAvatar);
if (user.avatar) {
const oldAvatar = path.join(avatarsDir, user.avatar);
if (fs.statSync(oldAvatar))
fs.unlinkSync(oldAvatar);
}
file.mv(path.join(avatarsDir, fileName), async (err) => {
if (err) {