mirror of
https://github.com/wekan/wekan.git
synced 2025-12-20 17:30:13 +01: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 fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { AttachmentStoreStrategyFilesystem, AttachmentStoreStrategyGridFs} from '/models/lib/attachmentStoreStrategy';
|
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;
|
let attachmentBucket;
|
||||||
if (Meteor.isServer) {
|
if (Meteor.isServer) {
|
||||||
|
|
@ -34,10 +34,10 @@ Attachments = new FilesCollection({
|
||||||
onAfterUpload(fileObj) {
|
onAfterUpload(fileObj) {
|
||||||
// current storage is the filesystem, update object and database
|
// current storage is the filesystem, update object and database
|
||||||
Object.keys(fileObj.versions).forEach(versionName => {
|
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 } });
|
Attachments.update({ _id: fileObj._id }, { $set: { "versions" : fileObj.versions } });
|
||||||
moveToStorage(fileObj, "gridfs", fileStoreStrategyFactory);
|
moveToStorage(fileObj, STORAGE_NAME_GRIDFS, fileStoreStrategyFactory);
|
||||||
},
|
},
|
||||||
interceptDownload(http, fileObj, versionName) {
|
interceptDownload(http, fileObj, versionName) {
|
||||||
const ret = fileStoreStrategyFactory.getFileStrategy(this, fileObj, versionName).interceptDownload(http);
|
const ret = fileStoreStrategyFactory.getFileStrategy(this, fileObj, versionName).interceptDownload(http);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@ import fs from 'fs';
|
||||||
import { createObjectId } from './grid/createObjectId';
|
import { createObjectId } from './grid/createObjectId';
|
||||||
import { createInterceptDownload } from './fsHooks/createInterceptDownload';
|
import { createInterceptDownload } from './fsHooks/createInterceptDownload';
|
||||||
|
|
||||||
|
export const STORAGE_NAME_FILESYSTEM = "fs";
|
||||||
|
export const STORAGE_NAME_GRIDFS = "gridfs";
|
||||||
|
|
||||||
/** Factory for FileStoreStrategy */
|
/** Factory for FileStoreStrategy */
|
||||||
export default class FileStoreStrategyFactory {
|
export default class FileStoreStrategyFactory {
|
||||||
|
|
||||||
|
|
@ -28,18 +31,18 @@ export default class FileStoreStrategyFactory {
|
||||||
if (!storage) {
|
if (!storage) {
|
||||||
if (fileObj.meta.source == "import") {
|
if (fileObj.meta.source == "import") {
|
||||||
// uploaded by import, so it's in GridFS (MongoDB)
|
// uploaded by import, so it's in GridFS (MongoDB)
|
||||||
storage = "gridfs";
|
storage = STORAGE_NAME_GRIDFS;
|
||||||
} else {
|
} else {
|
||||||
// newly uploaded, so it's at the filesystem
|
// newly uploaded, so it's at the filesystem
|
||||||
storage = "fs";
|
storage = STORAGE_NAME_FILESYSTEM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let ret;
|
let ret;
|
||||||
if (["fs", "gridfs"].includes(storage)) {
|
if ([STORAGE_NAME_FILESYSTEM, STORAGE_NAME_GRIDFS].includes(storage)) {
|
||||||
if (storage == "fs") {
|
if (storage == STORAGE_NAME_FILESYSTEM) {
|
||||||
ret = new this.classFileStoreStrategyFilesystem(filesCollection, fileObj, versionName);
|
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);
|
ret = new this.classFileStoreStrategyGridFs(this.gridFsBucket, filesCollection, fileObj, versionName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -185,7 +188,7 @@ export class FileStoreStrategyGridFs extends FileStoreStrategy {
|
||||||
* @return the storage name
|
* @return the storage name
|
||||||
*/
|
*/
|
||||||
getStorageName() {
|
getStorageName() {
|
||||||
return "gridfs";
|
return STORAGE_NAME_GRIDFS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** returns the GridFS Object-Id
|
/** returns the GridFS Object-Id
|
||||||
|
|
@ -255,7 +258,7 @@ export class FileStoreStrategyFilesystem extends FileStoreStrategy {
|
||||||
* @return the storage name
|
* @return the storage name
|
||||||
*/
|
*/
|
||||||
getStorageName() {
|
getStorageName() {
|
||||||
return "fs";
|
return STORAGE_NAME_FILESYSTEM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue