Skip to content

Commit

Permalink
add option shouldCreateFeatured
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangnguyen1247 committed Sep 2, 2020
1 parent 87f35f6 commit e7f67e1
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 4 deletions.
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface Options {
cacheControl?: ((req: Express.Request, file: Express.Multer.File, callback: (error: any, cacheControl?: string) => void) => void) | string;
serverSideEncryption?: ((req: Express.Request, file: Express.Multer.File, callback: (error: any, serverSideEncryption?: string) => void) => void) | string;
shouldCreateThumnail?: boolean,
shouldCreateFeatured?: boolean,
}

declare global {
Expand Down
24 changes: 21 additions & 3 deletions lib/MulterMinIOStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function autoContentType(req, file, cb) {
}

function collect(storage, req, file, cb) {
(0, _runParallel["default"])([storage.getBucket.bind(storage, req, file), storage.getKey.bind(storage, req, file), storage.getAcl.bind(storage, req, file), storage.getMetadata.bind(storage, req, file), storage.getCacheControl.bind(storage, req, file), storage.getContentDisposition.bind(storage, req, file), storage.getStorageClass.bind(storage, req, file), storage.getSSE.bind(storage, req, file), storage.getSSEKMS.bind(storage, req, file), storage.getShouldCreateThumbnail.bind(storage, req, file)], function (err, values) {
(0, _runParallel["default"])([storage.getBucket.bind(storage, req, file), storage.getKey.bind(storage, req, file), storage.getAcl.bind(storage, req, file), storage.getMetadata.bind(storage, req, file), storage.getCacheControl.bind(storage, req, file), storage.getContentDisposition.bind(storage, req, file), storage.getStorageClass.bind(storage, req, file), storage.getSSE.bind(storage, req, file), storage.getSSEKMS.bind(storage, req, file), storage.getShouldCreateThumbnail.bind(storage, req, file), storage.getShouldCreateFeatured.bind(storage, req, file)], function (err, values) {
if (err) return cb(err);
storage.getContentType(req, file, function (err, contentType, replacementStream) {
if (err) return cb(err);
Expand All @@ -82,7 +82,8 @@ function collect(storage, req, file, cb) {
replacementStream: replacementStream,
serverSideEncryption: values[7],
sseKmsKeyId: values[8],
shouldCreateThumbnail: values[9]
shouldCreateThumbnail: values[9],
shouldCreateFeatured: values[10]
});
});
});
Expand Down Expand Up @@ -269,7 +270,24 @@ function MinIOStorage(opts) {
break;

default:
throw new TypeError('Expected opts.shouldCreateThumbnail to be undefined, string, or function');
throw new TypeError('Expected opts.shouldCreateThumbnail to be undefined, boolean, or function');
}

switch ((0, _typeof2["default"])(opts.shouldCreateFeatured)) {
case 'function':
this.getShouldCreateFeatured = opts.shouldCreateFeatured;
break;

case 'boolean':
this.getShouldCreateFeatured = staticValue(opts.shouldCreateFeatured);
break;

case 'undefined':
this.getShouldCreateFeatured = false;
break;

default:
throw new TypeError('Expected opts.shouldCreateFeatured to be undefined, boolean, or function');
}
}

Expand Down
127 changes: 127 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@babel/preset-typescript": "^7.10.1",
"@babel/runtime": "^7.11.2",
"@types/chai": "^4.2.11",
"@types/minio": "^7.0.6",
"@types/mocha": "^7.0.2",
"@types/node": "^12.7.4",
"babel-plugin-module-resolver": "^4.0.0",
Expand All @@ -45,6 +46,7 @@
"chai-as-promised": "^7.1.1",
"cross-env": "^7.0.2",
"gts": "^2.0.2",
"minio": "^7.0.16",
"mocha": "^8.1.2",
"prettier": "^2.1.1",
"rimraf": "^3.0.2",
Expand Down
20 changes: 19 additions & 1 deletion src/MulterMinIOStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function collect(storage, req, file, cb) {
storage.getSSE.bind(storage, req, file),
storage.getSSEKMS.bind(storage, req, file),
storage.getShouldCreateThumbnail.bind(storage, req, file),
storage.getShouldCreateFeatured.bind(storage, req, file),
],
(err, values) => {
if (err) return cb(err);
Expand All @@ -87,6 +88,7 @@ function collect(storage, req, file, cb) {
serverSideEncryption: values[7],
sseKmsKeyId: values[8],
shouldCreateThumbnail: values[9],
shouldCreateFeatured: values[10],
});
}
);
Expand Down Expand Up @@ -265,7 +267,23 @@ function MinIOStorage(opts) {
break;
default:
throw new TypeError(
'Expected opts.shouldCreateThumbnail to be undefined, string, or function'
'Expected opts.shouldCreateThumbnail to be undefined, boolean, or function'
);
}

switch (typeof opts.shouldCreateFeatured) {
case 'function':
this.getShouldCreateFeatured = opts.shouldCreateFeatured;
break;
case 'boolean':
this.getShouldCreateFeatured = staticValue(opts.shouldCreateFeatured);
break;
case 'undefined':
this.getShouldCreateFeatured = false;
break;
default:
throw new TypeError(
'Expected opts.shouldCreateFeatured to be undefined, boolean, or function'
);
}
}
Expand Down

0 comments on commit e7f67e1

Please sign in to comment.