fix: user avatar images & upload

This commit is contained in:
David Arnold 2020-09-17 01:57:58 -05:00
parent 433ab32524
commit 116d68b48a
No known key found for this signature in database
GPG key ID: 6D6A936E69C59D08
3 changed files with 11 additions and 15 deletions

View file

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

View file

@ -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'() {

View file

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