@maioradv/nestjs-core 1.6.2 → 1.6.4

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.
@@ -17,5 +17,13 @@ export declare class S3Service {
17
17
  constructor(config: ConfigService);
18
18
  uploadImage(file: Express.Multer.File): Promise<UploadImageResponse>;
19
19
  removeFile(fileName: string): Promise<import("@aws-sdk/client-s3").DeleteObjectCommandOutput>;
20
+ listFiles(opts?: {
21
+ limit?: number;
22
+ folder?: string;
23
+ }): Promise<import("@aws-sdk/client-s3").ListObjectsCommandOutput>;
24
+ removeFiles(keys: string[]): Promise<import("@aws-sdk/client-s3").DeleteObjectsCommandOutput>;
25
+ clearAll(opts?: {
26
+ folder?: string;
27
+ }): Promise<import("@aws-sdk/client-s3").DeleteObjectsCommandOutput>;
20
28
  private randomString;
21
29
  }
@@ -65,6 +65,39 @@ let S3Service = class S3Service {
65
65
  Key: `${this.sdkConfigs.folder}/${fileName}`,
66
66
  }));
67
67
  }
68
+ async listFiles(opts = {}) {
69
+ return this.client.send(new client_s3_1.ListObjectsCommand({
70
+ Bucket: this.sdkConfigs.bucketName,
71
+ Prefix: opts.folder ?? this.sdkConfigs.folder,
72
+ MaxKeys: opts.limit
73
+ }));
74
+ }
75
+ async removeFiles(keys) {
76
+ return this.client.send(new client_s3_1.DeleteObjectsCommand({
77
+ Bucket: this.sdkConfigs.bucketName,
78
+ Delete: {
79
+ Objects: keys.map(k => ({
80
+ Key: k
81
+ }))
82
+ }
83
+ }));
84
+ }
85
+ async clearAll(opts = {}) {
86
+ const paginator = (0, client_s3_1.paginateListObjectsV2)({ client: this.client }, {
87
+ Bucket: this.sdkConfigs.bucketName,
88
+ Prefix: opts.folder ?? this.sdkConfigs.folder,
89
+ });
90
+ const objectKeys = [];
91
+ for await (const { Contents } of paginator) {
92
+ objectKeys.push(...Contents.map((obj) => ({ Key: obj.Key })));
93
+ }
94
+ return this.client.send(new client_s3_1.DeleteObjectsCommand({
95
+ Bucket: this.sdkConfigs.bucketName,
96
+ Delete: {
97
+ Objects: objectKeys
98
+ }
99
+ }));
100
+ }
68
101
  randomString(length) {
69
102
  let result = '';
70
103
  const characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maioradv/nestjs-core",
3
- "version": "1.6.2",
3
+ "version": "1.6.4",
4
4
  "description": "NestJS helpers by MaiorADV",
5
5
  "repository": "https://github.com/maioradv/nestjs-core.git",
6
6
  "author": "Maior ADV Srl",
@@ -12,6 +12,7 @@
12
12
  "/dist"
13
13
  ],
14
14
  "scripts": {
15
+ "example": "ts-node example/test.ts",
15
16
  "build": "tsc",
16
17
  "publish:npm": "npm publish --access public"
17
18
  },