From b9791de9d244f3c7ebcbc161155c54ac77f1c9c9 Mon Sep 17 00:00:00 2001 From: Alan Raison Date: Mon, 12 Feb 2024 16:48:19 +0000 Subject: [PATCH] feat: allow arbitrary StorageOptions to be passed into Storage client --- src/index.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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; }