@quatrain/storage-s3 1.1.12 → 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.config.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,21 +59,27 @@ 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) {
61
81
  return __awaiter(this, void 0, void 0, function* () {
62
- storage_1.Storage.debug(`Copying file ${file.ref} to ${destFile.ref}`);
82
+ storage_1.Storage.debug(`Copying file ${file.bucket}/${file.ref} to ${file.bucket}/${destFile.ref}`);
63
83
  const command = new client_s3_1.CopyObjectCommand({
64
84
  CopySource: encodeURI(`${file.bucket}/${file.ref}`),
65
85
  Bucket: file.bucket,
@@ -83,7 +103,7 @@ class S3StorageAdapter extends storage_1.AbstractStorageAdapter {
83
103
  move(file, destFile) {
84
104
  return __awaiter(this, void 0, void 0, function* () {
85
105
  try {
86
- storage_1.Storage.debug(`Moving file from ${file.ref} to ${destFile.ref}`);
106
+ storage_1.Storage.debug(`Moving file ${file.bucket}/${file.ref} to ${file.bucket}/${destFile.ref}`);
87
107
  yield this.copy(file, destFile);
88
108
  yield this.delete(file);
89
109
  }
@@ -100,7 +120,7 @@ class S3StorageAdapter extends storage_1.AbstractStorageAdapter {
100
120
  Bucket: file.bucket,
101
121
  Key: encodeURI(file.ref),
102
122
  });
103
- storage_1.Storage.debug(`Creating public url for ${file.ref}`);
123
+ storage_1.Storage.debug(`Creating public url for ${file.bucket}/${file.ref}`);
104
124
  const url = yield (0, s3_request_presigner_1.getSignedUrl)(this._client, command, { expiresIn });
105
125
  return { url, expiresIn };
106
126
  });
@@ -108,7 +128,7 @@ class S3StorageAdapter extends storage_1.AbstractStorageAdapter {
108
128
  delete(file) {
109
129
  var _a;
110
130
  return __awaiter(this, void 0, void 0, function* () {
111
- storage_1.Storage.debug(`Deleting file ${file.ref}`);
131
+ storage_1.Storage.debug(`Deleting file ${file.bucket}/${file.ref}`);
112
132
  const command = new client_s3_1.DeleteObjectCommand({
113
133
  Bucket: file.bucket,
114
134
  Key: file.ref,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/storage-s3",
3
- "version": "1.1.12",
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",
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "@aws-sdk/client-s3": "^3.337.0",
26
26
  "@aws-sdk/s3-request-presigner": "^3.342.0",
27
- "@quatrain/storage": "^1.1.12",
27
+ "@quatrain/storage": "^1.1.16",
28
28
  "fs-extra": "^11.2.0"
29
29
  },
30
30
  "scripts": {