@balena/pinejs 15.3.0-build-web-resource-4-a63974e733a2c0a0927f25b954022d36539bdad6-1 → 15.3.0-build-web-resource-4-e9954d761c19f484fa794ae2c5e2b6c91c80c2d6-1
Sign up to get free protection for your applications and to get access to all the features.
- package/.versionbot/CHANGELOG.yml +2 -2
- package/out/server-glue/webresource-handlers/S3Handler.d.ts +2 -0
- package/out/server-glue/webresource-handlers/S3Handler.js +7 -5
- package/out/server-glue/webresource-handlers/S3Handler.js.map +1 -1
- package/package.json +2 -2
- package/src/server-glue/webresource-handlers/S3Handler.ts +16 -7
@@ -1,6 +1,6 @@
|
|
1
1
|
- commits:
|
2
2
|
- subject: Fix getting model with odata name instead of sql name
|
3
|
-
hash:
|
3
|
+
hash: e9954d761c19f484fa794ae2c5e2b6c91c80c2d6
|
4
4
|
body: ""
|
5
5
|
footer:
|
6
6
|
Change-type: minor
|
@@ -44,7 +44,7 @@
|
|
44
44
|
nested: []
|
45
45
|
version: 15.3.0
|
46
46
|
title: ""
|
47
|
-
date: 2023-08-
|
47
|
+
date: 2023-08-11T19:25:46.127Z
|
48
48
|
- commits:
|
49
49
|
- subject: Return a response even when the request resolves to an HTTP error
|
50
50
|
hash: d1d68a068778a617d7b14b12a2657fb44511ee52
|
@@ -7,6 +7,8 @@ export interface S3HandlerProps {
|
|
7
7
|
endpoint: string;
|
8
8
|
bucket: string;
|
9
9
|
maxSize?: number;
|
10
|
+
signedUrlExpireTimeSeconds?: number;
|
11
|
+
signedUrlCacheExpireTimeSeconds?: number;
|
10
12
|
}
|
11
13
|
export declare class S3Handler implements WebResourceHandler {
|
12
14
|
private readonly config;
|
@@ -9,11 +9,6 @@ const crypto_1 = require("crypto");
|
|
9
9
|
const memoize = require("memoizee");
|
10
10
|
class S3Handler {
|
11
11
|
constructor(config) {
|
12
|
-
this.signedUrlExpireTimeSeconds = 86400;
|
13
|
-
this.signedUrlCacheExpireTimeSeconds = 82800;
|
14
|
-
this.cachedGetSignedUrl = memoize(this.s3SignUrl, {
|
15
|
-
maxAge: this.signedUrlCacheExpireTimeSeconds * 1000,
|
16
|
-
});
|
17
12
|
this.config = {
|
18
13
|
region: config.region,
|
19
14
|
credentials: {
|
@@ -23,9 +18,16 @@ class S3Handler {
|
|
23
18
|
endpoint: config.endpoint,
|
24
19
|
forcePathStyle: true,
|
25
20
|
};
|
21
|
+
this.signedUrlExpireTimeSeconds =
|
22
|
+
config.signedUrlExpireTimeSeconds ?? 86400;
|
23
|
+
this.signedUrlCacheExpireTimeSeconds =
|
24
|
+
config.signedUrlCacheExpireTimeSeconds ?? 82800;
|
26
25
|
this.maxFileSize = config.maxSize ?? 52428800;
|
27
26
|
this.bucket = config.bucket;
|
28
27
|
this.client = new client_s3_1.S3Client(this.config);
|
28
|
+
this.cachedGetSignedUrl = memoize(this.s3SignUrl, {
|
29
|
+
maxAge: this.signedUrlCacheExpireTimeSeconds * 1000,
|
30
|
+
});
|
29
31
|
}
|
30
32
|
async handleFile(resource) {
|
31
33
|
let size = 0;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"S3Handler.js","sourceRoot":"","sources":["../../../src/server-glue/webresource-handlers/S3Handler.ts"],"names":[],"mappings":";;;AAAA,gEAOgC;AAChC,kDAM4B;AAC5B,sDAA8C;AAC9C,wEAA6D;AAE7D,mCAAoC;AAEpC,oCAAoC;
|
1
|
+
{"version":3,"file":"S3Handler.js","sourceRoot":"","sources":["../../../src/server-glue/webresource-handlers/S3Handler.ts"],"names":[],"mappings":";;;AAAA,gEAOgC;AAChC,kDAM4B;AAC5B,sDAA8C;AAC9C,wEAA6D;AAE7D,mCAAoC;AAEpC,oCAAoC;AAapC,MAAa,SAAS;IAUrB,YAAY,MAAsB;QACjC,IAAI,CAAC,MAAM,GAAG;YACb,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,WAAW,EAAE;gBACZ,WAAW,EAAE,MAAM,CAAC,SAAS;gBAC7B,eAAe,EAAE,MAAM,CAAC,SAAS;aACjC;YACD,QAAQ,EAAE,MAAM,CA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EAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE;YACzC,SAAS,EAAE,IAAI,CAAC,0BAA0B;SAC1C,CAAC,CAAC;IACJ,CAAC;IAEO,QAAQ,CAAC,GAAW;QAC3B,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;IACxD,CAAC;IAEO,cAAc,CAAC,IAAY;QAClC,MAAM,iBAAiB,GAAG,IAAA,mCAAa,EAAC,IAAI,CAAC,CAAC;QAC9C,OAAO,iBAAiB,CAAC,SAAS,CAAC,iBAAiB,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5E,CAAC;CACD;AA7GD,8BA6GC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@balena/pinejs",
|
3
|
-
"version": "15.3.0-build-web-resource-4-
|
3
|
+
"version": "15.3.0-build-web-resource-4-e9954d761c19f484fa794ae2c5e2b6c91c80c2d6-1",
|
4
4
|
"main": "out/server-glue/module",
|
5
5
|
"repository": "git@github.com:balena-io/pinejs.git",
|
6
6
|
"license": "Apache-2.0",
|
@@ -144,6 +144,6 @@
|
|
144
144
|
"recursive": true
|
145
145
|
},
|
146
146
|
"versionist": {
|
147
|
-
"publishedAt": "2023-08-
|
147
|
+
"publishedAt": "2023-08-11T19:25:46.971Z"
|
148
148
|
}
|
149
149
|
}
|
@@ -27,6 +27,8 @@ export interface S3HandlerProps {
|
|
27
27
|
endpoint: string;
|
28
28
|
bucket: string;
|
29
29
|
maxSize?: number;
|
30
|
+
signedUrlExpireTimeSeconds?: number;
|
31
|
+
signedUrlCacheExpireTimeSeconds?: number;
|
30
32
|
}
|
31
33
|
|
32
34
|
export class S3Handler implements WebResourceHandler {
|
@@ -34,8 +36,8 @@ export class S3Handler implements WebResourceHandler {
|
|
34
36
|
private readonly bucket: string;
|
35
37
|
private readonly maxFileSize: number;
|
36
38
|
|
37
|
-
private readonly signedUrlExpireTimeSeconds
|
38
|
-
private readonly signedUrlCacheExpireTimeSeconds
|
39
|
+
private readonly signedUrlExpireTimeSeconds: number;
|
40
|
+
private readonly signedUrlCacheExpireTimeSeconds: number;
|
39
41
|
|
40
42
|
private client: S3Client;
|
41
43
|
|
@@ -50,9 +52,20 @@ export class S3Handler implements WebResourceHandler {
|
|
50
52
|
forcePathStyle: true,
|
51
53
|
};
|
52
54
|
|
55
|
+
this.signedUrlExpireTimeSeconds =
|
56
|
+
config.signedUrlExpireTimeSeconds ?? 86400; // 24h
|
57
|
+
this.signedUrlCacheExpireTimeSeconds =
|
58
|
+
config.signedUrlCacheExpireTimeSeconds ?? 82800; // 22h
|
59
|
+
|
53
60
|
this.maxFileSize = config.maxSize ?? 52428800;
|
54
61
|
this.bucket = config.bucket;
|
55
62
|
this.client = new S3Client(this.config);
|
63
|
+
|
64
|
+
// Memoize expects maxAge in MS and s3 signing method in seconds.
|
65
|
+
// Normalization to use only seconds and therefore convert here from seconds to MS
|
66
|
+
this.cachedGetSignedUrl = memoize(this.s3SignUrl, {
|
67
|
+
maxAge: this.signedUrlCacheExpireTimeSeconds * 1000,
|
68
|
+
});
|
56
69
|
}
|
57
70
|
|
58
71
|
public async handleFile(resource: IncomingFile): Promise<UploadResponse> {
|
@@ -107,11 +120,7 @@ export class S3Handler implements WebResourceHandler {
|
|
107
120
|
return webResource;
|
108
121
|
}
|
109
122
|
|
110
|
-
|
111
|
-
// Normalization to use only seconds and therefore convert here from seconds to MS
|
112
|
-
private cachedGetSignedUrl = memoize(this.s3SignUrl, {
|
113
|
-
maxAge: this.signedUrlCacheExpireTimeSeconds * 1000,
|
114
|
-
});
|
123
|
+
private cachedGetSignedUrl: (fileKey: string) => Promise<string>;
|
115
124
|
|
116
125
|
private s3SignUrl(fileKey: string): Promise<string> {
|
117
126
|
const command = new GetObjectCommand({
|