@milaboratories/pl-drivers 1.11.18 → 1.11.20
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/dist/clients/constructors.cjs +5 -5
- package/dist/clients/constructors.cjs.map +1 -1
- package/dist/clients/constructors.js +5 -5
- package/dist/clients/constructors.js.map +1 -1
- package/dist/clients/download.cjs +29 -5
- package/dist/clients/download.cjs.map +1 -1
- package/dist/clients/download.d.ts +5 -4
- package/dist/clients/download.d.ts.map +1 -1
- package/dist/clients/download.js +30 -6
- package/dist/clients/download.js.map +1 -1
- package/dist/clients/logs.cjs +57 -16
- package/dist/clients/logs.cjs.map +1 -1
- package/dist/clients/logs.d.ts +6 -5
- package/dist/clients/logs.d.ts.map +1 -1
- package/dist/clients/logs.js +58 -17
- package/dist/clients/logs.js.map +1 -1
- package/dist/clients/ls_api.cjs +44 -8
- package/dist/clients/ls_api.cjs.map +1 -1
- package/dist/clients/ls_api.d.ts +4 -4
- package/dist/clients/ls_api.d.ts.map +1 -1
- package/dist/clients/ls_api.js +45 -9
- package/dist/clients/ls_api.js.map +1 -1
- package/dist/clients/progress.cjs +32 -29
- package/dist/clients/progress.cjs.map +1 -1
- package/dist/clients/progress.d.ts +5 -5
- package/dist/clients/progress.d.ts.map +1 -1
- package/dist/clients/progress.js +33 -30
- package/dist/clients/progress.js.map +1 -1
- package/dist/clients/upload.cjs +96 -30
- package/dist/clients/upload.cjs.map +1 -1
- package/dist/clients/upload.d.ts +8 -11
- package/dist/clients/upload.d.ts.map +1 -1
- package/dist/clients/upload.js +97 -31
- package/dist/clients/upload.js.map +1 -1
- package/dist/drivers/download_blob/download_blob.cjs +2 -2
- package/dist/drivers/download_blob/download_blob.cjs.map +1 -1
- package/dist/drivers/download_blob/download_blob.js +1 -1
- package/dist/drivers/download_blob/download_blob.js.map +1 -1
- package/dist/drivers/download_blob/download_blob_task.cjs +5 -5
- package/dist/drivers/download_blob/download_blob_task.cjs.map +1 -1
- package/dist/drivers/download_blob/download_blob_task.js +2 -2
- package/dist/drivers/download_blob/download_blob_task.js.map +1 -1
- package/dist/drivers/download_blob_url/task.cjs +5 -5
- package/dist/drivers/download_blob_url/task.cjs.map +1 -1
- package/dist/drivers/download_blob_url/task.js +2 -2
- package/dist/drivers/download_blob_url/task.js.map +1 -1
- package/dist/drivers/download_url/task.cjs +2 -2
- package/dist/drivers/download_url/task.cjs.map +1 -1
- package/dist/drivers/download_url/task.js +2 -2
- package/dist/drivers/download_url/task.js.map +1 -1
- package/dist/drivers/logs_stream.cjs.map +1 -1
- package/dist/drivers/logs_stream.js.map +1 -1
- package/dist/helpers/download.cjs +5 -24
- package/dist/helpers/download.cjs.map +1 -1
- package/dist/helpers/download.d.ts +0 -13
- package/dist/helpers/download.d.ts.map +1 -1
- package/dist/helpers/download.js +5 -21
- package/dist/helpers/download.js.map +1 -1
- package/dist/helpers/download_errors.cjs +43 -0
- package/dist/helpers/download_errors.cjs.map +1 -0
- package/dist/helpers/download_errors.d.ts +23 -0
- package/dist/helpers/download_errors.d.ts.map +1 -0
- package/dist/helpers/download_errors.js +36 -0
- package/dist/helpers/download_errors.js.map +1 -0
- package/dist/index.cjs +7 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.cjs +2 -2
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.js.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.js +2 -2
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.js.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.cjs +2 -2
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.js.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.js +2 -2
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.js.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.cjs +3 -3
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.js.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.js +3 -3
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.js.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.cjs +6 -6
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.js.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.js +6 -6
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.js.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.cjs +84 -84
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.cjs.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.cjs.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.d.ts +16 -16
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.d.ts.map +1 -0
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.js.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.d.ts +118 -118
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.d.ts.map +1 -0
- package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.js +76 -76
- package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.js.map +1 -0
- package/dist/proto-grpc/google/api/http.d.ts.map +1 -0
- package/dist/{proto → proto-grpc}/google/protobuf/descriptor.d.ts +5 -149
- package/dist/proto-grpc/google/protobuf/descriptor.d.ts.map +1 -0
- package/dist/proto-grpc/google/protobuf/duration.cjs.map +1 -0
- package/dist/proto-grpc/google/protobuf/duration.d.ts.map +1 -0
- package/dist/proto-grpc/google/protobuf/duration.js.map +1 -0
- package/dist/proto-grpc/google/protobuf/timestamp.cjs.map +1 -0
- package/dist/proto-grpc/google/protobuf/timestamp.d.ts.map +1 -0
- package/dist/proto-grpc/google/protobuf/timestamp.js.map +1 -0
- package/dist/proto-rest/downloadapi.d.ts +105 -0
- package/dist/proto-rest/downloadapi.d.ts.map +1 -0
- package/dist/proto-rest/index.d.ts +17 -0
- package/dist/proto-rest/index.d.ts.map +1 -0
- package/dist/proto-rest/lsapi.d.ts +148 -0
- package/dist/proto-rest/lsapi.d.ts.map +1 -0
- package/dist/proto-rest/progressapi.d.ts +159 -0
- package/dist/proto-rest/progressapi.d.ts.map +1 -0
- package/dist/proto-rest/streamingapi.d.ts +469 -0
- package/dist/proto-rest/streamingapi.d.ts.map +1 -0
- package/dist/proto-rest/uploadapi.d.ts +355 -0
- package/dist/proto-rest/uploadapi.d.ts.map +1 -0
- package/package.json +10 -6
- package/src/clients/constructors.ts +11 -11
- package/src/clients/download.ts +34 -11
- package/src/clients/logs.ts +69 -21
- package/src/clients/ls_api.ts +58 -14
- package/src/clients/progress.ts +41 -44
- package/src/clients/upload.ts +117 -53
- package/src/drivers/download_blob/download_blob.ts +1 -1
- package/src/drivers/download_blob/download_blob_task.ts +2 -2
- package/src/drivers/download_blob_url/task.ts +2 -2
- package/src/drivers/download_url/task.ts +2 -2
- package/src/drivers/logs_stream.ts +1 -1
- package/src/drivers/upload.test.ts +6 -25
- package/src/helpers/download.ts +4 -26
- package/src/helpers/download_errors.ts +40 -0
- package/src/index.ts +1 -0
- package/src/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.ts +1 -1
- package/src/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.ts +2 -2
- package/src/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.ts +1 -1
- package/src/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.ts +2 -2
- package/src/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.ts +1 -1
- package/src/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.ts +3 -3
- package/src/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.ts +1 -1
- package/src/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.ts +6 -6
- package/src/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.ts +21 -21
- package/src/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.ts +159 -159
- package/src/{proto → proto-grpc}/google/api/http.ts +1 -1
- package/src/{proto → proto-grpc}/google/protobuf/descriptor.ts +9 -217
- package/src/{proto → proto-grpc}/google/protobuf/duration.ts +1 -1
- package/src/{proto → proto-grpc}/google/protobuf/timestamp.ts +1 -1
- package/src/proto-rest/downloadapi.ts +105 -0
- package/src/proto-rest/index.ts +28 -0
- package/src/proto-rest/lsapi.ts +148 -0
- package/src/proto-rest/progressapi.ts +159 -0
- package/src/proto-rest/streamingapi.ts +469 -0
- package/src/proto-rest/uploadapi.ts +355 -0
- package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.d.ts +0 -53
- package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.cjs.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.cjs.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.js.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.js.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.cjs.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.cjs.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.js.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.js.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.cjs.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.cjs.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.js.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.js.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.cjs.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.cjs.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.js.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.js.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.cjs.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.cjs.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.js.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.js.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts +0 -329
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts +0 -5358
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts +0 -537
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts +0 -87
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts +0 -106
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts +0 -256
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts.map +0 -1
- package/dist/proto/google/api/http.d.ts.map +0 -1
- package/dist/proto/google/protobuf/any.d.ts +0 -181
- package/dist/proto/google/protobuf/any.d.ts.map +0 -1
- package/dist/proto/google/protobuf/descriptor.d.ts.map +0 -1
- package/dist/proto/google/protobuf/duration.cjs.map +0 -1
- package/dist/proto/google/protobuf/duration.d.ts.map +0 -1
- package/dist/proto/google/protobuf/duration.js.map +0 -1
- package/dist/proto/google/protobuf/empty.d.ts +0 -32
- package/dist/proto/google/protobuf/empty.d.ts.map +0 -1
- package/dist/proto/google/protobuf/struct.d.ts +0 -187
- package/dist/proto/google/protobuf/struct.d.ts.map +0 -1
- package/dist/proto/google/protobuf/timestamp.cjs.map +0 -1
- package/dist/proto/google/protobuf/timestamp.d.ts.map +0 -1
- package/dist/proto/google/protobuf/timestamp.js.map +0 -1
- package/dist/proto/google/protobuf/wrappers.d.ts +0 -335
- package/dist/proto/google/protobuf/wrappers.d.ts.map +0 -1
- package/src/proto/github.com/googleapis/googleapis/google/rpc/status.ts +0 -125
- package/src/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.ts +0 -406
- package/src/proto/github.com/milaboratory/pl/plapi/plapiproto/api.ts +0 -14986
- package/src/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.ts +0 -1474
- package/src/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.ts +0 -181
- package/src/proto/github.com/milaboratory/pl/plapi/plapiproto/import.ts +0 -251
- package/src/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.ts +0 -693
- package/src/proto/google/protobuf/any.ts +0 -326
- package/src/proto/google/protobuf/empty.ts +0 -94
- package/src/proto/google/protobuf/struct.ts +0 -484
- package/src/proto/google/protobuf/wrappers.ts +0 -785
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.cjs +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.js +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.cjs +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.js +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.cjs +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.js +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.cjs +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.js +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.cjs +0 -0
- /package/dist/{proto → proto-grpc}/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.js +0 -0
- /package/dist/{proto → proto-grpc}/google/api/http.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/duration.cjs +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/duration.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/duration.js +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/timestamp.cjs +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/timestamp.d.ts +0 -0
- /package/dist/{proto → proto-grpc}/google/protobuf/timestamp.js +0 -0
package/dist/clients/upload.cjs
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
var plClient = require('@milaboratories/pl-client');
|
|
4
4
|
var fsp = require('node:fs/promises');
|
|
5
5
|
var undici = require('undici');
|
|
6
|
-
var protocol = require('../proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.cjs');
|
|
7
|
-
var protocol_client = require('../proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.cjs');
|
|
6
|
+
var protocol = require('../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.cjs');
|
|
7
|
+
var protocol_client = require('../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.cjs');
|
|
8
8
|
var crc32c = require('./crc32c.cjs');
|
|
9
9
|
|
|
10
10
|
function _interopNamespaceDefault(e) {
|
|
@@ -48,29 +48,84 @@ class BadRequestError extends Error {
|
|
|
48
48
|
class ClientUpload {
|
|
49
49
|
httpClient;
|
|
50
50
|
logger;
|
|
51
|
-
|
|
52
|
-
constructor(
|
|
51
|
+
wire;
|
|
52
|
+
constructor(wireClientProviderFactory, httpClient, _, logger) {
|
|
53
53
|
this.httpClient = httpClient;
|
|
54
54
|
this.logger = logger;
|
|
55
|
-
this.
|
|
55
|
+
this.wire = wireClientProviderFactory.createWireClientProvider((wire) => {
|
|
56
|
+
if (wire.type === 'grpc') {
|
|
57
|
+
return new protocol_client.UploadClient(wire.Transport);
|
|
58
|
+
}
|
|
59
|
+
return plClient.RestAPI.createClient({
|
|
60
|
+
hostAndPort: wire.Config.hostAndPort,
|
|
61
|
+
ssl: wire.Config.ssl,
|
|
62
|
+
dispatcher: wire.Dispatcher,
|
|
63
|
+
middlewares: wire.Middlewares,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
56
66
|
}
|
|
57
67
|
close() { }
|
|
58
68
|
async initUpload({ id, type }, options) {
|
|
59
|
-
const
|
|
69
|
+
const client = this.wire.get();
|
|
70
|
+
if (client instanceof protocol_client.UploadClient) {
|
|
71
|
+
const init = (await client.init({ resourceId: id }, plClient.addRTypeToMetadata(type, options)))
|
|
72
|
+
.response;
|
|
73
|
+
return {
|
|
74
|
+
overall: init.partsCount,
|
|
75
|
+
toUpload: this.partsToUpload(init.partsCount, init.uploadedParts),
|
|
76
|
+
checksumAlgorithm: init.checksumAlgorithm,
|
|
77
|
+
checksumHeader: init.checksumHeader,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const init = (await client.POST('/v1/upload/init', {
|
|
81
|
+
body: {
|
|
82
|
+
resourceId: id.toString(),
|
|
83
|
+
},
|
|
84
|
+
headers: { ...plClient.createRTypeRoutingHeader(type) },
|
|
85
|
+
})).data;
|
|
60
86
|
return {
|
|
61
|
-
overall: init.partsCount,
|
|
62
|
-
toUpload: this.partsToUpload(init.partsCount, init.uploadedParts),
|
|
87
|
+
overall: BigInt(init.partsCount),
|
|
88
|
+
toUpload: this.partsToUpload(BigInt(init.partsCount), init.uploadedParts.map(BigInt)),
|
|
63
89
|
checksumAlgorithm: init.checksumAlgorithm,
|
|
64
90
|
checksumHeader: init.checksumHeader,
|
|
65
91
|
};
|
|
66
92
|
}
|
|
67
93
|
async partUpload({ id, type }, path, expectedMTimeUnix, partNumber, checksumAlgorithm, checksumHeader, options) {
|
|
68
|
-
const
|
|
69
|
-
|
|
94
|
+
const client = this.wire.get();
|
|
95
|
+
let info;
|
|
96
|
+
if (client instanceof protocol_client.UploadClient) {
|
|
97
|
+
// partChecksum isn't used for now but protoc requires it to be set
|
|
98
|
+
info = (await client.getPartURL({
|
|
99
|
+
resourceId: id,
|
|
100
|
+
partNumber,
|
|
101
|
+
uploadedPartSize: 0n,
|
|
102
|
+
isInternalUse: false,
|
|
103
|
+
partChecksum: '',
|
|
104
|
+
}, plClient.addRTypeToMetadata(type, options))).response;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
const resp = (await client.POST('/v1/upload/get-part-url', {
|
|
108
|
+
body: {
|
|
109
|
+
resourceId: id.toString(),
|
|
110
|
+
partNumber: partNumber.toString(),
|
|
111
|
+
uploadedPartSize: '0',
|
|
112
|
+
isInternalUse: false,
|
|
113
|
+
partChecksum: '',
|
|
114
|
+
},
|
|
115
|
+
headers: { ...plClient.createRTypeRoutingHeader(type) },
|
|
116
|
+
})).data;
|
|
117
|
+
info = {
|
|
118
|
+
uploadUrl: resp.uploadUrl,
|
|
119
|
+
method: resp.method,
|
|
120
|
+
headers: resp.headers,
|
|
121
|
+
chunkStart: BigInt(resp.chunkStart),
|
|
122
|
+
chunkEnd: BigInt(resp.chunkEnd),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
70
125
|
const chunk = await readFileChunk(path, info.chunkStart, info.chunkEnd);
|
|
71
126
|
await checkExpectedMTime(path, expectedMTimeUnix);
|
|
72
127
|
const crc32cChecksum = calculateCrc32cChecksum(chunk);
|
|
73
|
-
if (checksumAlgorithm === protocol.
|
|
128
|
+
if (checksumAlgorithm === protocol.UploadAPI_ChecksumAlgorithm.CRC32C) {
|
|
74
129
|
info.headers.push({ name: checksumHeader, value: crc32cChecksum });
|
|
75
130
|
}
|
|
76
131
|
const contentLength = Number(info.chunkEnd - info.chunkStart);
|
|
@@ -106,10 +161,21 @@ class ClientUpload {
|
|
|
106
161
|
throw e;
|
|
107
162
|
throw new Error(`partUpload: error ${JSON.stringify(e)} happened while trying to do part upload to the url ${info.uploadUrl}, headers: ${JSON.stringify(info.headers)}`);
|
|
108
163
|
}
|
|
109
|
-
await this.
|
|
164
|
+
await this.updateProgress({ id, type }, BigInt(info.chunkEnd - info.chunkStart), options);
|
|
110
165
|
}
|
|
111
166
|
async finalize(info, options) {
|
|
112
|
-
|
|
167
|
+
const client = this.wire.get();
|
|
168
|
+
if (client instanceof protocol_client.UploadClient) {
|
|
169
|
+
await client.finalize({ resourceId: info.id }, plClient.addRTypeToMetadata(info.type, options));
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
await client.POST('/v1/upload/finalize', {
|
|
173
|
+
body: {
|
|
174
|
+
resourceId: info.id.toString(),
|
|
175
|
+
},
|
|
176
|
+
headers: { ...plClient.createRTypeRoutingHeader(info.type) },
|
|
177
|
+
});
|
|
178
|
+
}
|
|
113
179
|
}
|
|
114
180
|
/** Calculates parts that need to be uploaded from the parts that were
|
|
115
181
|
* already uploaded. */
|
|
@@ -122,23 +188,23 @@ class ClientUpload {
|
|
|
122
188
|
}
|
|
123
189
|
return toUpload;
|
|
124
190
|
}
|
|
125
|
-
async
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
await
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
191
|
+
async updateProgress({ id, type }, bytesProcessed, options) {
|
|
192
|
+
const client = this.wire.get();
|
|
193
|
+
if (client instanceof protocol_client.UploadClient) {
|
|
194
|
+
await client.updateProgress({
|
|
195
|
+
resourceId: id,
|
|
196
|
+
bytesProcessed,
|
|
197
|
+
}, plClient.addRTypeToMetadata(type, options)).response;
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
await client.POST('/v1/upload/update-progress', {
|
|
201
|
+
body: {
|
|
202
|
+
resourceId: id.toString(),
|
|
203
|
+
bytesProcessed: bytesProcessed.toString(),
|
|
204
|
+
},
|
|
205
|
+
headers: { ...plClient.createRTypeRoutingHeader(type) },
|
|
206
|
+
});
|
|
207
|
+
return;
|
|
142
208
|
}
|
|
143
209
|
}
|
|
144
210
|
async function readFileChunk(path, chunkStart, chunkEnd) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.cjs","sources":["../../src/clients/upload.ts"],"sourcesContent":["import type { GrpcClientProvider, GrpcClientProviderFactory, PlClient, ResourceId, ResourceType } from '@milaboratories/pl-client';\nimport { addRTypeToMetadata } from '@milaboratories/pl-client';\nimport type { ResourceInfo } from '@milaboratories/pl-tree';\nimport type { MiLogger } from '@milaboratories/ts-helpers';\nimport type { RpcOptions } from '@protobuf-ts/runtime-rpc';\nimport * as fs from 'node:fs/promises';\nimport type { Dispatcher } from 'undici';\nimport { request } from 'undici';\nimport { uploadapi_ChecksumAlgorithm, type uploadapi_GetPartURL_Response } from '../proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol';\nimport { UploadClient } from '../proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client';\nimport { crc32c } from './crc32c';\n\nimport type { IncomingHttpHeaders } from 'undici/types/header';\n\nexport class MTimeError extends Error {\n name = 'MTimeError';\n}\n\nexport class UnexpectedEOF extends Error {\n name = 'UnexpectedEOF';\n}\n\nexport class NetworkError extends Error {\n name = 'NetworkError';\n}\n\n/** Happens when the file doesn't exist */\nexport class NoFileForUploading extends Error {\n name = 'NoFileForUploading';\n}\n\nexport class BadRequestError extends Error {\n name = 'BadRequestError';\n}\n\n/** Low-level client for grpc uploadapi.\n * The user should pass here a concrete BlobUpload/<storageId> resource,\n * it can be got from handle field of BlobUpload. */\nexport class ClientUpload {\n private readonly grpcClient: GrpcClientProvider<UploadClient>;\n\n constructor(\n grpcClientProviderFactory: GrpcClientProviderFactory,\n public readonly httpClient: Dispatcher,\n _: PlClient,\n public readonly logger: MiLogger,\n ) {\n this.grpcClient = grpcClientProviderFactory.createGrpcClientProvider((transport) => new UploadClient(transport));\n }\n\n close() {}\n\n public async initUpload(\n { id, type }: ResourceInfo,\n options?: RpcOptions,\n ): Promise<{\n overall: bigint;\n toUpload: bigint[];\n checksumAlgorithm: uploadapi_ChecksumAlgorithm;\n checksumHeader: string;\n }> {\n const init = await this.grpcInit(id, type, options);\n return {\n overall: init.partsCount,\n toUpload: this.partsToUpload(init.partsCount, init.uploadedParts),\n checksumAlgorithm: init.checksumAlgorithm,\n checksumHeader: init.checksumHeader,\n };\n }\n\n public async partUpload(\n { id, type }: ResourceInfo,\n path: string,\n expectedMTimeUnix: bigint,\n partNumber: bigint,\n checksumAlgorithm: uploadapi_ChecksumAlgorithm,\n checksumHeader: string,\n options?: RpcOptions,\n ) {\n const info = await this.grpcGetPartUrl(\n { id, type },\n partNumber,\n 0n, // we update progress as a separate call later.\n options,\n );\n\n const chunk = await readFileChunk(path, info.chunkStart, info.chunkEnd);\n await checkExpectedMTime(path, expectedMTimeUnix);\n\n const crc32cChecksum = calculateCrc32cChecksum(chunk);\n if (checksumAlgorithm === uploadapi_ChecksumAlgorithm.CRC32C) {\n info.headers.push({ name: checksumHeader, value: crc32cChecksum });\n }\n\n const contentLength = Number(info.chunkEnd - info.chunkStart);\n if (chunk.length !== contentLength) {\n throw new Error(\n `Chunk size mismatch: expected ${contentLength} bytes, but read ${chunk.length} bytes from file`,\n );\n }\n\n const headers = Object.fromEntries(info.headers.map(({ name, value }) => [name.toLowerCase(), value]));\n\n try {\n const {\n body: rawBody,\n statusCode,\n headers: responseHeaders,\n } = await request(info.uploadUrl, {\n dispatcher: this.httpClient,\n body: chunk,\n // We got headers only after we send\n // the whole body (in case of S3 PUT requests it's 5 MB).\n // It might be slow with a slow connection (or with SSH),\n // that's why we got big timeout here.\n headersTimeout: 60000,\n bodyTimeout: 60000,\n // Prevent connection reuse by setting \"Connection: close\" header.\n // This works around an issue with the backend's built-in S3 implementation\n // that caused HTTP/1.1 protocol lines to be included in the uploaded file content.\n reset: true,\n headers,\n method: info.method.toUpperCase() as Dispatcher.HttpMethod,\n });\n\n // always read the body for resources to be garbage collected.\n const body = await rawBody.text();\n checkStatusCodeOk(statusCode, body, responseHeaders, info);\n } catch (e: unknown) {\n if (e instanceof NetworkError)\n throw e;\n\n if (e instanceof BadRequestError)\n throw e;\n\n throw new Error(`partUpload: error ${JSON.stringify(e)} happened while trying to do part upload to the url ${info.uploadUrl}, headers: ${JSON.stringify(info.headers)}`);\n }\n\n await this.grpcUpdateProgress({ id, type }, BigInt(info.chunkEnd - info.chunkStart), options);\n }\n\n public async finalize(info: ResourceInfo, options?: RpcOptions) {\n return await this.grpcFinalize(info, options);\n }\n\n /** Calculates parts that need to be uploaded from the parts that were\n * already uploaded. */\n private partsToUpload(partsCount: bigint, uploadedParts: bigint[]): bigint[] {\n const toUpload: bigint[] = [];\n const uploaded = new Set(uploadedParts);\n\n for (let i = 1n; i <= partsCount; i++) {\n if (!uploaded.has(i)) toUpload.push(i);\n }\n\n return toUpload;\n }\n\n private async grpcInit(id: ResourceId, type: ResourceType, options?: RpcOptions) {\n return await this.grpcClient.get().init({ resourceId: id }, addRTypeToMetadata(type, options))\n .response;\n }\n\n private async grpcGetPartUrl(\n { id, type }: ResourceInfo,\n partNumber: bigint,\n uploadedPartSize: bigint,\n options?: RpcOptions,\n ) {\n // partChecksum isn't used for now but protoc requires it to be set\n return await this.grpcClient.get().getPartURL(\n { resourceId: id, partNumber, uploadedPartSize, isInternalUse: false, partChecksum: '' },\n addRTypeToMetadata(type, options),\n ).response;\n }\n\n private async grpcUpdateProgress(\n { id, type }: ResourceInfo,\n bytesProcessed: bigint,\n options?: RpcOptions,\n ) {\n await this.grpcClient.get().updateProgress(\n {\n resourceId: id,\n bytesProcessed,\n },\n addRTypeToMetadata(type, options),\n ).response;\n }\n\n private async grpcFinalize({ id, type }: ResourceInfo, options?: RpcOptions) {\n return await this.grpcClient.get().finalize({ resourceId: id }, addRTypeToMetadata(type, options))\n .response;\n }\n}\n\nasync function readFileChunk(path: string, chunkStart: bigint, chunkEnd: bigint): Promise<Buffer> {\n let f: fs.FileHandle | undefined;\n try {\n f = await fs.open(path);\n const len = Number(chunkEnd - chunkStart);\n const pos = Number(chunkStart);\n const b = Buffer.alloc(len);\n const bytesRead = await readBytesFromPosition(f, b, len, pos);\n\n return b.subarray(0, bytesRead);\n } catch (e: unknown) {\n if (e && typeof e === 'object' && ('code' in e) && e.code == 'ENOENT') throw new NoFileForUploading(`there is no file ${path} for uploading`);\n throw e;\n } finally {\n await f?.close();\n }\n}\n\n/** Read len bytes from a given position.\n * Without this, `FileHandle.read` can read less bytes than needed. */\nasync function readBytesFromPosition(f: fs.FileHandle, b: Buffer, len: number, position: number) {\n let bytesReadTotal = 0;\n while (bytesReadTotal < len) {\n const { bytesRead } = await f.read(\n b,\n bytesReadTotal,\n len - bytesReadTotal,\n position + bytesReadTotal,\n );\n if (bytesRead === 0) {\n throw new UnexpectedEOF('file ended earlier than expected.');\n }\n bytesReadTotal += bytesRead;\n }\n\n return bytesReadTotal;\n}\n\nasync function checkExpectedMTime(path: string, expectedMTimeUnix: bigint) {\n const mTime = BigInt(Math.floor((await fs.stat(path)).mtimeMs / 1000));\n if (mTime > expectedMTimeUnix) {\n throw new MTimeError(`file was modified, expected mtime: ${expectedMTimeUnix}, got: ${mTime}.`);\n }\n}\n\nfunction checkStatusCodeOk(\n statusCode: number,\n body: string,\n headers: IncomingHttpHeaders,\n info: uploadapi_GetPartURL_Response,\n) {\n if (statusCode == 400) {\n throw new BadRequestError(`response is not ok, status code: ${statusCode},`\n + ` body: ${body}, headers: ${JSON.stringify(headers)}, url: ${info.uploadUrl}`);\n }\n\n if (statusCode != 200) {\n throw new NetworkError(\n `response is not ok, status code: ${statusCode},`\n + ` body: ${body}, headers: ${JSON.stringify(headers)}, url: ${info.uploadUrl}`,\n );\n }\n}\n\n/** Calculate CRC32C checksum of a buffer and return as base64 string */\nfunction calculateCrc32cChecksum(data: Buffer): string {\n const checksum = crc32c(data);\n // Convert to unsigned 32-bit integer and then to base64\n const buffer = Buffer.alloc(4);\n\n buffer.writeUInt32BE(checksum, 0);\n return buffer.toString('base64');\n}\n"],"names":["UploadClient","uploadapi_ChecksumAlgorithm","request","addRTypeToMetadata","fs","crc32c"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcM,MAAO,UAAW,SAAQ,KAAK,CAAA;IACnC,IAAI,GAAG,YAAY;AACpB;AAEK,MAAO,aAAc,SAAQ,KAAK,CAAA;IACtC,IAAI,GAAG,eAAe;AACvB;AAEK,MAAO,YAAa,SAAQ,KAAK,CAAA;IACrC,IAAI,GAAG,cAAc;AACtB;AAED;AACM,MAAO,kBAAmB,SAAQ,KAAK,CAAA;IAC3C,IAAI,GAAG,oBAAoB;AAC5B;AAEK,MAAO,eAAgB,SAAQ,KAAK,CAAA;IACxC,IAAI,GAAG,iBAAiB;AACzB;AAED;;AAEoD;MACvC,YAAY,CAAA;AAKL,IAAA,UAAA;AAEA,IAAA,MAAA;AAND,IAAA,UAAU;AAE3B,IAAA,WAAA,CACE,yBAAoD,EACpC,UAAsB,EACtC,CAAW,EACK,MAAgB,EAAA;QAFhB,IAAA,CAAA,UAAU,GAAV,UAAU;QAEV,IAAA,CAAA,MAAM,GAAN,MAAM;AAEtB,QAAA,IAAI,CAAC,UAAU,GAAG,yBAAyB,CAAC,wBAAwB,CAAC,CAAC,SAAS,KAAK,IAAIA,4BAAY,CAAC,SAAS,CAAC,CAAC;IAClH;AAEA,IAAA,KAAK,KAAI;IAEF,MAAM,UAAU,CACrB,EAAE,EAAE,EAAE,IAAI,EAAgB,EAC1B,OAAoB,EAAA;AAOpB,QAAA,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC;QACnD,OAAO;YACL,OAAO,EAA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pB,CAAA,iCAAA,EAAoC,UAAU,CAAA,CAAA;AAC5C,cAAA,CAAA,OAAA,EAAU,IAAI,CAAA,WAAA,EAAc,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA,OAAA,EAAU,IAAI,CAAC,SAAS,CAAA,CAAE,CAChF;IACH;AACF;AAEA;AACA,SAAS,uBAAuB,CAAC,IAAY,EAAA;AAC3C,IAAA,MAAM,QAAQ,GAAGC,aAAM,CAAC,IAAI,CAAC;;IAE7B,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAE9B,IAAA,MAAM,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC;AACjC,IAAA,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;AAClC;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"upload.cjs","sources":["../../src/clients/upload.ts"],"sourcesContent":["import type { WireClientProvider, WireClientProviderFactory, PlClient } from '@milaboratories/pl-client';\nimport { addRTypeToMetadata, createRTypeRoutingHeader, RestAPI } from '@milaboratories/pl-client';\nimport type { ResourceInfo } from '@milaboratories/pl-tree';\nimport type { MiLogger } from '@milaboratories/ts-helpers';\nimport type { RpcOptions } from '@protobuf-ts/runtime-rpc';\nimport * as fs from 'node:fs/promises';\nimport type { Dispatcher } from 'undici';\nimport { request } from 'undici';\nimport { UploadAPI_ChecksumAlgorithm, type UploadAPI_GetPartURL_Response } from '../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol';\nimport { UploadClient } from '../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client';\nimport type { UploadApiPaths, UploadRestClientType } from '../proto-rest';\nimport { crc32c } from './crc32c';\n\nimport type { IncomingHttpHeaders } from 'undici/types/header';\n\nexport class MTimeError extends Error {\n name = 'MTimeError';\n}\n\nexport class UnexpectedEOF extends Error {\n name = 'UnexpectedEOF';\n}\n\nexport class NetworkError extends Error {\n name = 'NetworkError';\n}\n\n/** Happens when the file doesn't exist */\nexport class NoFileForUploading extends Error {\n name = 'NoFileForUploading';\n}\n\nexport class BadRequestError extends Error {\n name = 'BadRequestError';\n}\n\n/** Low-level client for grpc uploadapi.\n * The user should pass here a concrete BlobUpload/<storageId> resource,\n * it can be got from handle field of BlobUpload. */\nexport class ClientUpload {\n private readonly wire: WireClientProvider<UploadRestClientType | UploadClient>;\n\n constructor(\n wireClientProviderFactory: WireClientProviderFactory,\n public readonly httpClient: Dispatcher,\n _: PlClient,\n public readonly logger: MiLogger,\n ) {\n this.wire = wireClientProviderFactory.createWireClientProvider(\n (wire) => {\n if (wire.type === 'grpc') {\n return new UploadClient(wire.Transport);\n }\n\n return RestAPI.createClient<UploadApiPaths>({\n hostAndPort: wire.Config.hostAndPort,\n ssl: wire.Config.ssl,\n dispatcher: wire.Dispatcher,\n middlewares: wire.Middlewares,\n });\n },\n );\n }\n\n close() {}\n\n public async initUpload(\n { id, type }: ResourceInfo,\n options?: RpcOptions,\n ): Promise<{\n overall: bigint;\n toUpload: bigint[];\n checksumAlgorithm: UploadAPI_ChecksumAlgorithm;\n checksumHeader: string;\n }> {\n const client = this.wire.get();\n\n if (client instanceof UploadClient) {\n const init = (await client.init({ resourceId: id }, addRTypeToMetadata(type, options)))\n .response;\n\n return {\n overall: init.partsCount,\n toUpload: this.partsToUpload(init.partsCount, init.uploadedParts),\n checksumAlgorithm: init.checksumAlgorithm,\n checksumHeader: init.checksumHeader,\n };\n }\n\n const init = (await client.POST('/v1/upload/init', {\n body: {\n resourceId: id.toString(),\n },\n headers: { ...createRTypeRoutingHeader(type) },\n })).data!;\n\n return {\n overall: BigInt(init.partsCount),\n toUpload: this.partsToUpload(BigInt(init.partsCount), init.uploadedParts.map(BigInt)),\n checksumAlgorithm: init.checksumAlgorithm,\n checksumHeader: init.checksumHeader,\n };\n }\n\n public async partUpload(\n { id, type }: ResourceInfo,\n path: string,\n expectedMTimeUnix: bigint,\n partNumber: bigint,\n checksumAlgorithm: UploadAPI_ChecksumAlgorithm,\n checksumHeader: string,\n options?: RpcOptions,\n ) {\n const client = this.wire.get();\n\n let info: UploadAPI_GetPartURL_Response;\n if (client instanceof UploadClient) {\n // partChecksum isn't used for now but protoc requires it to be set\n info = (await client.getPartURL(\n {\n resourceId: id,\n partNumber,\n uploadedPartSize: 0n,\n isInternalUse: false,\n partChecksum: '',\n },\n addRTypeToMetadata(type, options),\n )).response;\n } else {\n const resp = (await client.POST('/v1/upload/get-part-url', {\n body: {\n resourceId: id.toString(),\n partNumber: partNumber.toString(),\n uploadedPartSize: '0',\n isInternalUse: false,\n partChecksum: '',\n },\n headers: { ...createRTypeRoutingHeader(type) },\n })).data!;\n info = {\n uploadUrl: resp.uploadUrl,\n method: resp.method,\n headers: resp.headers,\n chunkStart: BigInt(resp.chunkStart),\n chunkEnd: BigInt(resp.chunkEnd),\n };\n }\n\n const chunk = await readFileChunk(path, info.chunkStart, info.chunkEnd);\n await checkExpectedMTime(path, expectedMTimeUnix);\n\n const crc32cChecksum = calculateCrc32cChecksum(chunk);\n if (checksumAlgorithm === UploadAPI_ChecksumAlgorithm.CRC32C) {\n info.headers.push({ name: checksumHeader, value: crc32cChecksum });\n }\n\n const contentLength = Number(info.chunkEnd - info.chunkStart);\n if (chunk.length !== contentLength) {\n throw new Error(\n `Chunk size mismatch: expected ${contentLength} bytes, but read ${chunk.length} bytes from file`,\n );\n }\n\n const headers = Object.fromEntries(info.headers.map(({ name, value }) => [name.toLowerCase(), value]));\n\n try {\n const {\n body: rawBody,\n statusCode,\n headers: responseHeaders,\n } = await request(info.uploadUrl, {\n dispatcher: this.httpClient,\n body: chunk,\n // We got headers only after we send\n // the whole body (in case of S3 PUT requests it's 5 MB).\n // It might be slow with a slow connection (or with SSH),\n // that's why we got big timeout here.\n headersTimeout: 60000,\n bodyTimeout: 60000,\n // Prevent connection reuse by setting \"Connection: close\" header.\n // This works around an issue with the backend's built-in S3 implementation\n // that caused HTTP/1.1 protocol lines to be included in the uploaded file content.\n reset: true,\n headers,\n method: info.method.toUpperCase() as Dispatcher.HttpMethod,\n });\n\n // always read the body for resources to be garbage collected.\n const body = await rawBody.text();\n checkStatusCodeOk(statusCode, body, responseHeaders, info);\n } catch (e: unknown) {\n if (e instanceof NetworkError)\n throw e;\n\n if (e instanceof BadRequestError)\n throw e;\n\n throw new Error(`partUpload: error ${JSON.stringify(e)} happened while trying to do part upload to the url ${info.uploadUrl}, headers: ${JSON.stringify(info.headers)}`);\n }\n\n await this.updateProgress({ id, type }, BigInt(info.chunkEnd - info.chunkStart), options);\n }\n\n public async finalize(info: ResourceInfo, options?: RpcOptions) {\n const client = this.wire.get();\n\n if (client instanceof UploadClient) {\n await client.finalize({ resourceId: info.id }, addRTypeToMetadata(info.type, options));\n } else {\n await client.POST('/v1/upload/finalize', {\n body: {\n resourceId: info.id.toString(),\n },\n headers: { ...createRTypeRoutingHeader(info.type) },\n });\n }\n }\n\n /** Calculates parts that need to be uploaded from the parts that were\n * already uploaded. */\n private partsToUpload(partsCount: bigint, uploadedParts: bigint[]): bigint[] {\n const toUpload: bigint[] = [];\n const uploaded = new Set(uploadedParts);\n\n for (let i = 1n; i <= partsCount; i++) {\n if (!uploaded.has(i)) toUpload.push(i);\n }\n\n return toUpload;\n }\n\n private async updateProgress(\n { id, type }: ResourceInfo,\n bytesProcessed: bigint,\n options?: RpcOptions,\n ): Promise<void> {\n const client = this.wire.get();\n\n if (client instanceof UploadClient) {\n await client.updateProgress(\n {\n resourceId: id,\n bytesProcessed,\n },\n addRTypeToMetadata(type, options),\n ).response;\n return;\n }\n\n await client.POST('/v1/upload/update-progress', {\n body: {\n resourceId: id.toString(),\n bytesProcessed: bytesProcessed.toString(),\n },\n headers: { ...createRTypeRoutingHeader(type) },\n });\n return;\n }\n}\n\nasync function readFileChunk(path: string, chunkStart: bigint, chunkEnd: bigint): Promise<Buffer> {\n let f: fs.FileHandle | undefined;\n try {\n f = await fs.open(path);\n const len = Number(chunkEnd - chunkStart);\n const pos = Number(chunkStart);\n const b = Buffer.alloc(len);\n const bytesRead = await readBytesFromPosition(f, b, len, pos);\n\n return b.subarray(0, bytesRead);\n } catch (e: unknown) {\n if (e && typeof e === 'object' && ('code' in e) && e.code == 'ENOENT') throw new NoFileForUploading(`there is no file ${path} for uploading`);\n throw e;\n } finally {\n await f?.close();\n }\n}\n\n/** Read len bytes from a given position.\n * Without this, `FileHandle.read` can read less bytes than needed. */\nasync function readBytesFromPosition(f: fs.FileHandle, b: Buffer, len: number, position: number) {\n let bytesReadTotal = 0;\n while (bytesReadTotal < len) {\n const { bytesRead } = await f.read(\n b,\n bytesReadTotal,\n len - bytesReadTotal,\n position + bytesReadTotal,\n );\n if (bytesRead === 0) {\n throw new UnexpectedEOF('file ended earlier than expected.');\n }\n bytesReadTotal += bytesRead;\n }\n\n return bytesReadTotal;\n}\n\nasync function checkExpectedMTime(path: string, expectedMTimeUnix: bigint) {\n const mTime = BigInt(Math.floor((await fs.stat(path)).mtimeMs / 1000));\n if (mTime > expectedMTimeUnix) {\n throw new MTimeError(`file was modified, expected mtime: ${expectedMTimeUnix}, got: ${mTime}.`);\n }\n}\n\nfunction checkStatusCodeOk(\n statusCode: number,\n body: string,\n headers: IncomingHttpHeaders,\n info: UploadAPI_GetPartURL_Response,\n) {\n if (statusCode == 400) {\n throw new BadRequestError(`response is not ok, status code: ${statusCode},`\n + ` body: ${body}, headers: ${JSON.stringify(headers)}, url: ${info.uploadUrl}`);\n }\n\n if (statusCode != 200) {\n throw new NetworkError(\n `response is not ok, status code: ${statusCode},`\n + ` body: ${body}, headers: ${JSON.stringify(headers)}, url: ${info.uploadUrl}`,\n );\n }\n}\n\n/** Calculate CRC32C checksum of a buffer and return as base64 string */\nfunction calculateCrc32cChecksum(data: Buffer): string {\n const checksum = crc32c(data);\n // Convert to unsigned 32-bit integer and then to base64\n const buffer = Buffer.alloc(4);\n\n buffer.writeUInt32BE(checksum, 0);\n return buffer.toString('base64');\n}\n"],"names":["UploadClient","RestAPI","addRTypeToMetadata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B,EAAE;QAC7B,MAAM,IAAI,UAAU,CAAC,CAAA,mCAAA,EAAsC,iBAAiB,CAAA,OAAA,EAAU,KAAK,CAAA,CAAA,CAAG,CAAC;IACjG;AACF;AAEA,SAAS,iBAAiB,CACxB,UAAkB,EAClB,IAAY,EACZ,OAA4B,EAC5B,IAAmC,EAAA;AAEnC,IAAA,IAAI,UAAU,IAAI,GAAG,EAAE;AACrB,QAAA,MAAM,IAAI,eAAe,CAAC,CAAA,iCAAA,EAAoC,UAAU,CAAA,CAAA;AACpE,cAAA,CAAA,OAAA,EAAU,IAAI,CAAA,WAAA,EAAc,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA,OAAA,EAAU,IAAI,CAAC,SAAS,CAAA,CAAE,CAAC;IACpF;AAEA,IAAA,IAAI,UAAU,IAAI,GAAG,EAAE;AACrB,QAAA,MAAM,IAAI,YAAY,CACpB,CAAA,iCAAA,EAAoC,UAAU,CAAA,CAAA;AAC5C,cAAA,CAAA,OAAA,EAAU,IAAI,CAAA,WAAA,EAAc,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA,OAAA,EAAU,IAAI,CAAC,SAAS,CAAA,CAAE,CAChF;IACH;AACF;AAEA;AACA,SAAS,uBAAuB,CAAC,IAAY,EAAA;AAC3C,IAAA,MAAM,QAAQ,GAAGC,aAAM,CAAC,IAAI,CAAC;;IAE7B,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAE9B,IAAA,MAAM,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC;AACjC,IAAA,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;AAClC;;;;;;;;;"}
|
package/dist/clients/upload.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WireClientProviderFactory, PlClient } from '@milaboratories/pl-client';
|
|
2
2
|
import type { ResourceInfo } from '@milaboratories/pl-tree';
|
|
3
3
|
import type { MiLogger } from '@milaboratories/ts-helpers';
|
|
4
4
|
import type { RpcOptions } from '@protobuf-ts/runtime-rpc';
|
|
5
5
|
import type { Dispatcher } from 'undici';
|
|
6
|
-
import {
|
|
6
|
+
import { UploadAPI_ChecksumAlgorithm } from '../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol';
|
|
7
7
|
export declare class MTimeError extends Error {
|
|
8
8
|
name: string;
|
|
9
9
|
}
|
|
@@ -26,23 +26,20 @@ export declare class BadRequestError extends Error {
|
|
|
26
26
|
export declare class ClientUpload {
|
|
27
27
|
readonly httpClient: Dispatcher;
|
|
28
28
|
readonly logger: MiLogger;
|
|
29
|
-
private readonly
|
|
30
|
-
constructor(
|
|
29
|
+
private readonly wire;
|
|
30
|
+
constructor(wireClientProviderFactory: WireClientProviderFactory, httpClient: Dispatcher, _: PlClient, logger: MiLogger);
|
|
31
31
|
close(): void;
|
|
32
32
|
initUpload({ id, type }: ResourceInfo, options?: RpcOptions): Promise<{
|
|
33
33
|
overall: bigint;
|
|
34
34
|
toUpload: bigint[];
|
|
35
|
-
checksumAlgorithm:
|
|
35
|
+
checksumAlgorithm: UploadAPI_ChecksumAlgorithm;
|
|
36
36
|
checksumHeader: string;
|
|
37
37
|
}>;
|
|
38
|
-
partUpload({ id, type }: ResourceInfo, path: string, expectedMTimeUnix: bigint, partNumber: bigint, checksumAlgorithm:
|
|
39
|
-
finalize(info: ResourceInfo, options?: RpcOptions): Promise<
|
|
38
|
+
partUpload({ id, type }: ResourceInfo, path: string, expectedMTimeUnix: bigint, partNumber: bigint, checksumAlgorithm: UploadAPI_ChecksumAlgorithm, checksumHeader: string, options?: RpcOptions): Promise<void>;
|
|
39
|
+
finalize(info: ResourceInfo, options?: RpcOptions): Promise<void>;
|
|
40
40
|
/** Calculates parts that need to be uploaded from the parts that were
|
|
41
41
|
* already uploaded. */
|
|
42
42
|
private partsToUpload;
|
|
43
|
-
private
|
|
44
|
-
private grpcGetPartUrl;
|
|
45
|
-
private grpcUpdateProgress;
|
|
46
|
-
private grpcFinalize;
|
|
43
|
+
private updateProgress;
|
|
47
44
|
}
|
|
48
45
|
//# sourceMappingURL=upload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../src/clients/upload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsB,yBAAyB,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../src/clients/upload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsB,yBAAyB,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAEzG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEzC,OAAO,EAAE,2BAA2B,EAAsC,MAAM,qFAAqF,CAAC;AAOtK,qBAAa,UAAW,SAAQ,KAAK;IACnC,IAAI,SAAgB;CACrB;AAED,qBAAa,aAAc,SAAQ,KAAK;IACtC,IAAI,SAAmB;CACxB;AAED,qBAAa,YAAa,SAAQ,KAAK;IACrC,IAAI,SAAkB;CACvB;AAED,0CAA0C;AAC1C,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,IAAI,SAAwB;CAC7B;AAED,qBAAa,eAAgB,SAAQ,KAAK;IACxC,IAAI,SAAqB;CAC1B;AAED;;oDAEoD;AACpD,qBAAa,YAAY;aAKL,UAAU,EAAE,UAAU;aAEtB,MAAM,EAAE,QAAQ;IANlC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA0D;gBAG7E,yBAAyB,EAAE,yBAAyB,EACpC,UAAU,EAAE,UAAU,EACtC,CAAC,EAAE,QAAQ,EACK,MAAM,EAAE,QAAQ;IAkBlC,KAAK;IAEQ,UAAU,CACrB,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,YAAY,EAC1B,OAAO,CAAC,EAAE,UAAU,GACnB,OAAO,CAAC;QACP,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;QACnB,iBAAiB,EAAE,2BAA2B,CAAC;QAC/C,cAAc,EAAE,MAAM,CAAC;KACxB,CAAC;IA8BS,UAAU,CACrB,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,YAAY,EAC1B,IAAI,EAAE,MAAM,EACZ,iBAAiB,EAAE,MAAM,EACzB,UAAU,EAAE,MAAM,EAClB,iBAAiB,EAAE,2BAA2B,EAC9C,cAAc,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE,UAAU;IA4FT,QAAQ,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,UAAU;IAe9D;2BACuB;IACvB,OAAO,CAAC,aAAa;YAWP,cAAc;CA2B7B"}
|
package/dist/clients/upload.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { addRTypeToMetadata } from '@milaboratories/pl-client';
|
|
1
|
+
import { RestAPI, addRTypeToMetadata, createRTypeRoutingHeader } from '@milaboratories/pl-client';
|
|
2
2
|
import * as fsp from 'node:fs/promises';
|
|
3
3
|
import { request } from 'undici';
|
|
4
|
-
import {
|
|
5
|
-
import { UploadClient } from '../proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.js';
|
|
4
|
+
import { UploadAPI_ChecksumAlgorithm } from '../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.js';
|
|
5
|
+
import { UploadClient } from '../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client.js';
|
|
6
6
|
import { crc32c } from './crc32c.js';
|
|
7
7
|
|
|
8
8
|
class MTimeError extends Error {
|
|
@@ -27,29 +27,84 @@ class BadRequestError extends Error {
|
|
|
27
27
|
class ClientUpload {
|
|
28
28
|
httpClient;
|
|
29
29
|
logger;
|
|
30
|
-
|
|
31
|
-
constructor(
|
|
30
|
+
wire;
|
|
31
|
+
constructor(wireClientProviderFactory, httpClient, _, logger) {
|
|
32
32
|
this.httpClient = httpClient;
|
|
33
33
|
this.logger = logger;
|
|
34
|
-
this.
|
|
34
|
+
this.wire = wireClientProviderFactory.createWireClientProvider((wire) => {
|
|
35
|
+
if (wire.type === 'grpc') {
|
|
36
|
+
return new UploadClient(wire.Transport);
|
|
37
|
+
}
|
|
38
|
+
return RestAPI.createClient({
|
|
39
|
+
hostAndPort: wire.Config.hostAndPort,
|
|
40
|
+
ssl: wire.Config.ssl,
|
|
41
|
+
dispatcher: wire.Dispatcher,
|
|
42
|
+
middlewares: wire.Middlewares,
|
|
43
|
+
});
|
|
44
|
+
});
|
|
35
45
|
}
|
|
36
46
|
close() { }
|
|
37
47
|
async initUpload({ id, type }, options) {
|
|
38
|
-
const
|
|
48
|
+
const client = this.wire.get();
|
|
49
|
+
if (client instanceof UploadClient) {
|
|
50
|
+
const init = (await client.init({ resourceId: id }, addRTypeToMetadata(type, options)))
|
|
51
|
+
.response;
|
|
52
|
+
return {
|
|
53
|
+
overall: init.partsCount,
|
|
54
|
+
toUpload: this.partsToUpload(init.partsCount, init.uploadedParts),
|
|
55
|
+
checksumAlgorithm: init.checksumAlgorithm,
|
|
56
|
+
checksumHeader: init.checksumHeader,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const init = (await client.POST('/v1/upload/init', {
|
|
60
|
+
body: {
|
|
61
|
+
resourceId: id.toString(),
|
|
62
|
+
},
|
|
63
|
+
headers: { ...createRTypeRoutingHeader(type) },
|
|
64
|
+
})).data;
|
|
39
65
|
return {
|
|
40
|
-
overall: init.partsCount,
|
|
41
|
-
toUpload: this.partsToUpload(init.partsCount, init.uploadedParts),
|
|
66
|
+
overall: BigInt(init.partsCount),
|
|
67
|
+
toUpload: this.partsToUpload(BigInt(init.partsCount), init.uploadedParts.map(BigInt)),
|
|
42
68
|
checksumAlgorithm: init.checksumAlgorithm,
|
|
43
69
|
checksumHeader: init.checksumHeader,
|
|
44
70
|
};
|
|
45
71
|
}
|
|
46
72
|
async partUpload({ id, type }, path, expectedMTimeUnix, partNumber, checksumAlgorithm, checksumHeader, options) {
|
|
47
|
-
const
|
|
48
|
-
|
|
73
|
+
const client = this.wire.get();
|
|
74
|
+
let info;
|
|
75
|
+
if (client instanceof UploadClient) {
|
|
76
|
+
// partChecksum isn't used for now but protoc requires it to be set
|
|
77
|
+
info = (await client.getPartURL({
|
|
78
|
+
resourceId: id,
|
|
79
|
+
partNumber,
|
|
80
|
+
uploadedPartSize: 0n,
|
|
81
|
+
isInternalUse: false,
|
|
82
|
+
partChecksum: '',
|
|
83
|
+
}, addRTypeToMetadata(type, options))).response;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
const resp = (await client.POST('/v1/upload/get-part-url', {
|
|
87
|
+
body: {
|
|
88
|
+
resourceId: id.toString(),
|
|
89
|
+
partNumber: partNumber.toString(),
|
|
90
|
+
uploadedPartSize: '0',
|
|
91
|
+
isInternalUse: false,
|
|
92
|
+
partChecksum: '',
|
|
93
|
+
},
|
|
94
|
+
headers: { ...createRTypeRoutingHeader(type) },
|
|
95
|
+
})).data;
|
|
96
|
+
info = {
|
|
97
|
+
uploadUrl: resp.uploadUrl,
|
|
98
|
+
method: resp.method,
|
|
99
|
+
headers: resp.headers,
|
|
100
|
+
chunkStart: BigInt(resp.chunkStart),
|
|
101
|
+
chunkEnd: BigInt(resp.chunkEnd),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
49
104
|
const chunk = await readFileChunk(path, info.chunkStart, info.chunkEnd);
|
|
50
105
|
await checkExpectedMTime(path, expectedMTimeUnix);
|
|
51
106
|
const crc32cChecksum = calculateCrc32cChecksum(chunk);
|
|
52
|
-
if (checksumAlgorithm ===
|
|
107
|
+
if (checksumAlgorithm === UploadAPI_ChecksumAlgorithm.CRC32C) {
|
|
53
108
|
info.headers.push({ name: checksumHeader, value: crc32cChecksum });
|
|
54
109
|
}
|
|
55
110
|
const contentLength = Number(info.chunkEnd - info.chunkStart);
|
|
@@ -85,10 +140,21 @@ class ClientUpload {
|
|
|
85
140
|
throw e;
|
|
86
141
|
throw new Error(`partUpload: error ${JSON.stringify(e)} happened while trying to do part upload to the url ${info.uploadUrl}, headers: ${JSON.stringify(info.headers)}`);
|
|
87
142
|
}
|
|
88
|
-
await this.
|
|
143
|
+
await this.updateProgress({ id, type }, BigInt(info.chunkEnd - info.chunkStart), options);
|
|
89
144
|
}
|
|
90
145
|
async finalize(info, options) {
|
|
91
|
-
|
|
146
|
+
const client = this.wire.get();
|
|
147
|
+
if (client instanceof UploadClient) {
|
|
148
|
+
await client.finalize({ resourceId: info.id }, addRTypeToMetadata(info.type, options));
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
await client.POST('/v1/upload/finalize', {
|
|
152
|
+
body: {
|
|
153
|
+
resourceId: info.id.toString(),
|
|
154
|
+
},
|
|
155
|
+
headers: { ...createRTypeRoutingHeader(info.type) },
|
|
156
|
+
});
|
|
157
|
+
}
|
|
92
158
|
}
|
|
93
159
|
/** Calculates parts that need to be uploaded from the parts that were
|
|
94
160
|
* already uploaded. */
|
|
@@ -101,23 +167,23 @@ class ClientUpload {
|
|
|
101
167
|
}
|
|
102
168
|
return toUpload;
|
|
103
169
|
}
|
|
104
|
-
async
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
await
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
170
|
+
async updateProgress({ id, type }, bytesProcessed, options) {
|
|
171
|
+
const client = this.wire.get();
|
|
172
|
+
if (client instanceof UploadClient) {
|
|
173
|
+
await client.updateProgress({
|
|
174
|
+
resourceId: id,
|
|
175
|
+
bytesProcessed,
|
|
176
|
+
}, addRTypeToMetadata(type, options)).response;
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
await client.POST('/v1/upload/update-progress', {
|
|
180
|
+
body: {
|
|
181
|
+
resourceId: id.toString(),
|
|
182
|
+
bytesProcessed: bytesProcessed.toString(),
|
|
183
|
+
},
|
|
184
|
+
headers: { ...createRTypeRoutingHeader(type) },
|
|
185
|
+
});
|
|
186
|
+
return;
|
|
121
187
|
}
|
|
122
188
|
}
|
|
123
189
|
async function readFileChunk(path, chunkStart, chunkEnd) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.js","sources":["../../src/clients/upload.ts"],"sourcesContent":["import type { GrpcClientProvider, GrpcClientProviderFactory, PlClient, ResourceId, ResourceType } from '@milaboratories/pl-client';\nimport { addRTypeToMetadata } from '@milaboratories/pl-client';\nimport type { ResourceInfo } from '@milaboratories/pl-tree';\nimport type { MiLogger } from '@milaboratories/ts-helpers';\nimport type { RpcOptions } from '@protobuf-ts/runtime-rpc';\nimport * as fs from 'node:fs/promises';\nimport type { Dispatcher } from 'undici';\nimport { request } from 'undici';\nimport { uploadapi_ChecksumAlgorithm, type uploadapi_GetPartURL_Response } from '../proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol';\nimport { UploadClient } from '../proto/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client';\nimport { crc32c } from './crc32c';\n\nimport type { IncomingHttpHeaders } from 'undici/types/header';\n\nexport class MTimeError extends Error {\n name = 'MTimeError';\n}\n\nexport class UnexpectedEOF extends Error {\n name = 'UnexpectedEOF';\n}\n\nexport class NetworkError extends Error {\n name = 'NetworkError';\n}\n\n/** Happens when the file doesn't exist */\nexport class NoFileForUploading extends Error {\n name = 'NoFileForUploading';\n}\n\nexport class BadRequestError extends Error {\n name = 'BadRequestError';\n}\n\n/** Low-level client for grpc uploadapi.\n * The user should pass here a concrete BlobUpload/<storageId> resource,\n * it can be got from handle field of BlobUpload. */\nexport class ClientUpload {\n private readonly grpcClient: GrpcClientProvider<UploadClient>;\n\n constructor(\n grpcClientProviderFactory: GrpcClientProviderFactory,\n public readonly httpClient: Dispatcher,\n _: PlClient,\n public readonly logger: MiLogger,\n ) {\n this.grpcClient = grpcClientProviderFactory.createGrpcClientProvider((transport) => new UploadClient(transport));\n }\n\n close() {}\n\n public async initUpload(\n { id, type }: ResourceInfo,\n options?: RpcOptions,\n ): Promise<{\n overall: bigint;\n toUpload: bigint[];\n checksumAlgorithm: uploadapi_ChecksumAlgorithm;\n checksumHeader: string;\n }> {\n const init = await this.grpcInit(id, type, options);\n return {\n overall: init.partsCount,\n toUpload: this.partsToUpload(init.partsCount, init.uploadedParts),\n checksumAlgorithm: init.checksumAlgorithm,\n checksumHeader: init.checksumHeader,\n };\n }\n\n public async partUpload(\n { id, type }: ResourceInfo,\n path: string,\n expectedMTimeUnix: bigint,\n partNumber: bigint,\n checksumAlgorithm: uploadapi_ChecksumAlgorithm,\n checksumHeader: string,\n options?: RpcOptions,\n ) {\n const info = await this.grpcGetPartUrl(\n { id, type },\n partNumber,\n 0n, // we update progress as a separate call later.\n options,\n );\n\n const chunk = await readFileChunk(path, info.chunkStart, info.chunkEnd);\n await checkExpectedMTime(path, expectedMTimeUnix);\n\n const crc32cChecksum = calculateCrc32cChecksum(chunk);\n if (checksumAlgorithm === uploadapi_ChecksumAlgorithm.CRC32C) {\n info.headers.push({ name: checksumHeader, value: crc32cChecksum });\n }\n\n const contentLength = Number(info.chunkEnd - info.chunkStart);\n if (chunk.length !== contentLength) {\n throw new Error(\n `Chunk size mismatch: expected ${contentLength} bytes, but read ${chunk.length} bytes from file`,\n );\n }\n\n const headers = Object.fromEntries(info.headers.map(({ name, value }) => [name.toLowerCase(), value]));\n\n try {\n const {\n body: rawBody,\n statusCode,\n headers: responseHeaders,\n } = await request(info.uploadUrl, {\n dispatcher: this.httpClient,\n body: chunk,\n // We got headers only after we send\n // the whole body (in case of S3 PUT requests it's 5 MB).\n // It might be slow with a slow connection (or with SSH),\n // that's why we got big timeout here.\n headersTimeout: 60000,\n bodyTimeout: 60000,\n // Prevent connection reuse by setting \"Connection: close\" header.\n // This works around an issue with the backend's built-in S3 implementation\n // that caused HTTP/1.1 protocol lines to be included in the uploaded file content.\n reset: true,\n headers,\n method: info.method.toUpperCase() as Dispatcher.HttpMethod,\n });\n\n // always read the body for resources to be garbage collected.\n const body = await rawBody.text();\n checkStatusCodeOk(statusCode, body, responseHeaders, info);\n } catch (e: unknown) {\n if (e instanceof NetworkError)\n throw e;\n\n if (e instanceof BadRequestError)\n throw e;\n\n throw new Error(`partUpload: error ${JSON.stringify(e)} happened while trying to do part upload to the url ${info.uploadUrl}, headers: ${JSON.stringify(info.headers)}`);\n }\n\n await this.grpcUpdateProgress({ id, type }, BigInt(info.chunkEnd - info.chunkStart), options);\n }\n\n public async finalize(info: ResourceInfo, options?: RpcOptions) {\n return await this.grpcFinalize(info, options);\n }\n\n /** Calculates parts that need to be uploaded from the parts that were\n * already uploaded. */\n private partsToUpload(partsCount: bigint, uploadedParts: bigint[]): bigint[] {\n const toUpload: bigint[] = [];\n const uploaded = new Set(uploadedParts);\n\n for (let i = 1n; i <= partsCount; i++) {\n if (!uploaded.has(i)) toUpload.push(i);\n }\n\n return toUpload;\n }\n\n private async grpcInit(id: ResourceId, type: ResourceType, options?: RpcOptions) {\n return await this.grpcClient.get().init({ resourceId: id }, addRTypeToMetadata(type, options))\n .response;\n }\n\n private async grpcGetPartUrl(\n { id, type }: ResourceInfo,\n partNumber: bigint,\n uploadedPartSize: bigint,\n options?: RpcOptions,\n ) {\n // partChecksum isn't used for now but protoc requires it to be set\n return await this.grpcClient.get().getPartURL(\n { resourceId: id, partNumber, uploadedPartSize, isInternalUse: false, partChecksum: '' },\n addRTypeToMetadata(type, options),\n ).response;\n }\n\n private async grpcUpdateProgress(\n { id, type }: ResourceInfo,\n bytesProcessed: bigint,\n options?: RpcOptions,\n ) {\n await this.grpcClient.get().updateProgress(\n {\n resourceId: id,\n bytesProcessed,\n },\n addRTypeToMetadata(type, options),\n ).response;\n }\n\n private async grpcFinalize({ id, type }: ResourceInfo, options?: RpcOptions) {\n return await this.grpcClient.get().finalize({ resourceId: id }, addRTypeToMetadata(type, options))\n .response;\n }\n}\n\nasync function readFileChunk(path: string, chunkStart: bigint, chunkEnd: bigint): Promise<Buffer> {\n let f: fs.FileHandle | undefined;\n try {\n f = await fs.open(path);\n const len = Number(chunkEnd - chunkStart);\n const pos = Number(chunkStart);\n const b = Buffer.alloc(len);\n const bytesRead = await readBytesFromPosition(f, b, len, pos);\n\n return b.subarray(0, bytesRead);\n } catch (e: unknown) {\n if (e && typeof e === 'object' && ('code' in e) && e.code == 'ENOENT') throw new NoFileForUploading(`there is no file ${path} for uploading`);\n throw e;\n } finally {\n await f?.close();\n }\n}\n\n/** Read len bytes from a given position.\n * Without this, `FileHandle.read` can read less bytes than needed. */\nasync function readBytesFromPosition(f: fs.FileHandle, b: Buffer, len: number, position: number) {\n let bytesReadTotal = 0;\n while (bytesReadTotal < len) {\n const { bytesRead } = await f.read(\n b,\n bytesReadTotal,\n len - bytesReadTotal,\n position + bytesReadTotal,\n );\n if (bytesRead === 0) {\n throw new UnexpectedEOF('file ended earlier than expected.');\n }\n bytesReadTotal += bytesRead;\n }\n\n return bytesReadTotal;\n}\n\nasync function checkExpectedMTime(path: string, expectedMTimeUnix: bigint) {\n const mTime = BigInt(Math.floor((await fs.stat(path)).mtimeMs / 1000));\n if (mTime > expectedMTimeUnix) {\n throw new MTimeError(`file was modified, expected mtime: ${expectedMTimeUnix}, got: ${mTime}.`);\n }\n}\n\nfunction checkStatusCodeOk(\n statusCode: number,\n body: string,\n headers: IncomingHttpHeaders,\n info: uploadapi_GetPartURL_Response,\n) {\n if (statusCode == 400) {\n throw new BadRequestError(`response is not ok, status code: ${statusCode},`\n + ` body: ${body}, headers: ${JSON.stringify(headers)}, url: ${info.uploadUrl}`);\n }\n\n if (statusCode != 200) {\n throw new NetworkError(\n `response is not ok, status code: ${statusCode},`\n + ` body: ${body}, headers: ${JSON.stringify(headers)}, url: ${info.uploadUrl}`,\n );\n }\n}\n\n/** Calculate CRC32C checksum of a buffer and return as base64 string */\nfunction calculateCrc32cChecksum(data: Buffer): string {\n const checksum = crc32c(data);\n // Convert to unsigned 32-bit integer and then to base64\n const buffer = Buffer.alloc(4);\n\n buffer.writeUInt32BE(checksum, 0);\n return buffer.toString('base64');\n}\n"],"names":["fs"],"mappings":";;;;;;;AAcM,MAAO,UAAW,SAAQ,KAAK,CAAA;IACnC,IAAI,GAAG,YAAY;AACpB;AAEK,MAAO,aAAc,SAAQ,KAAK,CAAA;IACtC,IAAI,GAAG,eAAe;AACvB;AAEK,MAAO,YAAa,SAAQ,KAAK,CAAA;IACrC,IAAI,GAAG,cAAc;AACtB;AAED;AACM,MAAO,kBAAmB,SAAQ,KAAK,CAAA;IAC3C,IAAI,GAAG,oBAAoB;AAC5B;AAEK,MAAO,eAAgB,SAAQ,KAAK,CAAA;IACxC,IAAI,GAAG,iBAAiB;AACzB;AAED;;AAEoD;MACvC,YAAY,CAAA;AAKL,IAAA,UAAA;AAEA,IAAA,MAAA;AAND,IAAA,UAAU;AAE3B,IAAA,WAAA,CACE,yBAAoD,EACpC,UAAsB,EACtC,CAAW,EACK,MAAgB,EAAA;QAFhB,IAAA,CAAA,UAAU,GAAV,UAAU;QAEV,IAAA,CAAA,MAAM,GAAN,MAAM;AAEtB,QAAA,IAAI,CAAC,UAAU,GAAG,yBAAyB,CAAC,wBAAwB,CAAC,CAAC,SAAS,KAAK,IAAI,YAAY,CAAC,SAAS,CAAC,CAAC;IAClH;AAEA,IAAA,KAAK,KAAI;IAEF,MAAM,UAAU,CACrB,EAAE,EAAE,EAAE,IAAI,EAAgB,EAC1B,OAAoB,EAAA;AAOpB,QAAA,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,EAAE,OA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B,QAAA,MAAM,IAAI,YAAY,CACpB,CAAA,iCAAA,EAAoC,UAAU,CAAA,CAAA;AAC5C,cAAA,CAAA,OAAA,EAAU,IAAI,CAAA,WAAA,EAAc,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA,OAAA,EAAU,IAAI,CAAC,SAAS,CAAA,CAAE,CAChF;IACH;AACF;AAEA;AACA,SAAS,uBAAuB,CAAC,IAAY,EAAA;AAC3C,IAAA,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC;;IAE7B,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAE9B,IAAA,MAAM,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC;AACjC,IAAA,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;AAClC;;;;"}
|
|
1
|
+
{"version":3,"file":"upload.js","sources":["../../src/clients/upload.ts"],"sourcesContent":["import type { WireClientProvider, WireClientProviderFactory, PlClient } from '@milaboratories/pl-client';\nimport { addRTypeToMetadata, createRTypeRoutingHeader, RestAPI } from '@milaboratories/pl-client';\nimport type { ResourceInfo } from '@milaboratories/pl-tree';\nimport type { MiLogger } from '@milaboratories/ts-helpers';\nimport type { RpcOptions } from '@protobuf-ts/runtime-rpc';\nimport * as fs from 'node:fs/promises';\nimport type { Dispatcher } from 'undici';\nimport { request } from 'undici';\nimport { UploadAPI_ChecksumAlgorithm, type UploadAPI_GetPartURL_Response } from '../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol';\nimport { UploadClient } from '../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.client';\nimport type { UploadApiPaths, UploadRestClientType } from '../proto-rest';\nimport { crc32c } from './crc32c';\n\nimport type { IncomingHttpHeaders } from 'undici/types/header';\n\nexport class MTimeError extends Error {\n name = 'MTimeError';\n}\n\nexport class UnexpectedEOF extends Error {\n name = 'UnexpectedEOF';\n}\n\nexport class NetworkError extends Error {\n name = 'NetworkError';\n}\n\n/** Happens when the file doesn't exist */\nexport class NoFileForUploading extends Error {\n name = 'NoFileForUploading';\n}\n\nexport class BadRequestError extends Error {\n name = 'BadRequestError';\n}\n\n/** Low-level client for grpc uploadapi.\n * The user should pass here a concrete BlobUpload/<storageId> resource,\n * it can be got from handle field of BlobUpload. */\nexport class ClientUpload {\n private readonly wire: WireClientProvider<UploadRestClientType | UploadClient>;\n\n constructor(\n wireClientProviderFactory: WireClientProviderFactory,\n public readonly httpClient: Dispatcher,\n _: PlClient,\n public readonly logger: MiLogger,\n ) {\n this.wire = wireClientProviderFactory.createWireClientProvider(\n (wire) => {\n if (wire.type === 'grpc') {\n return new UploadClient(wire.Transport);\n }\n\n return RestAPI.createClient<UploadApiPaths>({\n hostAndPort: wire.Config.hostAndPort,\n ssl: wire.Config.ssl,\n dispatcher: wire.Dispatcher,\n middlewares: wire.Middlewares,\n });\n },\n );\n }\n\n close() {}\n\n public async initUpload(\n { id, type }: ResourceInfo,\n options?: RpcOptions,\n ): Promise<{\n overall: bigint;\n toUpload: bigint[];\n checksumAlgorithm: UploadAPI_ChecksumAlgorithm;\n checksumHeader: string;\n }> {\n const client = this.wire.get();\n\n if (client instanceof UploadClient) {\n const init = (await client.init({ resourceId: id }, addRTypeToMetadata(type, options)))\n .response;\n\n return {\n overall: init.partsCount,\n toUpload: this.partsToUpload(init.partsCount, init.uploadedParts),\n checksumAlgorithm: init.checksumAlgorithm,\n checksumHeader: init.checksumHeader,\n };\n }\n\n const init = (await client.POST('/v1/upload/init', {\n body: {\n resourceId: id.toString(),\n },\n headers: { ...createRTypeRoutingHeader(type) },\n })).data!;\n\n return {\n overall: BigInt(init.partsCount),\n toUpload: this.partsToUpload(BigInt(init.partsCount), init.uploadedParts.map(BigInt)),\n checksumAlgorithm: init.checksumAlgorithm,\n checksumHeader: init.checksumHeader,\n };\n }\n\n public async partUpload(\n { id, type }: ResourceInfo,\n path: string,\n expectedMTimeUnix: bigint,\n partNumber: bigint,\n checksumAlgorithm: UploadAPI_ChecksumAlgorithm,\n checksumHeader: string,\n options?: RpcOptions,\n ) {\n const client = this.wire.get();\n\n let info: UploadAPI_GetPartURL_Response;\n if (client instanceof UploadClient) {\n // partChecksum isn't used for now but protoc requires it to be set\n info = (await client.getPartURL(\n {\n resourceId: id,\n partNumber,\n uploadedPartSize: 0n,\n isInternalUse: false,\n partChecksum: '',\n },\n addRTypeToMetadata(type, options),\n )).response;\n } else {\n const resp = (await client.POST('/v1/upload/get-part-url', {\n body: {\n resourceId: id.toString(),\n partNumber: partNumber.toString(),\n uploadedPartSize: '0',\n isInternalUse: false,\n partChecksum: '',\n },\n headers: { ...createRTypeRoutingHeader(type) },\n })).data!;\n info = {\n uploadUrl: resp.uploadUrl,\n method: resp.method,\n headers: resp.headers,\n chunkStart: BigInt(resp.chunkStart),\n chunkEnd: BigInt(resp.chunkEnd),\n };\n }\n\n const chunk = await readFileChunk(path, info.chunkStart, info.chunkEnd);\n await checkExpectedMTime(path, expectedMTimeUnix);\n\n const crc32cChecksum = calculateCrc32cChecksum(chunk);\n if (checksumAlgorithm === UploadAPI_ChecksumAlgorithm.CRC32C) {\n info.headers.push({ name: checksumHeader, value: crc32cChecksum });\n }\n\n const contentLength = Number(info.chunkEnd - info.chunkStart);\n if (chunk.length !== contentLength) {\n throw new Error(\n `Chunk size mismatch: expected ${contentLength} bytes, but read ${chunk.length} bytes from file`,\n );\n }\n\n const headers = Object.fromEntries(info.headers.map(({ name, value }) => [name.toLowerCase(), value]));\n\n try {\n const {\n body: rawBody,\n statusCode,\n headers: responseHeaders,\n } = await request(info.uploadUrl, {\n dispatcher: this.httpClient,\n body: chunk,\n // We got headers only after we send\n // the whole body (in case of S3 PUT requests it's 5 MB).\n // It might be slow with a slow connection (or with SSH),\n // that's why we got big timeout here.\n headersTimeout: 60000,\n bodyTimeout: 60000,\n // Prevent connection reuse by setting \"Connection: close\" header.\n // This works around an issue with the backend's built-in S3 implementation\n // that caused HTTP/1.1 protocol lines to be included in the uploaded file content.\n reset: true,\n headers,\n method: info.method.toUpperCase() as Dispatcher.HttpMethod,\n });\n\n // always read the body for resources to be garbage collected.\n const body = await rawBody.text();\n checkStatusCodeOk(statusCode, body, responseHeaders, info);\n } catch (e: unknown) {\n if (e instanceof NetworkError)\n throw e;\n\n if (e instanceof BadRequestError)\n throw e;\n\n throw new Error(`partUpload: error ${JSON.stringify(e)} happened while trying to do part upload to the url ${info.uploadUrl}, headers: ${JSON.stringify(info.headers)}`);\n }\n\n await this.updateProgress({ id, type }, BigInt(info.chunkEnd - info.chunkStart), options);\n }\n\n public async finalize(info: ResourceInfo, options?: RpcOptions) {\n const client = this.wire.get();\n\n if (client instanceof UploadClient) {\n await client.finalize({ resourceId: info.id }, addRTypeToMetadata(info.type, options));\n } else {\n await client.POST('/v1/upload/finalize', {\n body: {\n resourceId: info.id.toString(),\n },\n headers: { ...createRTypeRoutingHeader(info.type) },\n });\n }\n }\n\n /** Calculates parts that need to be uploaded from the parts that were\n * already uploaded. */\n private partsToUpload(partsCount: bigint, uploadedParts: bigint[]): bigint[] {\n const toUpload: bigint[] = [];\n const uploaded = new Set(uploadedParts);\n\n for (let i = 1n; i <= partsCount; i++) {\n if (!uploaded.has(i)) toUpload.push(i);\n }\n\n return toUpload;\n }\n\n private async updateProgress(\n { id, type }: ResourceInfo,\n bytesProcessed: bigint,\n options?: RpcOptions,\n ): Promise<void> {\n const client = this.wire.get();\n\n if (client instanceof UploadClient) {\n await client.updateProgress(\n {\n resourceId: id,\n bytesProcessed,\n },\n addRTypeToMetadata(type, options),\n ).response;\n return;\n }\n\n await client.POST('/v1/upload/update-progress', {\n body: {\n resourceId: id.toString(),\n bytesProcessed: bytesProcessed.toString(),\n },\n headers: { ...createRTypeRoutingHeader(type) },\n });\n return;\n }\n}\n\nasync function readFileChunk(path: string, chunkStart: bigint, chunkEnd: bigint): Promise<Buffer> {\n let f: fs.FileHandle | undefined;\n try {\n f = await fs.open(path);\n const len = Number(chunkEnd - chunkStart);\n const pos = Number(chunkStart);\n const b = Buffer.alloc(len);\n const bytesRead = await readBytesFromPosition(f, b, len, pos);\n\n return b.subarray(0, bytesRead);\n } catch (e: unknown) {\n if (e && typeof e === 'object' && ('code' in e) && e.code == 'ENOENT') throw new NoFileForUploading(`there is no file ${path} for uploading`);\n throw e;\n } finally {\n await f?.close();\n }\n}\n\n/** Read len bytes from a given position.\n * Without this, `FileHandle.read` can read less bytes than needed. */\nasync function readBytesFromPosition(f: fs.FileHandle, b: Buffer, len: number, position: number) {\n let bytesReadTotal = 0;\n while (bytesReadTotal < len) {\n const { bytesRead } = await f.read(\n b,\n bytesReadTotal,\n len - bytesReadTotal,\n position + bytesReadTotal,\n );\n if (bytesRead === 0) {\n throw new UnexpectedEOF('file ended earlier than expected.');\n }\n bytesReadTotal += bytesRead;\n }\n\n return bytesReadTotal;\n}\n\nasync function checkExpectedMTime(path: string, expectedMTimeUnix: bigint) {\n const mTime = BigInt(Math.floor((await fs.stat(path)).mtimeMs / 1000));\n if (mTime > expectedMTimeUnix) {\n throw new MTimeError(`file was modified, expected mtime: ${expectedMTimeUnix}, got: ${mTime}.`);\n }\n}\n\nfunction checkStatusCodeOk(\n statusCode: number,\n body: string,\n headers: IncomingHttpHeaders,\n info: UploadAPI_GetPartURL_Response,\n) {\n if (statusCode == 400) {\n throw new BadRequestError(`response is not ok, status code: ${statusCode},`\n + ` body: ${body}, headers: ${JSON.stringify(headers)}, url: ${info.uploadUrl}`);\n }\n\n if (statusCode != 200) {\n throw new NetworkError(\n `response is not ok, status code: ${statusCode},`\n + ` body: ${body}, headers: ${JSON.stringify(headers)}, url: ${info.uploadUrl}`,\n );\n }\n}\n\n/** Calculate CRC32C checksum of a buffer and return as base64 string */\nfunction calculateCrc32cChecksum(data: Buffer): string {\n const checksum = crc32c(data);\n // Convert to unsigned 32-bit integer and then to base64\n const buffer = Buffer.alloc(4);\n\n buffer.writeUInt32BE(checksum, 0);\n return buffer.toString('base64');\n}\n"],"names":["fs"],"m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AG,CAAC;IACjG;AACF;AAEA,SAAS,iBAAiB,CACxB,UAAkB,EAClB,IAAY,EACZ,OAA4B,EAC5B,IAAmC,EAAA;AAEnC,IAAA,IAAI,UAAU,IAAI,GAAG,EAAE;AACrB,QAAA,MAAM,IAAI,eAAe,CAAC,CAAA,iCAAA,EAAoC,UAAU,CAAA,CAAA;AACpE,cAAA,CAAA,OAAA,EAAU,IAAI,CAAA,WAAA,EAAc,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA,OAAA,EAAU,IAAI,CAAC,SAAS,CAAA,CAAE,CAAC;IACpF;AAEA,IAAA,IAAI,UAAU,IAAI,GAAG,EAAE;AACrB,QAAA,MAAM,IAAI,YAAY,CACpB,CAAA,iCAAA,EAAoC,UAAU,CAAA,CAAA;AAC5C,cAAA,CAAA,OAAA,EAAU,IAAI,CAAA,WAAA,EAAc,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA,OAAA,EAAU,IAAI,CAAC,SAAS,CAAA,CAAE,CAChF;IACH;AACF;AAEA;AACA,SAAS,uBAAuB,CAAC,IAAY,EAAA;AAC3C,IAAA,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC;;IAE7B,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAE9B,IAAA,MAAM,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC;AACjC,IAAA,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;AAClC;;;;"}
|
|
@@ -23,7 +23,7 @@ var blob_key = require('./blob_key.cjs');
|
|
|
23
23
|
var download_blob_task = require('./download_blob_task.cjs');
|
|
24
24
|
var files_cache = require('../helpers/files_cache.cjs');
|
|
25
25
|
var cache = require('./sparse_cache/cache.cjs');
|
|
26
|
-
var
|
|
26
|
+
var download_errors = require('../../helpers/download_errors.cjs');
|
|
27
27
|
|
|
28
28
|
function _interopNamespaceDefault(e) {
|
|
29
29
|
var n = Object.create(null);
|
|
@@ -194,7 +194,7 @@ class DownloadDriver {
|
|
|
194
194
|
return await request();
|
|
195
195
|
}
|
|
196
196
|
catch (error) {
|
|
197
|
-
if (
|
|
197
|
+
if (download_errors.isOffByOneError(error)) {
|
|
198
198
|
return await request();
|
|
199
199
|
}
|
|
200
200
|
throw error;
|