From 0d40542f933b8f12241c4a414c5490dabdf9e2c2 Mon Sep 17 00:00:00 2001
From: Ben Lubar
Date: Thu, 28 Jul 2016 12:21:37 -0500
Subject: [PATCH 1/2] Keep old versions of avatars in the filesystem. Change
the avatar URL each time a new one is uploaded to avoid caching problems.
Closes #4722.
---
src/user/picture.js | 20 +++-----------------
1 file changed, 3 insertions(+), 17 deletions(-)
diff --git a/src/user/picture.js b/src/user/picture.js
index 385050fcf2..19f6a2bd81 100644
--- a/src/user/picture.js
+++ b/src/user/picture.js
@@ -42,7 +42,7 @@ module.exports = function(User) {
return plugins.fireHook('filter:uploadImage', {image: picture, uid: updateUid}, next);
}
- var filename = updateUid + '-profileimg' + (convertToPNG ? '.png' : extension);
+ var filename = updateUid + '-profileimg-' + Date.now() + (convertToPNG ? '.png' : extension);
async.waterfall([
function(next) {
@@ -68,21 +68,7 @@ module.exports = function(User) {
});
},
function(next) {
- User.getUserField(updateUid, 'uploadedpicture', next);
- },
- function(oldpicture, next) {
- if (!oldpicture) {
- return file.saveFileToLocal(filename, 'profile', picture.path, next);
- }
- var oldpicturePath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), 'profile', path.basename(oldpicture));
-
- fs.unlink(oldpicturePath, function (err) {
- if (err) {
- winston.error(err);
- }
-
- file.saveFileToLocal(filename, 'profile', picture.path, next);
- });
+ file.saveFileToLocal(filename, 'profile', picture.path, next);
},
], next);
},
@@ -181,7 +167,7 @@ module.exports = function(User) {
return plugins.fireHook('filter:uploadImage', {image: image, uid: data.uid}, next);
}
- var filename = data.uid + '-profilecover';
+ var filename = data.uid + '-profilecover-' + Date.now();
async.waterfall([
function (next) {
file.isFileTypeAllowed(data.file.path, next);
From fc387111e29ca61a89745f51207b4c45e7919e5b Mon Sep 17 00:00:00 2001
From: Ben Lubar
Date: Thu, 28 Jul 2016 13:16:38 -0500
Subject: [PATCH 2/2] make keeping avatar versions an option in the ACP that is
turned off by default
---
src/user/picture.js | 6 ++++--
src/views/admin/settings/uploads.tpl | 9 ++++++++-
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/user/picture.js b/src/user/picture.js
index 19f6a2bd81..38d013cab0 100644
--- a/src/user/picture.js
+++ b/src/user/picture.js
@@ -25,6 +25,7 @@ module.exports = function(User) {
var updateUid = uid;
var imageDimension = parseInt(meta.config.profileImageDimension, 10) || 128;
var convertToPNG = parseInt(meta.config['profile:convertProfileImageToPNG'], 10) === 1;
+ var keepAllVersions = parseInt(meta.config['profile:keepAllUserImages'], 10) === 1;
var uploadedImage;
async.waterfall([
@@ -42,7 +43,7 @@ module.exports = function(User) {
return plugins.fireHook('filter:uploadImage', {image: picture, uid: updateUid}, next);
}
- var filename = updateUid + '-profileimg-' + Date.now() + (convertToPNG ? '.png' : extension);
+ var filename = updateUid + '-profileimg' + (keepAllVersions ? '-' + Date.now() : '') + (convertToPNG ? '.png' : extension);
async.waterfall([
function(next) {
@@ -120,6 +121,7 @@ module.exports = function(User) {
};
User.updateCoverPicture = function(data, callback) {
+ var keepAllVersions = parseInt(meta.config['profile:keepAllUserImages'], 10) === 1;
var url, md5sum;
if (!data.imageData && data.position) {
@@ -167,7 +169,7 @@ module.exports = function(User) {
return plugins.fireHook('filter:uploadImage', {image: image, uid: data.uid}, next);
}
- var filename = data.uid + '-profilecover-' + Date.now();
+ var filename = data.uid + '-profilecover' + (keepAllVersions ? '-' + Date.now() : '');
async.waterfall([
function (next) {
file.isFileTypeAllowed(data.file.path, next);
diff --git a/src/views/admin/settings/uploads.tpl b/src/views/admin/settings/uploads.tpl
index f5b2e3c5a5..9b76626dd3 100644
--- a/src/views/admin/settings/uploads.tpl
+++ b/src/views/admin/settings/uploads.tpl
@@ -115,6 +115,13 @@
(in kilobytes, default: 2,048 KiB)
+
+
+
+
@@ -132,4 +139,4 @@
-
\ No newline at end of file
+