@quatrain/storage-s3 1.1.25 → 1.2.1

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,7 +17,7 @@ export declare class S3StorageAdapter extends AbstractStorageAdapter {
17
17
  * @returns
18
18
  */
19
19
  move(file: FileType, destFile: FileType): Promise<FileType>;
20
- getUrl(file: FileType, expiresIn?: number): Promise<{
20
+ getUrl(file: FileType, expiresIn?: number, action?: any, extra?: any): Promise<{
21
21
  url: string;
22
22
  expiresIn: number;
23
23
  }>;
@@ -115,11 +115,16 @@ class S3StorageAdapter extends storage_1.AbstractStorageAdapter {
115
115
  });
116
116
  }
117
117
  getUrl(file_1) {
118
- return __awaiter(this, arguments, void 0, function* (file, expiresIn = 3600) {
119
- const command = new client_s3_1.GetObjectCommand({
118
+ return __awaiter(this, arguments, void 0, function* (file, expiresIn = 3600, action = 'read', extra = {}) {
119
+ const commandArgs = {
120
120
  Bucket: file.bucket,
121
121
  Key: encodeURI(file.ref),
122
- });
122
+ };
123
+ const cacheControl = extra.cacheControl || (this._params.config.publicCacheDuration ? `max-age=${this._params.config.publicCacheDuration}` : undefined);
124
+ if (cacheControl) {
125
+ commandArgs.ResponseCacheControl = cacheControl;
126
+ }
127
+ const command = new client_s3_1.GetObjectCommand(commandArgs);
123
128
  storage_1.Storage.debug(`Creating public url for ${file.bucket}/${file.ref}`);
124
129
  const url = yield (0, s3_request_presigner_1.getSignedUrl)(this._client, command, { expiresIn });
125
130
  return { url, expiresIn };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/storage-s3",
3
- "version": "1.1.25",
3
+ "version": "1.2.1",
4
4
  "description": "Storage adapter for S3 compatible services",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -33,7 +33,7 @@
33
33
  "dependencies": {
34
34
  "@aws-sdk/client-s3": "^3.337.0",
35
35
  "@aws-sdk/s3-request-presigner": "^3.342.0",
36
- "@quatrain/storage": "^1.1.34",
36
+ "@quatrain/storage": "^1.2.1",
37
37
  "fs-extra": "^11.2.0"
38
38
  },
39
39
  "scripts": {
@@ -41,5 +41,8 @@
41
41
  "build": "tsc",
42
42
  "wbuild": "tsc --watch",
43
43
  "bump-to": "yarn version"
44
+ },
45
+ "typedoc": {
46
+ "entryPoint": "src/index.ts"
44
47
  }
45
48
  }
@@ -141,11 +141,19 @@ export class S3StorageAdapter extends AbstractStorageAdapter {
141
141
  return destFile
142
142
  }
143
143
 
144
- async getUrl(file: FileType, expiresIn = 3600) {
145
- const command = new GetObjectCommand({
144
+ async getUrl(file: FileType, expiresIn = 3600, action: any = 'read', extra: any = {}) {
145
+ const commandArgs: any = {
146
146
  Bucket: file.bucket,
147
147
  Key: encodeURI(file.ref),
148
- })
148
+ }
149
+
150
+ const cacheControl = extra.cacheControl || (this._params.config.publicCacheDuration ? `max-age=${this._params.config.publicCacheDuration}` : undefined)
151
+
152
+ if (cacheControl) {
153
+ commandArgs.ResponseCacheControl = cacheControl
154
+ }
155
+
156
+ const command = new GetObjectCommand(commandArgs)
149
157
  Storage.debug(`Creating public url for ${file.bucket}/${file.ref}`)
150
158
  const url = await getSignedUrl(this._client, command, { expiresIn })
151
159
  return { url, expiresIn }