mirror of
https://github.com/wekan/wekan.git
synced 2025-04-22 04:57:07 -04:00
Ref: Avatars to use modern gridfs
This commit is contained in:
parent
96f8b5c9f4
commit
1ae5bc482b
1 changed files with 20 additions and 18 deletions
|
@ -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;
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue