@quatrain/storage-s3 1.1.11 → 1.1.13

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.
@@ -11,13 +11,21 @@ export declare class S3StorageAdapter extends AbstractStorageAdapter {
11
11
  streamToBuffer(stream: Stream): Promise<Buffer>;
12
12
  create(file: FileType, stream: Readable): Promise<FileType>;
13
13
  copy(file: FileType, destFile: FileType): Promise<void>;
14
- move(file: FileType, destFile: FileType): Promise<void>;
14
+ /**
15
+ * Move file to given destination
16
+ * There is no native command in AWS SDK for this, we need to copy then delete source media
17
+ * @param file
18
+ * @param destFile
19
+ * @returns
20
+ */
21
+ move(file: FileType, destFile: FileType): Promise<FileType>;
15
22
  getUrl(file: FileType, expiresIn?: number): Promise<{
16
23
  url: string;
17
24
  expiresIn: number;
18
25
  }>;
19
26
  delete(file: FileType): Promise<boolean>;
20
27
  getReadable(file: FileType): Promise<Readable>;
28
+ getMetaData(file: FileType): Promise<FileType>;
21
29
  stream(file: FileType, res: any): Promise<any>;
22
30
  download(file: FileType, meta: DownloadFileMetaType): Promise<string>;
23
31
  getUploadUrl(file: FileType, expiresIn?: number): Promise<FileResponseLinkType>;
@@ -28,7 +28,7 @@ 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.endpoint || this._params.region}`);
32
32
  }
33
33
  getDriver() {
34
34
  return this._client;
@@ -59,7 +59,7 @@ class S3StorageAdapter extends storage_1.AbstractStorageAdapter {
59
59
  }
60
60
  copy(file, destFile) {
61
61
  return __awaiter(this, void 0, void 0, function* () {
62
- storage_1.Storage.debug(`Copying file ${file.ref} to ${destFile.ref}`);
62
+ storage_1.Storage.debug(`Copying file ${file.bucket}/${file.ref} to ${file.bucket}/${destFile.ref}`);
63
63
  const command = new client_s3_1.CopyObjectCommand({
64
64
  CopySource: encodeURI(`${file.bucket}/${file.ref}`),
65
65
  Bucket: file.bucket,
@@ -73,15 +73,25 @@ class S3StorageAdapter extends storage_1.AbstractStorageAdapter {
73
73
  }
74
74
  });
75
75
  }
76
+ /**
77
+ * Move file to given destination
78
+ * There is no native command in AWS SDK for this, we need to copy then delete source media
79
+ * @param file
80
+ * @param destFile
81
+ * @returns
82
+ */
76
83
  move(file, destFile) {
77
84
  return __awaiter(this, void 0, void 0, function* () {
78
85
  try {
86
+ storage_1.Storage.debug(`Moving file ${file.bucket}/${file.ref} to ${file.bucket}/${destFile.ref}`);
79
87
  yield this.copy(file, destFile);
80
88
  yield this.delete(file);
81
89
  }
82
90
  catch (err) {
91
+ storage_1.Storage.error(`Failed to move file from ${file.ref} to ${destFile.ref}: ${err.message}`);
83
92
  console.log(err);
84
93
  }
94
+ return destFile;
85
95
  });
86
96
  }
87
97
  getUrl(file, expiresIn = 3600) {
@@ -90,7 +100,7 @@ class S3StorageAdapter extends storage_1.AbstractStorageAdapter {
90
100
  Bucket: file.bucket,
91
101
  Key: encodeURI(file.ref),
92
102
  });
93
- storage_1.Storage.debug(`Creating public url for ${file.ref}`);
103
+ storage_1.Storage.debug(`Creating public url for ${file.bucket}/${file.ref}`);
94
104
  const url = yield (0, s3_request_presigner_1.getSignedUrl)(this._client, command, { expiresIn });
95
105
  return { url, expiresIn };
96
106
  });
@@ -98,7 +108,7 @@ class S3StorageAdapter extends storage_1.AbstractStorageAdapter {
98
108
  delete(file) {
99
109
  var _a;
100
110
  return __awaiter(this, void 0, void 0, function* () {
101
- storage_1.Storage.log(`Deleting file ${file.ref}`);
111
+ storage_1.Storage.debug(`Deleting file ${file.bucket}/${file.ref}`);
102
112
  const command = new client_s3_1.DeleteObjectCommand({
103
113
  Bucket: file.bucket,
104
114
  Key: file.ref,
@@ -125,6 +135,17 @@ class S3StorageAdapter extends storage_1.AbstractStorageAdapter {
125
135
  return readable;
126
136
  });
127
137
  }
138
+ getMetaData(file) {
139
+ return __awaiter(this, void 0, void 0, function* () {
140
+ const command = new client_s3_1.HeadObjectCommand({
141
+ Bucket: file.bucket,
142
+ Key: file.ref,
143
+ });
144
+ const item = yield this._client.send(command);
145
+ const meta = Object.assign(Object.assign({}, file), { contentType: item.ContentType, size: item.ContentLength, lastModified: item.LastModified });
146
+ return meta;
147
+ });
148
+ }
128
149
  stream(file, res) {
129
150
  var _a;
130
151
  return __awaiter(this, void 0, void 0, function* () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/storage-s3",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "description": "Storage adapter for S3 compatible services",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -24,14 +24,18 @@
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.11",
27
+ "@quatrain/storage": "^1.1.16",
28
28
  "fs-extra": "^11.2.0"
29
29
  },
30
30
  "scripts": {
31
- "test": "tsc && jest --verbose",
31
+ "test-ci": "jest --runInBand",
32
32
  "build": "tsc",
33
33
  "wbuild": "tsc --watch",
34
34
  "bump-to": "yarn version",
35
- "publish": "yarn build && yarn npm publish --access public"
35
+ "hash": "node ../../bin/hashFolder.js",
36
+ "hash:persist": "yarn hash > .hash_latest.txt",
37
+ "hash:compare": "yarn hash > .hash_newest.txt && cmp -s .hash_latest.txt .hash_newest.txt",
38
+ "publish": "yarn hash:compare || yarn publish:process",
39
+ "publish:process": "yarn version patch && yarn build && yarn npm publish --access public && yarn hash:persist"
36
40
  }
37
41
  }