@maioradv/nestjs-core 2.2.9 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,21 +10,20 @@ export type UploadImageResponse = {
10
10
  mimeType: string;
11
11
  size: number;
12
12
  };
13
+ export type S3ServiceOptions = {
14
+ folder?: string;
15
+ limit?: number;
16
+ };
13
17
  export declare class S3Service {
14
18
  private readonly config;
15
19
  readonly client: S3Client;
16
20
  private sdkConfigs;
17
21
  private readonly logger;
18
22
  constructor(config: ConfigService);
19
- uploadImage(file: Express.Multer.File): Promise<UploadImageResponse>;
20
- removeFile(fileName: string): Promise<import("@aws-sdk/client-s3").DeleteObjectCommandOutput>;
21
- listFiles(opts?: {
22
- limit?: number;
23
- folder?: string;
24
- }): Promise<import("@aws-sdk/client-s3").ListObjectsCommandOutput>;
23
+ uploadImage(file: Express.Multer.File, opts?: S3ServiceOptions): Promise<UploadImageResponse>;
24
+ removeFile(fileName: string, opts?: S3ServiceOptions): Promise<import("@aws-sdk/client-s3").DeleteObjectCommandOutput>;
25
+ listFiles(opts?: S3ServiceOptions): Promise<import("@aws-sdk/client-s3").ListObjectsCommandOutput>;
25
26
  removeFiles(keys: string[]): Promise<import("@aws-sdk/client-s3").DeleteObjectsCommandOutput>;
26
- clearAll(opts?: {
27
- folder?: string;
28
- }): Promise<import("@aws-sdk/client-s3").DeleteObjectsCommandOutput>;
27
+ clearAll(opts?: S3ServiceOptions): Promise<import("@aws-sdk/client-s3").DeleteObjectsCommandOutput>;
29
28
  private randomString;
30
29
  }
@@ -30,8 +30,9 @@ let S3Service = class S3Service {
30
30
  }
31
31
  });
32
32
  }
33
- async uploadImage(file) {
33
+ async uploadImage(file, opts = {}) {
34
34
  try {
35
+ const FOLDER = opts.folder ?? this.sdkConfigs.folder;
35
36
  let fileName = `${this.randomString(6)}-${file.originalname}`;
36
37
  /*try {
37
38
  const check = await this.client.send(
@@ -44,14 +45,14 @@ let S3Service = class S3Service {
44
45
  } catch(e) {}*/
45
46
  const response = await this.client.send(new client_s3_1.PutObjectCommand({
46
47
  Bucket: this.sdkConfigs.bucketName,
47
- Key: `${this.sdkConfigs.folder}/${fileName}`,
48
+ Key: `${FOLDER}/${fileName}`,
48
49
  Body: file.buffer,
49
50
  ContentType: file.mimetype
50
51
  }));
51
52
  const size = (0, image_size_1.imageSize)(file.buffer);
52
53
  const checksum = (0, crypto_1.createHash)('md5').update(file.buffer).digest("base64");
53
54
  return {
54
- src: `${this.sdkConfigs.baseUrl}/${this.sdkConfigs.folder}/${fileName}`,
55
+ src: `${this.sdkConfigs.baseUrl}/${FOLDER}/${fileName}`,
55
56
  width: size.width,
56
57
  height: size.height,
57
58
  checksum: checksum,
@@ -65,10 +66,11 @@ let S3Service = class S3Service {
65
66
  throw e;
66
67
  }
67
68
  }
68
- async removeFile(fileName) {
69
+ async removeFile(fileName, opts = {}) {
70
+ const FOLDER = opts.folder ?? this.sdkConfigs.folder;
69
71
  return this.client.send(new client_s3_1.DeleteObjectCommand({
70
72
  Bucket: this.sdkConfigs.bucketName,
71
- Key: `${this.sdkConfigs.folder}/${fileName}`,
73
+ Key: `${FOLDER}/${fileName}`,
72
74
  }));
73
75
  }
74
76
  async listFiles(opts = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maioradv/nestjs-core",
3
- "version": "2.2.9",
3
+ "version": "2.3.0",
4
4
  "description": "NestJS helpers by MaiorADV",
5
5
  "repository": "https://github.com/maioradv/nestjs-core.git",
6
6
  "author": "Maior ADV Srl",