Skip to content

Commit

Permalink
feat(config): allow to pass all config options for AWS and S3 instances
Browse files Browse the repository at this point in the history
  • Loading branch information
visurel committed Sep 28, 2020
1 parent 3813c7f commit 3a34c55
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
20 changes: 17 additions & 3 deletions lib/interfaces/multer-extended-s3-options.interface.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
import { LoggerService } from '@nestjs/common';
import { GlobalConfigInstance } from 'aws-sdk/lib/config';
import AWS from 'aws-sdk';

export interface MulterExtendedS3Options {
/**
* AWS Access Key ID
* @deprecated v2 use awsConfig instead
*/
readonly accessKeyId: string;
readonly accessKeyId?: string;
/**
* AWS Secret Access Key
* @deprecated v2 use awsConfig instead
*/
readonly secretAccessKey: string;
readonly secretAccessKey?: string;
/**
* Default region name
* default: us-west-2
* @deprecated v2 use awsConfig instead
*/
readonly region: string;
readonly region?: string;
/**
* AWS Config
*/
readonly awsConfig?: GlobalConfigInstance;
/**
* S3 Config
*/
readonly s3Config?: AWS.S3.Types.ClientConfiguration;
/**
* The name of Amazon S3 bucket
*/
Expand All @@ -30,6 +43,7 @@ export interface MulterExtendedS3Options {
readonly acl?: string;
/**
* AWS Endpoint
* @deprecated v2 use s3Config instead
*/
readonly endpoint?: string;
/**
Expand Down
6 changes: 4 additions & 2 deletions lib/multer-config.loader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AWS from 'aws-sdk';
import { AmazonS3Storage, ImageFileExtensions, MulterExceptions } from './multer-sharp';
import { Injectable, Inject, Logger, BadRequestException, LoggerService } from '@nestjs/common';
import { MulterOptionsFactory, MulterModuleOptions } from '@nestjs/platform-express';
import { BadRequestException, Inject, Injectable, Logger, LoggerService } from '@nestjs/common';
import { MulterModuleOptions, MulterOptionsFactory } from '@nestjs/platform-express';
import { MULTER_EXTENDED_S3_OPTIONS } from './constants';
import { MulterExtendedS3Options } from './interfaces';

Expand All @@ -22,10 +22,12 @@ export class MulterConfigLoader implements MulterS3ConfigService {
accessKeyId: s3Options.accessKeyId,
secretAccessKey: s3Options.secretAccessKey,
region: s3Options.region || MulterConfigLoader.DEFAULT_REGION,
...s3Options.awsConfig,
});

this.S3 = new AWS.S3({
endpoint: s3Options.endpoint,
...s3Options.s3Config,
});
this.logger = s3Options.logger || new Logger(MulterConfigLoader.name);
this.logger.log(JSON.stringify(s3Options));
Expand Down

0 comments on commit 3a34c55

Please sign in to comment.