diff --git a/src/server/endpoints/api/User.js b/src/server/endpoints/api/User.js index ecf5740..611fca3 100644 --- a/src/server/endpoints/api/User.js +++ b/src/server/endpoints/api/User.js @@ -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) {