Ref: Avatars to use modern gridfs

This commit is contained in:
David Arnold 2020-09-13 17:05:40 -05:00 committed by Denis Perov
parent 96f8b5c9f4
commit 1ae5bc482b

View file

@ -1,32 +1,34 @@
/*
import { Meteor } from 'meteor/meteor';
import { FilesCollection } from 'meteor/ostrio:files';
import { createBucket } from './lib/grid/createBucket';
import { createOnAfterUpload } from './lib/fsHooks/createOnAfterUpload';
import { createInterceptDownload } from './lib/fsHooks/createInterceptDownload';
import { createOnAfterRemove } from './lib/fsHooks/createOnAfterRemove';
Avatars = new FS.Collection('avatars', {
stores: [new FS.Store.GridFS('avatars')],
filter: {
maxSize: 520000,
allow: {
contentTypes: ['image/*'],
},
const avatarsBucket = createBucket('avatars');
export const Avatars = new FilesCollection({
debug: false, // Change to `true` for debugging
collectionName: 'avatars',
allowClientCode: false,
onBeforeUpload(file) {
if (file.size <= 72000 && file.isImage) return true;
return 'Please upload image, with size equal or less than 72KB';
},
onAfterUpload: createOnAfterUpload(avatarsBucket),
interceptDownload: createInterceptDownload(avatarsBucket),
onAfterRemove: createOnAfterRemove(avatarsBucket),
});
function isOwner(userId, file) {
return userId && userId === file.userId;
function isOwner(userId, doc) {
return userId && userId === doc.userId;
}
Avatars.allow({
insert: isOwner,
update: isOwner,
remove: isOwner,
download() {
return true;
},
fetch: ['userId'],
});
Avatars.files.before.insert((userId, doc) => {
doc.userId = userId;
});
export default Avatars;
*/