0.0.3 • Published 2 years ago

dm-ali-oss v0.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Description

a dynamic module for ali oss inject difference instance

Installation

$ npm install dm-ali-oss

Quick Start

async configuration

Like other factory providers, our factory function can be async and can inject dependencies through inject.

  AliOssModule.registerAsync('P1', {
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => {
        return {
          accessKeyId: configService.get('ALI_OSS_ACCESS_KEY_ID'),
          accessKeySecret: configService.get('ALI_OSS_ACCESS_KEY_SECRET'),
          bucket: configService.get('ALI_OSS_BUCKET'),
          region: configService.get('ALI_OSS_REGION'),
          endpoint:configService.get('ALI_OSS_ENDPOINT'),
        };
      },
    }),

then you can inject with the target provider

@Injectable()
export class AppService {
  constructor(@Inject('P1') private readonly aliOssService: AliOssService) {}
  async getHello(): Promise<string> {
    const result = await this.aliOssService.getObject('test/test.txt');
    return result.toString();
  }
}

current AliOssService support method

  • putObject()
  • getObject()
  • putAcl()
  • createBucket()
  • getStream()

you can read details by typings

Test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

License

Nest is MIT licensed.