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