@quatrain/storage-s3 1.1.13 → 1.1.14

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.
@@ -7,6 +7,7 @@ import { S3Client } from '@aws-sdk/client-s3';
7
7
  export declare class S3StorageAdapter extends AbstractStorageAdapter {
8
8
  protected _client: S3Client;
9
9
  constructor(params: StorageParameters);
10
+ test(): Promise<boolean>;
10
11
  getDriver(): S3Client;
11
12
  streamToBuffer(stream: Stream): Promise<Buffer>;
12
13
  create(file: FileType, stream: Readable): Promise<FileType>;
@@ -28,7 +28,21 @@ class S3StorageAdapter extends storage_1.AbstractStorageAdapter {
28
28
  },
29
29
  };
30
30
  this._client = new client_s3_1.S3Client(config);
31
- storage_1.Storage.info(`AWS Storage Adapter initialized in ${this._params.endpoint || this._params.region}`);
31
+ storage_1.Storage.info(`AWS Storage Adapter initialized in ${this._params.config.endpoint || this._params.config.region}`);
32
+ }
33
+ test() {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ try {
36
+ const command = new client_s3_1.ListBucketsCommand();
37
+ const res = yield this._client.send(command);
38
+ //Storage.info(`S3 Buckets: ${JSON.stringify(res.Buckets)}`)
39
+ return true;
40
+ }
41
+ catch (err) {
42
+ storage_1.Storage.error(`Failed to connect to S3: ${err.message}`);
43
+ return false;
44
+ }
45
+ });
32
46
  }
33
47
  getDriver() {
34
48
  return this._client;
@@ -45,16 +59,22 @@ class S3StorageAdapter extends storage_1.AbstractStorageAdapter {
45
59
  }
46
60
  create(file, stream) {
47
61
  return __awaiter(this, void 0, void 0, function* () {
48
- const input = {
49
- Bucket: file.bucket || this._params.config.bucket,
50
- Key: file.ref,
51
- Body: yield this.streamToBuffer(stream),
52
- ContentType: file.contentType,
53
- };
54
- storage_1.Storage.debug(`Uploading ${file.ref} to ${file.bucket}`);
55
- const command = new client_s3_1.PutObjectCommand(input);
56
- yield this._client.send(command);
57
- return file;
62
+ try {
63
+ const input = {
64
+ Bucket: file.bucket || this._params.config.bucket,
65
+ Key: file.ref,
66
+ Body: yield this.streamToBuffer(stream),
67
+ ContentType: file.contentType,
68
+ };
69
+ storage_1.Storage.debug(`Uploading ${file.ref} to ${file.bucket}`);
70
+ const command = new client_s3_1.PutObjectCommand(input);
71
+ yield this._client.send(command);
72
+ return file;
73
+ }
74
+ catch (err) {
75
+ storage_1.Storage.error(`Failed to upload file ${file.ref} to ${file.bucket}: ${err.message}`);
76
+ throw new Error(`Failed to upload file ${file.ref} to ${file.bucket}: ${err.message}`);
77
+ }
58
78
  });
59
79
  }
60
80
  copy(file, destFile) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/storage-s3",
3
- "version": "1.1.13",
3
+ "version": "1.1.14",
4
4
  "description": "Storage adapter for S3 compatible services",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",