diff --git a/src/index.ts b/src/index.ts index 8a2dc6f..0584f2d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -103,15 +103,15 @@ export default class MulterGoogleCloudStorage implements multer.StorageEngine { : this.getContentType = opts.contentType || this.getContentType; } - opts.bucket = opts.bucket || process.env.GCS_BUCKET || null; - opts.projectId = opts.projectId || process.env.GCLOUD_PROJECT || null; - opts.keyFilename = opts.keyFilename || process.env.GCS_KEYFILE || null; + const bucket = opts.bucket || process.env.GCS_BUCKET || null; + const projectId = opts.projectId || process.env.GCLOUD_PROJECT || null; + const keyFilename = opts.keyFilename || process.env.GCS_KEYFILE || null; - if (!opts.bucket) { + if (!bucket) { throw new Error('You have to specify bucket for Google Cloud Storage to work.'); } - if (!opts.projectId) { + if (!projectId) { throw new Error('You have to specify project id for Google Cloud Storage to work.'); } @@ -121,12 +121,12 @@ export default class MulterGoogleCloudStorage implements multer.StorageEngine { */ this.gcsStorage = new Storage({ - projectId: opts.projectId, - keyFilename: opts.keyFilename, - credentials: opts.credentials + ...opts, + projectId, + keyFilename, }); - this.gcsBucket = this.gcsStorage.bucket(opts.bucket); + this.gcsBucket = this.gcsStorage.bucket(bucket); this.options = opts; }