From 6420e4c6a6db0d513e9946eab616fc14279ec2f3 Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Thu, 25 Jul 2013 14:51:31 -0400 Subject: [PATCH] added this back, file extensions might change need to delete old pic --- src/routes/user.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/routes/user.js b/src/routes/user.js index 4c98b6c81f..1f53282806 100644 --- a/src/routes/user.js +++ b/src/routes/user.js @@ -126,7 +126,22 @@ var user = require('./../user.js'), return; } - uploadUserPicture(req.user.uid, path.extname(req.files.userPhoto.name), req.files.userPhoto.path, res); + user.getUserField(req.user.uid, 'uploadedpicture', function(oldpicture) { + if(!oldpicture) { + uploadUserPicture(req.user.uid, path.extname(req.files.userPhoto.name), req.files.userPhoto.path, res); + return; + } + + var absolutePath = path.join(global.configuration['ROOT_DIRECTORY'], global.nconf.get('upload_path'), path.basename(oldpicture)); + + fs.unlink(absolutePath, function(err) { + if(err) { + console.error('[%d] %s', Date.now(), + err); + } + + uploadUserPicture(req.user.uid, path.extname(req.files.userPhoto.name), req.files.userPhoto.path, res); + }); + }); }); function uploadUserPicture(uid, extension, tempPath, res) {