diff --git a/app/assets/javascripts/discourse/components/avatar-uploader.js.es6 b/app/assets/javascripts/discourse/components/avatar-uploader.js.es6 index d5e983ccf8c..b4d4073c5d1 100644 --- a/app/assets/javascripts/discourse/components/avatar-uploader.js.es6 +++ b/app/assets/javascripts/discourse/components/avatar-uploader.js.es6 @@ -17,12 +17,12 @@ export default Em.Component.extend(UploadMixin, { // indeed, the server gives us back the url to the file we've just uploaded // often, this file is not a square, so we need to crop it properly // this will also capture the first frame of animated avatars when they're not allowed - Discourse.Utilities.cropAvatar(upload.url, upload.original_filename).then(avatarTemplate => { + Discourse.Utilities.cropAvatar(upload.url).then(avatarTemplate => { this.set("uploadedAvatarTemplate", avatarTemplate); // indicates the users is using an uploaded avatar (must happen after cropping, otherwise // we will attempt to load an invalid avatar and cache a redirect to old one, uploadedAvatarTemplate - // trumps over custom avatar upload id) + // trumps over custom_avatar_upload_id) this.set("custom_avatar_upload_id", upload.id); }); diff --git a/app/assets/javascripts/discourse/controllers/edit-category.js.es6 b/app/assets/javascripts/discourse/controllers/edit-category.js.es6 index ca15eda2496..52e0e45bc2c 100644 --- a/app/assets/javascripts/discourse/controllers/edit-category.js.es6 +++ b/app/assets/javascripts/discourse/controllers/edit-category.js.es6 @@ -5,7 +5,6 @@ import { categoryBadgeHTML } from 'discourse/helpers/category-link'; // Modal for editing / creating a category export default ObjectController.extend(ModalFunctionality, { foregroundColors: ['FFFFFF', '000000'], - categoryUploadUrl: '/uploads', editingPermissions: false, selectedTab: null, saving: false, diff --git a/app/assets/javascripts/discourse/lib/utilities.js b/app/assets/javascripts/discourse/lib/utilities.js index d85e474132e..76b24f5007f 100644 --- a/app/assets/javascripts/discourse/lib/utilities.js +++ b/app/assets/javascripts/discourse/lib/utilities.js @@ -310,11 +310,11 @@ Discourse.Utilities = { @method cropAvatar @param {String} url The url of the avatar - @param {String} fileType The file type of the uploaded file @returns {Promise} a promise that will eventually be the cropped avatar. **/ - cropAvatar: function(url, fileType) { - if (Discourse.SiteSettings.allow_animated_avatars && fileType === "image/gif") { + cropAvatar: function(url) { + const extension = /\.(\w{2,})$/.exec(url)[1]; + if (Discourse.SiteSettings.allow_animated_avatars && extension === "gif") { // can't crop animated gifs... let the browser stretch the gif return Ember.RSVP.resolve(url); } else { @@ -344,7 +344,7 @@ Discourse.Utilities = { // draw the image into the canvas canvas.getContext("2d").drawImage(img, x, y, dimension, dimension, 0, 0, size, size); // retrieve the image from the canvas - resolve(canvas.toDataURL(fileType)); + resolve(canvas.toDataURL("image/" + extension)); }; // launch the onload event image.src = url; diff --git a/test/javascripts/lib/utilities-test.js.es6 b/test/javascripts/lib/utilities-test.js.es6 index 75d4f14b869..47088b30351 100644 --- a/test/javascripts/lib/utilities-test.js.es6 +++ b/test/javascripts/lib/utilities-test.js.es6 @@ -177,7 +177,7 @@ module("Discourse.Utilities.cropAvatar with animated avatars", { asyncTestDiscourse("cropAvatar", function() { expect(1); - utils.cropAvatar("/path/to/avatar.gif", "image/gif").then(function(avatarTemplate) { + utils.cropAvatar("/path/to/avatar.gif").then(function(avatarTemplate) { equal(avatarTemplate, "/path/to/avatar.gif", "returns the url to the gif when animated gif are enabled"); start(); });