Skip to content

Commit

Permalink
feat: allow arbitrary StorageOptions to be passed into Storage client
Browse files Browse the repository at this point in the history
  • Loading branch information
alanraison committed Feb 12, 2024
1 parent adc9800 commit b9791de
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}

Expand All @@ -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;
}
Expand Down

0 comments on commit b9791de

Please sign in to comment.