diff --git a/index.d.ts b/index.d.ts index 295e0e3..b9ef7d9 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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 { diff --git a/lib/MulterMinIOStorage.js b/lib/MulterMinIOStorage.js index c089200..2d7bb70 100644 --- a/lib/MulterMinIOStorage.js +++ b/lib/MulterMinIOStorage.js @@ -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); @@ -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] }); }); }); @@ -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'); } } diff --git a/package-lock.json b/package-lock.json index 17106e8..1caf425 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1645,6 +1645,15 @@ "integrity": "sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY=", "dev": true }, + "@types/minio": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/@types/minio/-/minio-7.0.6.tgz", + "integrity": "sha512-wSNdxcqse8pHdsIyZcSIbgqZq3qcgdLsvSzp1ZvuxzBb717s7/BvEORiRgkl9r/QDORpoaQGg9vsl387tVtjIA==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/mocha": { "version": "7.0.2", "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-7.0.2.tgz", @@ -1920,6 +1929,12 @@ "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", "dev": true }, + "async": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz", + "integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw==", + "dev": true + }, "async-each": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/async-each/-/async-each-1.0.3.tgz", @@ -2364,6 +2379,28 @@ } } }, + "block-stream2": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/block-stream2/-/block-stream2-2.0.0.tgz", + "integrity": "sha512-1oI+RHHUEo64xomy1ozLgVJetFlHkIfQfJzTBQrj6xWnEMEPooeo2fZoqFjp0yzfHMBrgxwgh70tKp6T17+i3g==", + "dev": true, + "requires": { + "readable-stream": "^3.4.0" + }, + "dependencies": { + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "dev": true, + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } + } + }, "boxen": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/boxen/-/boxen-4.2.0.tgz", @@ -3216,6 +3253,12 @@ "is-symbol": "^1.0.2" } }, + "es6-error": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/es6-error/-/es6-error-4.1.1.tgz", + "integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==", + "dev": true + }, "escape-goat": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/escape-goat/-/escape-goat-2.1.1.tgz", @@ -4606,6 +4649,12 @@ "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", "dev": true }, + "json-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-stream/-/json-stream-1.0.0.tgz", + "integrity": "sha1-GjhU4o0rvuqzHMfd9oPS3cVlJwg=", + "dev": true + }, "json5": { "version": "0.5.1", "resolved": "https://registry.npmjs.org/json5/-/json5-0.5.1.tgz", @@ -4792,6 +4841,21 @@ "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", "dev": true }, + "mime-db": { + "version": "1.44.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", + "integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==", + "dev": true + }, + "mime-types": { + "version": "2.1.27", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz", + "integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==", + "dev": true, + "requires": { + "mime-db": "1.44.0" + } + }, "mimic-fn": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", @@ -4843,6 +4907,25 @@ } } }, + "minio": { + "version": "7.0.16", + "resolved": "https://registry.npmjs.org/minio/-/minio-7.0.16.tgz", + "integrity": "sha512-OgCJ3XVMzukSqoMFBiBDeyz30BxYTBM9yRLVRBCExTb+QKVxJh4DnUOS2/zw7OPeDyXXEvYSzDvg4FkCf1Cxyw==", + "dev": true, + "requires": { + "async": "^3.1.0", + "block-stream2": "^2.0.0", + "es6-error": "^4.1.1", + "json-stream": "^1.0.0", + "lodash": "^4.14.2", + "mime-types": "^2.1.14", + "mkdirp": "^0.5.1", + "querystring": "0.2.0", + "through2": "^3.0.1", + "xml": "^1.0.0", + "xml2js": "^0.4.15" + } + }, "mixin-deep": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.2.tgz", @@ -5555,6 +5638,12 @@ "escape-goat": "^2.0.0" } }, + "querystring": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz", + "integrity": "sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA=", + "dev": true + }, "quick-lru": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-4.0.1.tgz", @@ -6227,6 +6316,12 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true }, + "sax": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", + "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==", + "dev": true + }, "semver": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", @@ -6823,6 +6918,16 @@ "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "dev": true }, + "through2": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/through2/-/through2-3.0.2.tgz", + "integrity": "sha512-enaDQ4MUyP2W6ZyT6EsMzqBPZaM/avg8iuo+l2d3QCs0J+6RaqkHV/2/lOwDTueBHeJ/2LG9lrLW3d5rWPucuQ==", + "dev": true, + "requires": { + "inherits": "^2.0.4", + "readable-stream": "2 || 3" + } + }, "tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", @@ -7392,6 +7497,28 @@ "integrity": "sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q==", "dev": true }, + "xml": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz", + "integrity": "sha1-eLpyAgApxbyHuKgaPPzXS0ovweU=", + "dev": true + }, + "xml2js": { + "version": "0.4.23", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz", + "integrity": "sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==", + "dev": true, + "requires": { + "sax": ">=0.6.0", + "xmlbuilder": "~11.0.0" + } + }, + "xmlbuilder": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", + "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==", + "dev": true + }, "y18n": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", diff --git a/package.json b/package.json index 1e491df..ae5b150 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/src/MulterMinIOStorage.ts b/src/MulterMinIOStorage.ts index b065709..5168b20 100644 --- a/src/MulterMinIOStorage.ts +++ b/src/MulterMinIOStorage.ts @@ -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); @@ -87,6 +88,7 @@ function collect(storage, req, file, cb) { serverSideEncryption: values[7], sseKmsKeyId: values[8], shouldCreateThumbnail: values[9], + shouldCreateFeatured: values[10], }); } ); @@ -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' ); } }