From 116d68b48a2376870aec828d138293296e7fc423 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Thu, 17 Sep 2020 01:57:58 -0500 Subject: [PATCH] fix: user avatar images & upload --- client/components/users/userAvatar.jade | 2 +- client/components/users/userAvatar.js | 20 ++++++++------------ models/avatars.js | 4 ++-- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/client/components/users/userAvatar.jade b/client/components/users/userAvatar.jade index 7ec7d8e13..cbc1c7a9e 100644 --- a/client/components/users/userAvatar.jade +++ b/client/components/users/userAvatar.jade @@ -43,7 +43,7 @@ template(name="changeAvatarPopup") each uploadedAvatars li: a.js-select-avatar .member - img.avatar.avatar-image(src="{{url avatarUrlOptions}}") + img.avatar.avatar-image(src="{{link}}?auth=false&brokenIsFine=true") | {{_ 'uploaded-avatar'}} if isSelected i.fa.fa-check diff --git a/client/components/users/userAvatar.js b/client/components/users/userAvatar.js index 99e5e690a..e5bf7c88e 100644 --- a/client/components/users/userAvatar.js +++ b/client/components/users/userAvatar.js @@ -1,3 +1,5 @@ +import { formatFleURL } from 'meteor/ostrio:files/lib'; + Template.userAvatar.helpers({ userData() { // We need to handle a special case for the search results provided by the @@ -53,21 +55,14 @@ BlazeComponent.extendComponent({ Meteor.subscribe('my-avatars'); }, - avatarUrlOptions() { - return { - auth: false, - brokenIsFine: true, - }; - }, - uploadedAvatars() { - return Avatars.find({ userId: Meteor.userId() }); + return Avatars.find({ userId: Meteor.userId() }).each(); }, isSelected() { const userProfile = Meteor.user().profile; const avatarUrl = userProfile && userProfile.avatarUrl; - const currentAvatarUrl = this.currentData().url(this.avatarUrlOptions()); + const currentAvatarUrl = `${this.currentData().link()}?auth=false&brokenIsFine=true`; return avatarUrl === currentAvatarUrl; }, @@ -104,8 +99,9 @@ BlazeComponent.extendComponent({ ); uploader.on('uploaded', (error, fileRef) => { if (!error) { - self.setAvatar(fileRef.path); - // self.setAvatar(this.currentData().url(this.avatarUrlOptions())); + self.setAvatar( + `${formatFleURL(fileRef)}?auth=false&brokenIsFine=true`, + ); } }); uploader.on('error', (error, fileData) => { @@ -115,7 +111,7 @@ BlazeComponent.extendComponent({ } }, 'click .js-select-avatar'() { - const avatarUrl = this.currentData().url(this.avatarUrlOptions()); + const avatarUrl = `${this.currentData().link()}?auth=false&brokenIsFine=true`; this.setAvatar(avatarUrl); }, 'click .js-select-initials'() { diff --git a/models/avatars.js b/models/avatars.js index c0a8cfcb4..d45dc3df6 100644 --- a/models/avatars.js +++ b/models/avatars.js @@ -15,9 +15,9 @@ Avatars = new FilesCollection({ collectionName: 'avatars', allowClientCode: true, onBeforeUpload(file) { - if (file.size <= 72000 && file.type.startsWith("image/")) { + if (file.size <= 72000 && file.type.startsWith('image/')) { return true; - }; + } return 'avatar-too-big'; }, onAfterUpload: createOnAfterUpload(avatarsBucket),