@nxtedition/lib 19.1.2 → 19.1.3
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.
- package/couch.js +6 -4
- package/package.json +1 -1
- package/s3.js +18 -11
package/couch.js
CHANGED
|
@@ -930,6 +930,7 @@ class ErrorHandler extends undici.DecoratorHandler {
|
|
|
930
930
|
#opts
|
|
931
931
|
#handler
|
|
932
932
|
#error
|
|
933
|
+
#headers
|
|
933
934
|
|
|
934
935
|
constructor({ opts, handler }) {
|
|
935
936
|
super(handler)
|
|
@@ -949,11 +950,11 @@ class ErrorHandler extends undici.DecoratorHandler {
|
|
|
949
950
|
this.#statusText = statusText
|
|
950
951
|
|
|
951
952
|
if (this.#statusCode < 200 || this.#statusCode > 300) {
|
|
952
|
-
headers = Array.isArray(headers) ? undiciUtil.parseHeaders(headers) : headers
|
|
953
|
+
this.#headers = Array.isArray(headers) ? undiciUtil.parseHeaders(headers) : headers
|
|
953
954
|
|
|
954
955
|
this.#error = new Error(this.#statusText ?? this.#statusCode)
|
|
955
956
|
|
|
956
|
-
this.#contentType = parseContentType(headers['content-type'] ?? '')?.type
|
|
957
|
+
this.#contentType = parseContentType(this.#headers['content-type'] ?? '')?.type
|
|
957
958
|
if (this.#contentType !== 'application/json' && this.#contentType !== 'plain/text') {
|
|
958
959
|
throw this.#error
|
|
959
960
|
}
|
|
@@ -1003,10 +1004,11 @@ class ErrorHandler extends undici.DecoratorHandler {
|
|
|
1003
1004
|
} else if (this.#contentType === 'plain/text') {
|
|
1004
1005
|
throw Object.assign(this.#error, {
|
|
1005
1006
|
data: {
|
|
1006
|
-
|
|
1007
|
-
|
|
1007
|
+
ureq: this.#opts,
|
|
1008
|
+
ures: {
|
|
1008
1009
|
body: this.#str,
|
|
1009
1010
|
statusCode: this.#statusCode,
|
|
1011
|
+
headers: this.#headers,
|
|
1010
1012
|
},
|
|
1011
1013
|
},
|
|
1012
1014
|
})
|
package/package.json
CHANGED
package/s3.js
CHANGED
|
@@ -4,11 +4,24 @@ import tp from 'node:timers/promises'
|
|
|
4
4
|
import AWS from '@aws-sdk/client-s3'
|
|
5
5
|
import PQueue from 'p-queue'
|
|
6
6
|
|
|
7
|
-
const CONTENT_MD5_EXPR = /^[A-F0-9]{32}$/i
|
|
8
|
-
const CONTENT_LENGTH_EXPR = /^\d+$/i
|
|
9
|
-
|
|
10
7
|
const queue = new PQueue({ concurrency: 8 })
|
|
11
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Uploads a file to S3 using multipart upload.
|
|
11
|
+
*
|
|
12
|
+
* @param {Object} options - The options for the upload.
|
|
13
|
+
* @param {AWS.S3} options.client - The S3 client.
|
|
14
|
+
* @param {AbortSignal} options.signal - The signal to abort the upload.
|
|
15
|
+
* @param {Object} options.logger - The logger to use.
|
|
16
|
+
* @param {number} [options.partSize=16e6] - The size of each part in the multipart upload.
|
|
17
|
+
* @param {Object} options.params - The parameters for the upload.
|
|
18
|
+
* @param {Buffer|NodeJS.ReadStream} options.params.Body - The data to upload.
|
|
19
|
+
* @param {string} options.params.Key - The key of the object.
|
|
20
|
+
* @param {string} options.params.Bucket - The name of the bucket.
|
|
21
|
+
* @param {string} [options.params.ContentMD5] - The MD5 hash of the object as base64 string.
|
|
22
|
+
* @param {number} [options.params.ContentLength] - The length of the object.
|
|
23
|
+
* @returns {Promise<Object>} The result of the upload.
|
|
24
|
+
*/
|
|
12
25
|
export async function upload({ client: s3, signal, logger, partSize = 16e6, params }) {
|
|
13
26
|
if (s3 == null) {
|
|
14
27
|
throw new Error('Invalid client')
|
|
@@ -24,13 +37,7 @@ export async function upload({ client: s3, signal, logger, partSize = 16e6, para
|
|
|
24
37
|
|
|
25
38
|
const { Body, Key, Bucket, ContentMD5, ContentLength } = params ?? {}
|
|
26
39
|
|
|
27
|
-
|
|
28
|
-
throw new Error(`Invalid ContentMD5: ${ContentMD5}`)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (ContentLength != null && !CONTENT_LENGTH_EXPR.test(ContentLength)) {
|
|
32
|
-
throw new Error(`Invalid ContentLength: ${ContentLength}`)
|
|
33
|
-
}
|
|
40
|
+
// TODO (fix): Valdate ContentMD & ContentLength
|
|
34
41
|
|
|
35
42
|
const promises = []
|
|
36
43
|
|
|
@@ -190,7 +197,7 @@ export async function upload({ client: s3, signal, logger, partSize = 16e6, para
|
|
|
190
197
|
}
|
|
191
198
|
|
|
192
199
|
const size = ContentLength != null ? Number(ContentLength) : null
|
|
193
|
-
const hash = ContentMD5
|
|
200
|
+
const hash = ContentMD5 ? Buffer.from(ContentMD5, 'base64').toString('hex') : null
|
|
194
201
|
|
|
195
202
|
if (size != null && size !== result.size) {
|
|
196
203
|
throw new Error(`Expected size ${size} but got ${result.size}`)
|