From 2a0cb3b9eed9da1fbc0fe0215f9bc8928a856ba2 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Wed, 26 Apr 2017 14:57:49 -0600 Subject: [PATCH 1/2] 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); + }, +}; From 8a87311d5c35c259e0d4f6b5889d78675dec32d1 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Wed, 26 Apr 2017 15:08:12 -0600 Subject: [PATCH 2/2] Remove annoying jslint comment Use an rc file instead --- src/upgrade.js | 2 -- src/upgrades/1.0.0/chat_room_hashes.js | 2 -- src/upgrades/1.0.0/chat_upgrade.js | 2 -- src/upgrades/1.0.0/global_moderators.js | 2 -- src/upgrades/1.0.0/social_post_sharing.js | 2 -- src/upgrades/1.0.0/theme_to_active_plugins.js | 2 -- src/upgrades/1.0.0/user_best_posts.js | 2 -- src/upgrades/1.0.0/users_notvalidated.js | 2 -- src/upgrades/1.1.0/assign_topic_read_privilege.js | 2 -- src/upgrades/1.1.0/dismiss_flags_from_deleted_topics.js | 2 -- src/upgrades/1.1.0/group_title_update.js | 2 -- src/upgrades/1.1.0/separate_upvote_downvote.js | 2 -- src/upgrades/1.1.0/user_post_count_per_tid.js | 2 -- src/upgrades/1.1.1/remove_negative_best_posts.js | 2 -- src/upgrades/1.1.1/upload_privileges.js | 2 -- src/upgrades/1.2.0/category_recent_tids.js | 2 -- src/upgrades/1.2.0/edit_delete_deletetopic_privileges.js | 2 -- src/upgrades/1.3.0/favourites_to_bookmarks.js | 2 -- src/upgrades/1.3.0/sorted_sets_for_post_replies.js | 2 -- src/upgrades/1.4.0/global_and_user_language_keys.js | 2 -- src/upgrades/1.4.0/sorted_set_for_pinned_topics.js | 2 -- src/upgrades/1.4.4/config_urls_update.js | 2 -- src/upgrades/1.4.4/sound_settings.js | 2 -- src/upgrades/1.4.6/delete_sessions.js | 2 -- src/upgrades/1.5.0/allowed_file_extensions.js | 2 -- src/upgrades/1.5.0/flags_refactor.js | 2 -- src/upgrades/1.5.0/moderation_history_refactor.js | 2 -- src/upgrades/1.5.0/post_votes_zset.js | 2 -- src/upgrades/1.5.0/remove_relative_uploaded_profile_cover.js | 2 -- src/upgrades/TEMPLATE | 2 -- 30 files changed, 60 deletions(-) diff --git a/src/upgrade.js b/src/upgrade.js index c395dc8884..22c7867eeb 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var async = require('async'); diff --git a/src/upgrades/1.0.0/chat_room_hashes.js b/src/upgrades/1.0.0/chat_room_hashes.js index 054b6c8d7e..ae52be31f7 100644 --- a/src/upgrades/1.0.0/chat_room_hashes.js +++ b/src/upgrades/1.0.0/chat_room_hashes.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.0.0/chat_upgrade.js b/src/upgrades/1.0.0/chat_upgrade.js index ae93ca95a5..d5a971d4b4 100644 --- a/src/upgrades/1.0.0/chat_upgrade.js +++ b/src/upgrades/1.0.0/chat_upgrade.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.0.0/global_moderators.js b/src/upgrades/1.0.0/global_moderators.js index 3ba5f49955..7639da9453 100644 --- a/src/upgrades/1.0.0/global_moderators.js +++ b/src/upgrades/1.0.0/global_moderators.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var async = require('async'); diff --git a/src/upgrades/1.0.0/social_post_sharing.js b/src/upgrades/1.0.0/social_post_sharing.js index 03d303fe07..3477da86bb 100644 --- a/src/upgrades/1.0.0/social_post_sharing.js +++ b/src/upgrades/1.0.0/social_post_sharing.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.0.0/theme_to_active_plugins.js b/src/upgrades/1.0.0/theme_to_active_plugins.js index 3a3bdd25eb..07b95f45aa 100644 --- a/src/upgrades/1.0.0/theme_to_active_plugins.js +++ b/src/upgrades/1.0.0/theme_to_active_plugins.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.0.0/user_best_posts.js b/src/upgrades/1.0.0/user_best_posts.js index 560ef7b29c..986e88efa7 100644 --- a/src/upgrades/1.0.0/user_best_posts.js +++ b/src/upgrades/1.0.0/user_best_posts.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.0.0/users_notvalidated.js b/src/upgrades/1.0.0/users_notvalidated.js index 5b5e60270b..a69deb90df 100644 --- a/src/upgrades/1.0.0/users_notvalidated.js +++ b/src/upgrades/1.0.0/users_notvalidated.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.1.0/assign_topic_read_privilege.js b/src/upgrades/1.1.0/assign_topic_read_privilege.js index 9f23cd7384..93d06485e6 100644 --- a/src/upgrades/1.1.0/assign_topic_read_privilege.js +++ b/src/upgrades/1.1.0/assign_topic_read_privilege.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.1.0/dismiss_flags_from_deleted_topics.js b/src/upgrades/1.1.0/dismiss_flags_from_deleted_topics.js index 85d14f6bbc..6cbf6b7254 100644 --- a/src/upgrades/1.1.0/dismiss_flags_from_deleted_topics.js +++ b/src/upgrades/1.1.0/dismiss_flags_from_deleted_topics.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.1.0/group_title_update.js b/src/upgrades/1.1.0/group_title_update.js index 1c6065a3d4..7b8847f276 100644 --- a/src/upgrades/1.1.0/group_title_update.js +++ b/src/upgrades/1.1.0/group_title_update.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.1.0/separate_upvote_downvote.js b/src/upgrades/1.1.0/separate_upvote_downvote.js index 3f78667dc5..dbfb5aee09 100644 --- a/src/upgrades/1.1.0/separate_upvote_downvote.js +++ b/src/upgrades/1.1.0/separate_upvote_downvote.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.1.0/user_post_count_per_tid.js b/src/upgrades/1.1.0/user_post_count_per_tid.js index 7b27606c99..f275e7a9a4 100644 --- a/src/upgrades/1.1.0/user_post_count_per_tid.js +++ b/src/upgrades/1.1.0/user_post_count_per_tid.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.1.1/remove_negative_best_posts.js b/src/upgrades/1.1.1/remove_negative_best_posts.js index 22b6bb9ad1..cadf1a397f 100644 --- a/src/upgrades/1.1.1/remove_negative_best_posts.js +++ b/src/upgrades/1.1.1/remove_negative_best_posts.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.1.1/upload_privileges.js b/src/upgrades/1.1.1/upload_privileges.js index d84516efb7..217e6e19fe 100644 --- a/src/upgrades/1.1.1/upload_privileges.js +++ b/src/upgrades/1.1.1/upload_privileges.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.2.0/category_recent_tids.js b/src/upgrades/1.2.0/category_recent_tids.js index 9256cde5f5..3d8d1cdf9c 100644 --- a/src/upgrades/1.2.0/category_recent_tids.js +++ b/src/upgrades/1.2.0/category_recent_tids.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.2.0/edit_delete_deletetopic_privileges.js b/src/upgrades/1.2.0/edit_delete_deletetopic_privileges.js index acc87b7b19..40f8eda0ce 100644 --- a/src/upgrades/1.2.0/edit_delete_deletetopic_privileges.js +++ b/src/upgrades/1.2.0/edit_delete_deletetopic_privileges.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.3.0/favourites_to_bookmarks.js b/src/upgrades/1.3.0/favourites_to_bookmarks.js index 065f02c94a..b1037c860f 100644 --- a/src/upgrades/1.3.0/favourites_to_bookmarks.js +++ b/src/upgrades/1.3.0/favourites_to_bookmarks.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.3.0/sorted_sets_for_post_replies.js b/src/upgrades/1.3.0/sorted_sets_for_post_replies.js index 1cce287829..e5a5506591 100644 --- a/src/upgrades/1.3.0/sorted_sets_for_post_replies.js +++ b/src/upgrades/1.3.0/sorted_sets_for_post_replies.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.4.0/global_and_user_language_keys.js b/src/upgrades/1.4.0/global_and_user_language_keys.js index 20548e6820..3428ad5678 100644 --- a/src/upgrades/1.4.0/global_and_user_language_keys.js +++ b/src/upgrades/1.4.0/global_and_user_language_keys.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.4.0/sorted_set_for_pinned_topics.js b/src/upgrades/1.4.0/sorted_set_for_pinned_topics.js index a82ef80884..c461c8df05 100644 --- a/src/upgrades/1.4.0/sorted_set_for_pinned_topics.js +++ b/src/upgrades/1.4.0/sorted_set_for_pinned_topics.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.4.4/config_urls_update.js b/src/upgrades/1.4.4/config_urls_update.js index 9f4bba93ac..02689ceecb 100644 --- a/src/upgrades/1.4.4/config_urls_update.js +++ b/src/upgrades/1.4.4/config_urls_update.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.4.4/sound_settings.js b/src/upgrades/1.4.4/sound_settings.js index 73b15e881a..57768fcc65 100644 --- a/src/upgrades/1.4.4/sound_settings.js +++ b/src/upgrades/1.4.4/sound_settings.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.4.6/delete_sessions.js b/src/upgrades/1.4.6/delete_sessions.js index 3e143ffed2..571d4e125c 100644 --- a/src/upgrades/1.4.6/delete_sessions.js +++ b/src/upgrades/1.4.6/delete_sessions.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.5.0/allowed_file_extensions.js b/src/upgrades/1.5.0/allowed_file_extensions.js index 158c04ab1d..29e348f16f 100644 --- a/src/upgrades/1.5.0/allowed_file_extensions.js +++ b/src/upgrades/1.5.0/allowed_file_extensions.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.5.0/flags_refactor.js b/src/upgrades/1.5.0/flags_refactor.js index 08fc1831d8..c8be689f18 100644 --- a/src/upgrades/1.5.0/flags_refactor.js +++ b/src/upgrades/1.5.0/flags_refactor.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.5.0/moderation_history_refactor.js b/src/upgrades/1.5.0/moderation_history_refactor.js index 50bb10a7e8..59e10367d8 100644 --- a/src/upgrades/1.5.0/moderation_history_refactor.js +++ b/src/upgrades/1.5.0/moderation_history_refactor.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/1.5.0/post_votes_zset.js b/src/upgrades/1.5.0/post_votes_zset.js index 7feabe8169..4b5795a4b8 100644 --- a/src/upgrades/1.5.0/post_votes_zset.js +++ b/src/upgrades/1.5.0/post_votes_zset.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); 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 index 54a5e80ff2..fc8eb542f6 100644 --- a/src/upgrades/1.5.0/remove_relative_uploaded_profile_cover.js +++ b/src/upgrades/1.5.0/remove_relative_uploaded_profile_cover.js @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database'); diff --git a/src/upgrades/TEMPLATE b/src/upgrades/TEMPLATE index 83cd01586d..9618bc4f9e 100644 --- a/src/upgrades/TEMPLATE +++ b/src/upgrades/TEMPLATE @@ -1,5 +1,3 @@ -/* jslint node: true */ - 'use strict'; var db = require('../../database');