Fix profile covers not working with subfolders

Remove relative_path from the paths saved in the database so they're more portable
v1.18.x
Peter Jaszkowiak 8 years ago
parent 33e8ecc1f4
commit 2a0cb3b9ee

@ -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;

@ -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;
}

@ -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);
},
};
Loading…
Cancel
Save