FIX: cropAvatar

This commit is contained in:
Régis Hanol 2015-05-20 11:32:21 +02:00
parent 8d967d9065
commit 566b267981
4 changed files with 7 additions and 8 deletions

View File

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

View File

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

View File

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

View File

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