mirror of
https://github.com/wekan/wekan.git
synced 2026-01-06 01:28:49 +01:00
Multi-File Storage.
Thanks to mfilser ! Related https://github.com/wekan/wekan/pull/4484 Merge branch 'master' into upgrade-meteor
This commit is contained in:
commit
68e8155805
29 changed files with 921 additions and 276 deletions
|
|
@ -1,25 +1,24 @@
|
|||
import { Meteor } from 'meteor/meteor';
|
||||
import { FilesCollection } from 'meteor/ostrio:files';
|
||||
import path from 'path';
|
||||
import { createBucket } from './lib/grid/createBucket';
|
||||
import { createOnAfterUpload } from './lib/fsHooks/createOnAfterUpload';
|
||||
import { createInterceptDownload } from './lib/fsHooks/createInterceptDownload';
|
||||
import { createOnAfterRemove } from './lib/fsHooks/createOnAfterRemove';
|
||||
import FileStoreStrategyFactory, { FileStoreStrategyFilesystem, FileStoreStrategyGridFs} from '/models/lib/fileStoreStrategy';
|
||||
|
||||
let avatarsBucket;
|
||||
let storagePath;
|
||||
if (Meteor.isServer) {
|
||||
avatarsBucket = createBucket('avatars');
|
||||
storagePath = path.join(process.env.WRITABLE_PATH, 'avatars');
|
||||
}
|
||||
|
||||
const fileStoreStrategyFactory = new FileStoreStrategyFactory(FileStoreStrategyFilesystem, storagePath, FileStoreStrategyGridFs, avatarsBucket);
|
||||
|
||||
Avatars = new FilesCollection({
|
||||
debug: false, // Change to `true` for debugging
|
||||
collectionName: 'avatars',
|
||||
allowClientCode: true,
|
||||
storagePath() {
|
||||
if (process.env.WRITABLE_PATH) {
|
||||
return path.join(process.env.WRITABLE_PATH, 'uploads', 'avatars');
|
||||
}
|
||||
return path.normalize(`assets/app/uploads/${this.collectionName}`);;
|
||||
const ret = fileStoreStrategyFactory.storagePath;
|
||||
return ret;
|
||||
},
|
||||
onBeforeUpload(file) {
|
||||
if (file.size <= 72000 && file.type.startsWith('image/')) {
|
||||
|
|
@ -27,9 +26,24 @@ Avatars = new FilesCollection({
|
|||
}
|
||||
return 'avatar-too-big';
|
||||
},
|
||||
onAfterUpload: createOnAfterUpload(avatarsBucket),
|
||||
interceptDownload: createInterceptDownload(avatarsBucket),
|
||||
onAfterRemove: createOnAfterRemove(avatarsBucket),
|
||||
onAfterUpload(fileObj) {
|
||||
// current storage is the filesystem, update object and database
|
||||
Object.keys(fileObj.versions).forEach(versionName => {
|
||||
fileObj.versions[versionName].storage = "fs";
|
||||
});
|
||||
Avatars.update({ _id: fileObj._id }, { $set: { "versions" : fileObj.versions } });
|
||||
},
|
||||
interceptDownload(http, fileObj, versionName) {
|
||||
const ret = fileStoreStrategyFactory.getFileStrategy(fileObj, versionName).interceptDownload(http, this.cacheControl);
|
||||
return ret;
|
||||
},
|
||||
onAfterRemove(files) {
|
||||
files.forEach(fileObj => {
|
||||
Object.keys(fileObj.versions).forEach(versionName => {
|
||||
fileStoreStrategyFactory.getFileStrategy(fileObj, versionName).onAfterRemove();
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
function isOwner(userId, doc) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue