From 2a0cb3b9eed9da1fbc0fe0215f9bc8928a856ba2 Mon Sep 17 00:00:00 2001
From: Peter Jaszkowiak
Date: Wed, 26 Apr 2017 14:57:49 -0600
Subject: [PATCH] Fix profile covers not working with subfolders
Remove relative_path from the paths saved in the database so they're more portable
---
src/controllers/accounts/helpers.js | 3 +-
src/controllers/accounts/profile.js | 3 --
.../remove_relative_uploaded_profile_cover.js | 38 +++++++++++++++++++
3 files changed, 40 insertions(+), 4 deletions(-)
create mode 100644 src/upgrades/1.5.0/remove_relative_uploaded_profile_cover.js
diff --git a/src/controllers/accounts/helpers.js b/src/controllers/accounts/helpers.js
index 339b3a2c2f..3c73d31800 100644
--- a/src/controllers/accounts/helpers.js
+++ b/src/controllers/accounts/helpers.js
@@ -4,6 +4,7 @@
var async = require('async');
var validator = require('validator');
var winston = require('winston');
+var nconf = require('nconf');
var user = require('../../user');
var groups = require('../../groups');
@@ -144,7 +145,7 @@ helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) {
userData.birthday = validator.escape(String(userData.birthday || ''));
userData.moderationNote = validator.escape(String(userData.moderationNote || ''));
- userData['cover:url'] = userData['cover:url'] || require('../../coverPhoto').getDefaultProfileCover(userData.uid);
+ userData['cover:url'] = (nconf.get('relative_path') + userData['cover:url']) || require('../../coverPhoto').getDefaultProfileCover(userData.uid);
userData['cover:position'] = validator.escape(String(userData['cover:position'] || '50% 50%'));
userData['username:disableEdit'] = !userData.isAdmin && parseInt(meta.config['username:disableEdit'], 10) === 1;
userData['email:disableEdit'] = !userData.isAdmin && parseInt(meta.config['email:disableEdit'], 10) === 1;
diff --git a/src/controllers/accounts/profile.js b/src/controllers/accounts/profile.js
index d22e3256bf..450ee92f60 100644
--- a/src/controllers/accounts/profile.js
+++ b/src/controllers/accounts/profile.js
@@ -82,9 +82,6 @@ profileController.get = function (req, res, callback) {
var pageCount = Math.ceil(userData.postcount / itemsPerPage);
userData.pagination = pagination.create(page, pageCount, req.query);
- userData['cover:url'] = userData['cover:url'] || require('../../coverPhoto').getDefaultProfileCover(userData.uid);
- userData['cover:position'] = userData['cover:position'] || '50% 50%';
-
if (!parseInt(userData.profileviews, 10)) {
userData.profileviews = 1;
}
diff --git a/src/upgrades/1.5.0/remove_relative_uploaded_profile_cover.js b/src/upgrades/1.5.0/remove_relative_uploaded_profile_cover.js
new file mode 100644
index 0000000000..54a5e80ff2
--- /dev/null
+++ b/src/upgrades/1.5.0/remove_relative_uploaded_profile_cover.js
@@ -0,0 +1,38 @@
+/* jslint node: true */
+
+'use strict';
+
+var db = require('../../database');
+var batch = require('../../batch');
+
+var async = require('async');
+
+module.exports = {
+ name: 'Remove relative_path from uploaded profile cover urls',
+ timestamp: Date.UTC(2017, 3, 26),
+ method: function (callback) {
+ var progress = this.progress;
+
+ batch.processSortedSet('users:joindate', function (ids, done) {
+ async.each(ids, function (uid, cb) {
+ async.waterfall([
+ function (next) {
+ db.getObjectField('user:' + uid, 'cover:url', next);
+ },
+ function (url, next) {
+ progress.incr();
+
+ if (!url) {
+ return next();
+ }
+
+ var newUrl = url.replace(/^.*?\/uploads\//, '/assets/uploads/');
+ db.setObjectField('user:' + uid, 'cover:url', newUrl, next);
+ },
+ ], cb);
+ }, done);
+ }, {
+ progress: this.progress,
+ }, callback);
+ },
+};