mirror of
https://github.com/wekan/wekan.git
synced 2025-04-23 05:27:14 -04:00
Move storage names for filesystem and gridfs to constants
This commit is contained in:
parent
99c37bd521
commit
72b8672e62
2 changed files with 13 additions and 10 deletions
|
@ -4,7 +4,7 @@ import { createBucket } from './lib/grid/createBucket';
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { AttachmentStoreStrategyFilesystem, AttachmentStoreStrategyGridFs} from '/models/lib/attachmentStoreStrategy';
|
||||
import FileStoreStrategyFactory, {moveToStorage} from '/models/lib/fileStoreStrategy';
|
||||
import FileStoreStrategyFactory, {moveToStorage, STORAGE_NAME_FILESYSTEM, STORAGE_NAME_GRIDFS} from '/models/lib/fileStoreStrategy';
|
||||
|
||||
let attachmentBucket;
|
||||
if (Meteor.isServer) {
|
||||
|
@ -34,10 +34,10 @@ Attachments = new FilesCollection({
|
|||
onAfterUpload(fileObj) {
|
||||
// current storage is the filesystem, update object and database
|
||||
Object.keys(fileObj.versions).forEach(versionName => {
|
||||
fileObj.versions[versionName].storage = "fs";
|
||||
fileObj.versions[versionName].storage = STORAGE_NAME_FILESYSTEM;
|
||||
});
|
||||
Attachments.update({ _id: fileObj._id }, { $set: { "versions" : fileObj.versions } });
|
||||
moveToStorage(fileObj, "gridfs", fileStoreStrategyFactory);
|
||||
moveToStorage(fileObj, STORAGE_NAME_GRIDFS, fileStoreStrategyFactory);
|
||||
},
|
||||
interceptDownload(http, fileObj, versionName) {
|
||||
const ret = fileStoreStrategyFactory.getFileStrategy(this, fileObj, versionName).interceptDownload(http);
|
||||
|
|
|
@ -2,6 +2,9 @@ import fs from 'fs';
|
|||
import { createObjectId } from './grid/createObjectId';
|
||||
import { createInterceptDownload } from './fsHooks/createInterceptDownload';
|
||||
|
||||
export const STORAGE_NAME_FILESYSTEM = "fs";
|
||||
export const STORAGE_NAME_GRIDFS = "gridfs";
|
||||
|
||||
/** Factory for FileStoreStrategy */
|
||||
export default class FileStoreStrategyFactory {
|
||||
|
||||
|
@ -28,18 +31,18 @@ export default class FileStoreStrategyFactory {
|
|||
if (!storage) {
|
||||
if (fileObj.meta.source == "import") {
|
||||
// uploaded by import, so it's in GridFS (MongoDB)
|
||||
storage = "gridfs";
|
||||
storage = STORAGE_NAME_GRIDFS;
|
||||
} else {
|
||||
// newly uploaded, so it's at the filesystem
|
||||
storage = "fs";
|
||||
storage = STORAGE_NAME_FILESYSTEM;
|
||||
}
|
||||
}
|
||||
}
|
||||
let ret;
|
||||
if (["fs", "gridfs"].includes(storage)) {
|
||||
if (storage == "fs") {
|
||||
if ([STORAGE_NAME_FILESYSTEM, STORAGE_NAME_GRIDFS].includes(storage)) {
|
||||
if (storage == STORAGE_NAME_FILESYSTEM) {
|
||||
ret = new this.classFileStoreStrategyFilesystem(filesCollection, fileObj, versionName);
|
||||
} else if (storage == "gridfs") {
|
||||
} else if (storage == STORAGE_NAME_GRIDFS) {
|
||||
ret = new this.classFileStoreStrategyGridFs(this.gridFsBucket, filesCollection, fileObj, versionName);
|
||||
}
|
||||
}
|
||||
|
@ -185,7 +188,7 @@ export class FileStoreStrategyGridFs extends FileStoreStrategy {
|
|||
* @return the storage name
|
||||
*/
|
||||
getStorageName() {
|
||||
return "gridfs";
|
||||
return STORAGE_NAME_GRIDFS;
|
||||
}
|
||||
|
||||
/** returns the GridFS Object-Id
|
||||
|
@ -255,7 +258,7 @@ export class FileStoreStrategyFilesystem extends FileStoreStrategy {
|
|||
* @return the storage name
|
||||
*/
|
||||
getStorageName() {
|
||||
return "fs";
|
||||
return STORAGE_NAME_FILESYSTEM;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue