@bytescale/sdk 3.0.0-alpha.13 → 3.0.0-alpha.14
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/browser/cjs/main.js +52 -39
- package/dist/browser/esm/main.mjs +52 -39
- package/dist/node/cjs/main.js +54 -31
- package/dist/node/esm/main.mjs +54 -31
- package/dist/types/private/UploadManagerBase.d.ts +5 -1
- package/dist/types/private/model/OnPartProgress.d.ts +1 -1
- package/dist/types/public/browser/UploadManagerBrowser.d.ts +1 -1
- package/dist/worker/cjs/main.js +50 -29
- package/dist/worker/esm/main.mjs +50 -29
- package/package.json +1 -1
package/dist/browser/cjs/main.js
CHANGED
|
@@ -2044,10 +2044,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2044
2044
|
_this2.assertNotCancelled(request);
|
|
2045
2045
|
var source = _this2.processUploadSource(request.data);
|
|
2046
2046
|
var preUploadInfo = _this2.getPreUploadInfo(request, source);
|
|
2047
|
-
var
|
|
2047
|
+
var bytesTotal = preUploadInfo.size;
|
|
2048
|
+
var makeOnProgressForPart = _this2.makeOnProgressForPartFactory(request, bytesTotal);
|
|
2048
2049
|
var init = _this2.preUpload(source);
|
|
2049
2050
|
// Raise initial progress event SYNCHRONOUSLY.
|
|
2050
|
-
onProgress
|
|
2051
|
+
if (request.onProgress !== undefined) {
|
|
2052
|
+
request.onProgress(_this2.makeProgressEvent(0, bytesTotal));
|
|
2053
|
+
}
|
|
2051
2054
|
return UploadManagerBase_await(_this2.beginUpload(request, preUploadInfo), function (uploadInfo) {
|
|
2052
2055
|
var partCount = uploadInfo.uploadParts.count;
|
|
2053
2056
|
var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
|
|
@@ -2057,7 +2060,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2057
2060
|
var intervalHandle = setInterval(_this2.onIntervalTick(request, cancel), _this2.intervalMs);
|
|
2058
2061
|
return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
|
|
2059
2062
|
return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
|
|
2060
|
-
return _this2.uploadPart(request, source, part, uploadInfo,
|
|
2063
|
+
return _this2.uploadPart(request, source, part, uploadInfo, makeOnProgressForPart(), addCancellationHandler);
|
|
2061
2064
|
})), function () {
|
|
2062
2065
|
return UploadManagerBase_awaitIgnored(_this2.postUpload(init));
|
|
2063
2066
|
});
|
|
@@ -2113,21 +2116,37 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2113
2116
|
addCancellationHandler: addCancellationHandler
|
|
2114
2117
|
};
|
|
2115
2118
|
}
|
|
2119
|
+
/**
|
|
2120
|
+
* Returns a callback, which when called, returns a callback that can be used by ONE specific part to report its progress.
|
|
2121
|
+
*/
|
|
2116
2122
|
}, {
|
|
2117
|
-
key: "
|
|
2118
|
-
value: function
|
|
2123
|
+
key: "makeOnProgressForPartFactory",
|
|
2124
|
+
value: function makeOnProgressForPartFactory(request, bytesTotal) {
|
|
2125
|
+
var _this4 = this;
|
|
2119
2126
|
var onProgress = request.onProgress;
|
|
2120
2127
|
if (onProgress === undefined) {
|
|
2121
|
-
return function () {
|
|
2128
|
+
return function () {
|
|
2129
|
+
return function () {};
|
|
2130
|
+
};
|
|
2122
2131
|
}
|
|
2123
2132
|
var bytesSent = 0;
|
|
2124
|
-
return function (
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2133
|
+
return function () {
|
|
2134
|
+
var bytesSentForPart = 0;
|
|
2135
|
+
return function (bytesSentTotalForPart) {
|
|
2136
|
+
var delta = bytesSentTotalForPart - bytesSentForPart;
|
|
2137
|
+
bytesSentForPart += delta;
|
|
2138
|
+
bytesSent += delta;
|
|
2139
|
+
onProgress(_this4.makeProgressEvent(bytesSent, bytesTotal));
|
|
2140
|
+
};
|
|
2141
|
+
};
|
|
2142
|
+
}
|
|
2143
|
+
}, {
|
|
2144
|
+
key: "makeProgressEvent",
|
|
2145
|
+
value: function makeProgressEvent(bytesSent, bytesTotal) {
|
|
2146
|
+
return {
|
|
2147
|
+
bytesTotal: bytesTotal,
|
|
2148
|
+
bytesSent: bytesSent,
|
|
2149
|
+
progress: Math.round(bytesSent / bytesTotal * 100)
|
|
2131
2150
|
};
|
|
2132
2151
|
}
|
|
2133
2152
|
}, {
|
|
@@ -2150,9 +2169,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2150
2169
|
mime = _ref2.mime,
|
|
2151
2170
|
originalFileName = _ref2.originalFileName;
|
|
2152
2171
|
try {
|
|
2153
|
-
var
|
|
2154
|
-
return UploadManagerBase_await(
|
|
2155
|
-
accountId:
|
|
2172
|
+
var _this6 = this;
|
|
2173
|
+
return UploadManagerBase_await(_this6.uploadApi.beginMultipartUpload({
|
|
2174
|
+
accountId: _this6.accountId,
|
|
2156
2175
|
beginMultipartUploadRequest: {
|
|
2157
2176
|
metadata: request.metadata,
|
|
2158
2177
|
mime: mime,
|
|
@@ -2171,14 +2190,14 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2171
2190
|
key: "uploadPart",
|
|
2172
2191
|
value: function uploadPart(request, source, partIndex, uploadInfo, onProgress, addCancellationHandler) {
|
|
2173
2192
|
try {
|
|
2174
|
-
var
|
|
2175
|
-
|
|
2176
|
-
return UploadManagerBase_await(
|
|
2177
|
-
|
|
2178
|
-
return UploadManagerBase_await(
|
|
2179
|
-
|
|
2180
|
-
return UploadManagerBase_awaitIgnored(
|
|
2181
|
-
accountId:
|
|
2193
|
+
var _this8 = this;
|
|
2194
|
+
_this8.assertNotCancelled(request);
|
|
2195
|
+
return UploadManagerBase_await(_this8.getUploadPart(partIndex, uploadInfo), function (part) {
|
|
2196
|
+
_this8.assertNotCancelled(request);
|
|
2197
|
+
return UploadManagerBase_await(_this8.putUploadPart(part, source, onProgress, addCancellationHandler), function (etag) {
|
|
2198
|
+
_this8.assertNotCancelled(request);
|
|
2199
|
+
return UploadManagerBase_awaitIgnored(_this8.uploadApi.completeUploadPart({
|
|
2200
|
+
accountId: _this8.accountId,
|
|
2182
2201
|
uploadId: uploadInfo.uploadId,
|
|
2183
2202
|
uploadPartIndex: partIndex,
|
|
2184
2203
|
completeUploadPartRequest: {
|
|
@@ -2198,9 +2217,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2198
2217
|
key: "putUploadPart",
|
|
2199
2218
|
value: function putUploadPart(part, source, onProgress, addCancellationHandler) {
|
|
2200
2219
|
try {
|
|
2201
|
-
var
|
|
2220
|
+
var _this10 = this;
|
|
2202
2221
|
var contentLength = part.range.inclusiveEnd + 1 - part.range.inclusiveStart;
|
|
2203
|
-
return UploadManagerBase_await(
|
|
2222
|
+
return UploadManagerBase_await(_this10.doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler), function (_ref3) {
|
|
2204
2223
|
var status = _ref3.status,
|
|
2205
2224
|
etag = _ref3.etag;
|
|
2206
2225
|
if (Math.floor(status / 100) !== 2) {
|
|
@@ -2209,6 +2228,8 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2209
2228
|
if (etag === undefined) {
|
|
2210
2229
|
throw new Error("No 'etag' response header found in upload part response.");
|
|
2211
2230
|
}
|
|
2231
|
+
// Always send 100% for part, as some UploadManager implementations either don't report progress, or may not report the last chunk uploaded.
|
|
2232
|
+
onProgress(contentLength);
|
|
2212
2233
|
return etag;
|
|
2213
2234
|
});
|
|
2214
2235
|
} catch (e) {
|
|
@@ -2219,13 +2240,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2219
2240
|
key: "getUploadPart",
|
|
2220
2241
|
value: function getUploadPart(partIndex, uploadInfo) {
|
|
2221
2242
|
try {
|
|
2222
|
-
var
|
|
2243
|
+
var _this12 = this;
|
|
2223
2244
|
if (partIndex === 0) {
|
|
2224
2245
|
return uploadInfo.uploadParts.first;
|
|
2225
2246
|
}
|
|
2226
|
-
return UploadManagerBase_await(
|
|
2247
|
+
return UploadManagerBase_await(_this12.uploadApi.getUploadPart({
|
|
2227
2248
|
uploadId: uploadInfo.uploadId,
|
|
2228
|
-
accountId:
|
|
2249
|
+
accountId: _this12.accountId,
|
|
2229
2250
|
uploadPartIndex: partIndex
|
|
2230
2251
|
}));
|
|
2231
2252
|
} catch (e) {
|
|
@@ -2413,7 +2434,7 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBrowser) {
|
|
|
2413
2434
|
}
|
|
2414
2435
|
UploadManagerBrowser_createClass(UploadManager, [{
|
|
2415
2436
|
key: "doPutUploadPart",
|
|
2416
|
-
value: function doPutUploadPart(part,
|
|
2437
|
+
value: function doPutUploadPart(part, _contentLength, source, onProgress, addCancellationHandler) {
|
|
2417
2438
|
try {
|
|
2418
2439
|
var _this2 = this;
|
|
2419
2440
|
var xhr = new XMLHttpRequest();
|
|
@@ -2423,23 +2444,15 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBrowser) {
|
|
|
2423
2444
|
xhr.abort();
|
|
2424
2445
|
}
|
|
2425
2446
|
});
|
|
2426
|
-
var lastBytesSent = 0;
|
|
2427
|
-
var setBytesSent = function setBytesSent(newBytesSent) {
|
|
2428
|
-
var delta = newBytesSent - lastBytesSent;
|
|
2429
|
-
lastBytesSent = newBytesSent;
|
|
2430
|
-
onProgress(delta);
|
|
2431
|
-
};
|
|
2432
2447
|
return UploadManagerBrowser_finallyRethrows(function () {
|
|
2433
2448
|
return UploadManagerBrowser_await(new Promise(function (resolve, reject) {
|
|
2434
2449
|
xhr.upload.addEventListener("progress", function (evt) {
|
|
2435
2450
|
if (evt.lengthComputable) {
|
|
2436
|
-
|
|
2451
|
+
onProgress(evt.loaded);
|
|
2437
2452
|
}
|
|
2438
2453
|
}, false);
|
|
2439
2454
|
xhr.addEventListener("load", function () {
|
|
2440
2455
|
var _a;
|
|
2441
|
-
// Ensure we always report the progress of a finished upload as 100%.
|
|
2442
|
-
setBytesSent(contentLength);
|
|
2443
2456
|
var etag = (_a = xhr.getResponseHeader("etag")) !== null && _a !== void 0 ? _a : undefined;
|
|
2444
2457
|
resolve({
|
|
2445
2458
|
etag: etag,
|
|
@@ -2029,10 +2029,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2029
2029
|
_this2.assertNotCancelled(request);
|
|
2030
2030
|
var source = _this2.processUploadSource(request.data);
|
|
2031
2031
|
var preUploadInfo = _this2.getPreUploadInfo(request, source);
|
|
2032
|
-
var
|
|
2032
|
+
var bytesTotal = preUploadInfo.size;
|
|
2033
|
+
var makeOnProgressForPart = _this2.makeOnProgressForPartFactory(request, bytesTotal);
|
|
2033
2034
|
var init = _this2.preUpload(source);
|
|
2034
2035
|
// Raise initial progress event SYNCHRONOUSLY.
|
|
2035
|
-
onProgress
|
|
2036
|
+
if (request.onProgress !== undefined) {
|
|
2037
|
+
request.onProgress(_this2.makeProgressEvent(0, bytesTotal));
|
|
2038
|
+
}
|
|
2036
2039
|
return UploadManagerBase_await(_this2.beginUpload(request, preUploadInfo), function (uploadInfo) {
|
|
2037
2040
|
var partCount = uploadInfo.uploadParts.count;
|
|
2038
2041
|
var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
|
|
@@ -2042,7 +2045,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2042
2045
|
var intervalHandle = setInterval(_this2.onIntervalTick(request, cancel), _this2.intervalMs);
|
|
2043
2046
|
return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
|
|
2044
2047
|
return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
|
|
2045
|
-
return _this2.uploadPart(request, source, part, uploadInfo,
|
|
2048
|
+
return _this2.uploadPart(request, source, part, uploadInfo, makeOnProgressForPart(), addCancellationHandler);
|
|
2046
2049
|
})), function () {
|
|
2047
2050
|
return UploadManagerBase_awaitIgnored(_this2.postUpload(init));
|
|
2048
2051
|
});
|
|
@@ -2098,21 +2101,37 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2098
2101
|
addCancellationHandler: addCancellationHandler
|
|
2099
2102
|
};
|
|
2100
2103
|
}
|
|
2104
|
+
/**
|
|
2105
|
+
* Returns a callback, which when called, returns a callback that can be used by ONE specific part to report its progress.
|
|
2106
|
+
*/
|
|
2101
2107
|
}, {
|
|
2102
|
-
key: "
|
|
2103
|
-
value: function
|
|
2108
|
+
key: "makeOnProgressForPartFactory",
|
|
2109
|
+
value: function makeOnProgressForPartFactory(request, bytesTotal) {
|
|
2110
|
+
var _this4 = this;
|
|
2104
2111
|
var onProgress = request.onProgress;
|
|
2105
2112
|
if (onProgress === undefined) {
|
|
2106
|
-
return function () {
|
|
2113
|
+
return function () {
|
|
2114
|
+
return function () {};
|
|
2115
|
+
};
|
|
2107
2116
|
}
|
|
2108
2117
|
var bytesSent = 0;
|
|
2109
|
-
return function (
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2118
|
+
return function () {
|
|
2119
|
+
var bytesSentForPart = 0;
|
|
2120
|
+
return function (bytesSentTotalForPart) {
|
|
2121
|
+
var delta = bytesSentTotalForPart - bytesSentForPart;
|
|
2122
|
+
bytesSentForPart += delta;
|
|
2123
|
+
bytesSent += delta;
|
|
2124
|
+
onProgress(_this4.makeProgressEvent(bytesSent, bytesTotal));
|
|
2125
|
+
};
|
|
2126
|
+
};
|
|
2127
|
+
}
|
|
2128
|
+
}, {
|
|
2129
|
+
key: "makeProgressEvent",
|
|
2130
|
+
value: function makeProgressEvent(bytesSent, bytesTotal) {
|
|
2131
|
+
return {
|
|
2132
|
+
bytesTotal: bytesTotal,
|
|
2133
|
+
bytesSent: bytesSent,
|
|
2134
|
+
progress: Math.round(bytesSent / bytesTotal * 100)
|
|
2116
2135
|
};
|
|
2117
2136
|
}
|
|
2118
2137
|
}, {
|
|
@@ -2135,9 +2154,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2135
2154
|
mime = _ref2.mime,
|
|
2136
2155
|
originalFileName = _ref2.originalFileName;
|
|
2137
2156
|
try {
|
|
2138
|
-
var
|
|
2139
|
-
return UploadManagerBase_await(
|
|
2140
|
-
accountId:
|
|
2157
|
+
var _this6 = this;
|
|
2158
|
+
return UploadManagerBase_await(_this6.uploadApi.beginMultipartUpload({
|
|
2159
|
+
accountId: _this6.accountId,
|
|
2141
2160
|
beginMultipartUploadRequest: {
|
|
2142
2161
|
metadata: request.metadata,
|
|
2143
2162
|
mime: mime,
|
|
@@ -2156,14 +2175,14 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2156
2175
|
key: "uploadPart",
|
|
2157
2176
|
value: function uploadPart(request, source, partIndex, uploadInfo, onProgress, addCancellationHandler) {
|
|
2158
2177
|
try {
|
|
2159
|
-
var
|
|
2160
|
-
|
|
2161
|
-
return UploadManagerBase_await(
|
|
2162
|
-
|
|
2163
|
-
return UploadManagerBase_await(
|
|
2164
|
-
|
|
2165
|
-
return UploadManagerBase_awaitIgnored(
|
|
2166
|
-
accountId:
|
|
2178
|
+
var _this8 = this;
|
|
2179
|
+
_this8.assertNotCancelled(request);
|
|
2180
|
+
return UploadManagerBase_await(_this8.getUploadPart(partIndex, uploadInfo), function (part) {
|
|
2181
|
+
_this8.assertNotCancelled(request);
|
|
2182
|
+
return UploadManagerBase_await(_this8.putUploadPart(part, source, onProgress, addCancellationHandler), function (etag) {
|
|
2183
|
+
_this8.assertNotCancelled(request);
|
|
2184
|
+
return UploadManagerBase_awaitIgnored(_this8.uploadApi.completeUploadPart({
|
|
2185
|
+
accountId: _this8.accountId,
|
|
2167
2186
|
uploadId: uploadInfo.uploadId,
|
|
2168
2187
|
uploadPartIndex: partIndex,
|
|
2169
2188
|
completeUploadPartRequest: {
|
|
@@ -2183,9 +2202,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2183
2202
|
key: "putUploadPart",
|
|
2184
2203
|
value: function putUploadPart(part, source, onProgress, addCancellationHandler) {
|
|
2185
2204
|
try {
|
|
2186
|
-
var
|
|
2205
|
+
var _this10 = this;
|
|
2187
2206
|
var contentLength = part.range.inclusiveEnd + 1 - part.range.inclusiveStart;
|
|
2188
|
-
return UploadManagerBase_await(
|
|
2207
|
+
return UploadManagerBase_await(_this10.doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler), function (_ref3) {
|
|
2189
2208
|
var status = _ref3.status,
|
|
2190
2209
|
etag = _ref3.etag;
|
|
2191
2210
|
if (Math.floor(status / 100) !== 2) {
|
|
@@ -2194,6 +2213,8 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2194
2213
|
if (etag === undefined) {
|
|
2195
2214
|
throw new Error("No 'etag' response header found in upload part response.");
|
|
2196
2215
|
}
|
|
2216
|
+
// Always send 100% for part, as some UploadManager implementations either don't report progress, or may not report the last chunk uploaded.
|
|
2217
|
+
onProgress(contentLength);
|
|
2197
2218
|
return etag;
|
|
2198
2219
|
});
|
|
2199
2220
|
} catch (e) {
|
|
@@ -2204,13 +2225,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2204
2225
|
key: "getUploadPart",
|
|
2205
2226
|
value: function getUploadPart(partIndex, uploadInfo) {
|
|
2206
2227
|
try {
|
|
2207
|
-
var
|
|
2228
|
+
var _this12 = this;
|
|
2208
2229
|
if (partIndex === 0) {
|
|
2209
2230
|
return uploadInfo.uploadParts.first;
|
|
2210
2231
|
}
|
|
2211
|
-
return UploadManagerBase_await(
|
|
2232
|
+
return UploadManagerBase_await(_this12.uploadApi.getUploadPart({
|
|
2212
2233
|
uploadId: uploadInfo.uploadId,
|
|
2213
|
-
accountId:
|
|
2234
|
+
accountId: _this12.accountId,
|
|
2214
2235
|
uploadPartIndex: partIndex
|
|
2215
2236
|
}));
|
|
2216
2237
|
} catch (e) {
|
|
@@ -2398,7 +2419,7 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBrowser) {
|
|
|
2398
2419
|
}
|
|
2399
2420
|
UploadManagerBrowser_createClass(UploadManager, [{
|
|
2400
2421
|
key: "doPutUploadPart",
|
|
2401
|
-
value: function doPutUploadPart(part,
|
|
2422
|
+
value: function doPutUploadPart(part, _contentLength, source, onProgress, addCancellationHandler) {
|
|
2402
2423
|
try {
|
|
2403
2424
|
var _this2 = this;
|
|
2404
2425
|
var xhr = new XMLHttpRequest();
|
|
@@ -2408,23 +2429,15 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBrowser) {
|
|
|
2408
2429
|
xhr.abort();
|
|
2409
2430
|
}
|
|
2410
2431
|
});
|
|
2411
|
-
var lastBytesSent = 0;
|
|
2412
|
-
var setBytesSent = function setBytesSent(newBytesSent) {
|
|
2413
|
-
var delta = newBytesSent - lastBytesSent;
|
|
2414
|
-
lastBytesSent = newBytesSent;
|
|
2415
|
-
onProgress(delta);
|
|
2416
|
-
};
|
|
2417
2432
|
return UploadManagerBrowser_finallyRethrows(function () {
|
|
2418
2433
|
return UploadManagerBrowser_await(new Promise(function (resolve, reject) {
|
|
2419
2434
|
xhr.upload.addEventListener("progress", function (evt) {
|
|
2420
2435
|
if (evt.lengthComputable) {
|
|
2421
|
-
|
|
2436
|
+
onProgress(evt.loaded);
|
|
2422
2437
|
}
|
|
2423
2438
|
}, false);
|
|
2424
2439
|
xhr.addEventListener("load", function () {
|
|
2425
2440
|
var _a;
|
|
2426
|
-
// Ensure we always report the progress of a finished upload as 100%.
|
|
2427
|
-
setBytesSent(contentLength);
|
|
2428
2441
|
var etag = (_a = xhr.getResponseHeader("etag")) !== null && _a !== void 0 ? _a : undefined;
|
|
2429
2442
|
resolve({
|
|
2430
2443
|
etag: etag,
|
package/dist/node/cjs/main.js
CHANGED
|
@@ -2044,10 +2044,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2044
2044
|
_this2.assertNotCancelled(request);
|
|
2045
2045
|
var source = _this2.processUploadSource(request.data);
|
|
2046
2046
|
var preUploadInfo = _this2.getPreUploadInfo(request, source);
|
|
2047
|
-
var
|
|
2047
|
+
var bytesTotal = preUploadInfo.size;
|
|
2048
|
+
var makeOnProgressForPart = _this2.makeOnProgressForPartFactory(request, bytesTotal);
|
|
2048
2049
|
var init = _this2.preUpload(source);
|
|
2049
2050
|
// Raise initial progress event SYNCHRONOUSLY.
|
|
2050
|
-
onProgress
|
|
2051
|
+
if (request.onProgress !== undefined) {
|
|
2052
|
+
request.onProgress(_this2.makeProgressEvent(0, bytesTotal));
|
|
2053
|
+
}
|
|
2051
2054
|
return UploadManagerBase_await(_this2.beginUpload(request, preUploadInfo), function (uploadInfo) {
|
|
2052
2055
|
var partCount = uploadInfo.uploadParts.count;
|
|
2053
2056
|
var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
|
|
@@ -2057,7 +2060,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2057
2060
|
var intervalHandle = setInterval(_this2.onIntervalTick(request, cancel), _this2.intervalMs);
|
|
2058
2061
|
return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
|
|
2059
2062
|
return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
|
|
2060
|
-
return _this2.uploadPart(request, source, part, uploadInfo,
|
|
2063
|
+
return _this2.uploadPart(request, source, part, uploadInfo, makeOnProgressForPart(), addCancellationHandler);
|
|
2061
2064
|
})), function () {
|
|
2062
2065
|
return UploadManagerBase_awaitIgnored(_this2.postUpload(init));
|
|
2063
2066
|
});
|
|
@@ -2113,21 +2116,37 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2113
2116
|
addCancellationHandler: addCancellationHandler
|
|
2114
2117
|
};
|
|
2115
2118
|
}
|
|
2119
|
+
/**
|
|
2120
|
+
* Returns a callback, which when called, returns a callback that can be used by ONE specific part to report its progress.
|
|
2121
|
+
*/
|
|
2116
2122
|
}, {
|
|
2117
|
-
key: "
|
|
2118
|
-
value: function
|
|
2123
|
+
key: "makeOnProgressForPartFactory",
|
|
2124
|
+
value: function makeOnProgressForPartFactory(request, bytesTotal) {
|
|
2125
|
+
var _this4 = this;
|
|
2119
2126
|
var onProgress = request.onProgress;
|
|
2120
2127
|
if (onProgress === undefined) {
|
|
2121
|
-
return function () {
|
|
2128
|
+
return function () {
|
|
2129
|
+
return function () {};
|
|
2130
|
+
};
|
|
2122
2131
|
}
|
|
2123
2132
|
var bytesSent = 0;
|
|
2124
|
-
return function (
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2133
|
+
return function () {
|
|
2134
|
+
var bytesSentForPart = 0;
|
|
2135
|
+
return function (bytesSentTotalForPart) {
|
|
2136
|
+
var delta = bytesSentTotalForPart - bytesSentForPart;
|
|
2137
|
+
bytesSentForPart += delta;
|
|
2138
|
+
bytesSent += delta;
|
|
2139
|
+
onProgress(_this4.makeProgressEvent(bytesSent, bytesTotal));
|
|
2140
|
+
};
|
|
2141
|
+
};
|
|
2142
|
+
}
|
|
2143
|
+
}, {
|
|
2144
|
+
key: "makeProgressEvent",
|
|
2145
|
+
value: function makeProgressEvent(bytesSent, bytesTotal) {
|
|
2146
|
+
return {
|
|
2147
|
+
bytesTotal: bytesTotal,
|
|
2148
|
+
bytesSent: bytesSent,
|
|
2149
|
+
progress: Math.round(bytesSent / bytesTotal * 100)
|
|
2131
2150
|
};
|
|
2132
2151
|
}
|
|
2133
2152
|
}, {
|
|
@@ -2150,9 +2169,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2150
2169
|
mime = _ref2.mime,
|
|
2151
2170
|
originalFileName = _ref2.originalFileName;
|
|
2152
2171
|
try {
|
|
2153
|
-
var
|
|
2154
|
-
return UploadManagerBase_await(
|
|
2155
|
-
accountId:
|
|
2172
|
+
var _this6 = this;
|
|
2173
|
+
return UploadManagerBase_await(_this6.uploadApi.beginMultipartUpload({
|
|
2174
|
+
accountId: _this6.accountId,
|
|
2156
2175
|
beginMultipartUploadRequest: {
|
|
2157
2176
|
metadata: request.metadata,
|
|
2158
2177
|
mime: mime,
|
|
@@ -2171,14 +2190,14 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2171
2190
|
key: "uploadPart",
|
|
2172
2191
|
value: function uploadPart(request, source, partIndex, uploadInfo, onProgress, addCancellationHandler) {
|
|
2173
2192
|
try {
|
|
2174
|
-
var
|
|
2175
|
-
|
|
2176
|
-
return UploadManagerBase_await(
|
|
2177
|
-
|
|
2178
|
-
return UploadManagerBase_await(
|
|
2179
|
-
|
|
2180
|
-
return UploadManagerBase_awaitIgnored(
|
|
2181
|
-
accountId:
|
|
2193
|
+
var _this8 = this;
|
|
2194
|
+
_this8.assertNotCancelled(request);
|
|
2195
|
+
return UploadManagerBase_await(_this8.getUploadPart(partIndex, uploadInfo), function (part) {
|
|
2196
|
+
_this8.assertNotCancelled(request);
|
|
2197
|
+
return UploadManagerBase_await(_this8.putUploadPart(part, source, onProgress, addCancellationHandler), function (etag) {
|
|
2198
|
+
_this8.assertNotCancelled(request);
|
|
2199
|
+
return UploadManagerBase_awaitIgnored(_this8.uploadApi.completeUploadPart({
|
|
2200
|
+
accountId: _this8.accountId,
|
|
2182
2201
|
uploadId: uploadInfo.uploadId,
|
|
2183
2202
|
uploadPartIndex: partIndex,
|
|
2184
2203
|
completeUploadPartRequest: {
|
|
@@ -2198,9 +2217,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2198
2217
|
key: "putUploadPart",
|
|
2199
2218
|
value: function putUploadPart(part, source, onProgress, addCancellationHandler) {
|
|
2200
2219
|
try {
|
|
2201
|
-
var
|
|
2220
|
+
var _this10 = this;
|
|
2202
2221
|
var contentLength = part.range.inclusiveEnd + 1 - part.range.inclusiveStart;
|
|
2203
|
-
return UploadManagerBase_await(
|
|
2222
|
+
return UploadManagerBase_await(_this10.doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler), function (_ref3) {
|
|
2204
2223
|
var status = _ref3.status,
|
|
2205
2224
|
etag = _ref3.etag;
|
|
2206
2225
|
if (Math.floor(status / 100) !== 2) {
|
|
@@ -2209,6 +2228,8 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2209
2228
|
if (etag === undefined) {
|
|
2210
2229
|
throw new Error("No 'etag' response header found in upload part response.");
|
|
2211
2230
|
}
|
|
2231
|
+
// Always send 100% for part, as some UploadManager implementations either don't report progress, or may not report the last chunk uploaded.
|
|
2232
|
+
onProgress(contentLength);
|
|
2212
2233
|
return etag;
|
|
2213
2234
|
});
|
|
2214
2235
|
} catch (e) {
|
|
@@ -2219,13 +2240,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2219
2240
|
key: "getUploadPart",
|
|
2220
2241
|
value: function getUploadPart(partIndex, uploadInfo) {
|
|
2221
2242
|
try {
|
|
2222
|
-
var
|
|
2243
|
+
var _this12 = this;
|
|
2223
2244
|
if (partIndex === 0) {
|
|
2224
2245
|
return uploadInfo.uploadParts.first;
|
|
2225
2246
|
}
|
|
2226
|
-
return UploadManagerBase_await(
|
|
2247
|
+
return UploadManagerBase_await(_this12.uploadApi.getUploadPart({
|
|
2227
2248
|
uploadId: uploadInfo.uploadId,
|
|
2228
|
-
accountId:
|
|
2249
|
+
accountId: _this12.accountId,
|
|
2229
2250
|
uploadPartIndex: partIndex
|
|
2230
2251
|
}));
|
|
2231
2252
|
} catch (e) {
|
|
@@ -2872,10 +2893,12 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
|
|
|
2872
2893
|
var _this2 = this;
|
|
2873
2894
|
// Report progress:
|
|
2874
2895
|
var hasWarned = false;
|
|
2896
|
+
var bytesSent = 0;
|
|
2875
2897
|
return UploadManagerNode_await(_this2.sliceDataForRequest(source, part), function (stream) {
|
|
2876
2898
|
var streamWithProgress = stream.on("data", function (data) {
|
|
2877
|
-
if (data.
|
|
2878
|
-
|
|
2899
|
+
if (data.byteLength !== undefined) {
|
|
2900
|
+
bytesSent += data.byteLength;
|
|
2901
|
+
onProgress(bytesSent);
|
|
2879
2902
|
} else if (!hasWarned) {
|
|
2880
2903
|
hasWarned = true;
|
|
2881
2904
|
console.warn("Expected stream to contain buffers, but it did not, so upload progress won't be reported.");
|
package/dist/node/esm/main.mjs
CHANGED
|
@@ -2031,10 +2031,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2031
2031
|
_this2.assertNotCancelled(request);
|
|
2032
2032
|
var source = _this2.processUploadSource(request.data);
|
|
2033
2033
|
var preUploadInfo = _this2.getPreUploadInfo(request, source);
|
|
2034
|
-
var
|
|
2034
|
+
var bytesTotal = preUploadInfo.size;
|
|
2035
|
+
var makeOnProgressForPart = _this2.makeOnProgressForPartFactory(request, bytesTotal);
|
|
2035
2036
|
var init = _this2.preUpload(source);
|
|
2036
2037
|
// Raise initial progress event SYNCHRONOUSLY.
|
|
2037
|
-
onProgress
|
|
2038
|
+
if (request.onProgress !== undefined) {
|
|
2039
|
+
request.onProgress(_this2.makeProgressEvent(0, bytesTotal));
|
|
2040
|
+
}
|
|
2038
2041
|
return UploadManagerBase_await(_this2.beginUpload(request, preUploadInfo), function (uploadInfo) {
|
|
2039
2042
|
var partCount = uploadInfo.uploadParts.count;
|
|
2040
2043
|
var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
|
|
@@ -2044,7 +2047,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2044
2047
|
var intervalHandle = setInterval(_this2.onIntervalTick(request, cancel), _this2.intervalMs);
|
|
2045
2048
|
return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
|
|
2046
2049
|
return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
|
|
2047
|
-
return _this2.uploadPart(request, source, part, uploadInfo,
|
|
2050
|
+
return _this2.uploadPart(request, source, part, uploadInfo, makeOnProgressForPart(), addCancellationHandler);
|
|
2048
2051
|
})), function () {
|
|
2049
2052
|
return UploadManagerBase_awaitIgnored(_this2.postUpload(init));
|
|
2050
2053
|
});
|
|
@@ -2100,21 +2103,37 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2100
2103
|
addCancellationHandler: addCancellationHandler
|
|
2101
2104
|
};
|
|
2102
2105
|
}
|
|
2106
|
+
/**
|
|
2107
|
+
* Returns a callback, which when called, returns a callback that can be used by ONE specific part to report its progress.
|
|
2108
|
+
*/
|
|
2103
2109
|
}, {
|
|
2104
|
-
key: "
|
|
2105
|
-
value: function
|
|
2110
|
+
key: "makeOnProgressForPartFactory",
|
|
2111
|
+
value: function makeOnProgressForPartFactory(request, bytesTotal) {
|
|
2112
|
+
var _this4 = this;
|
|
2106
2113
|
var onProgress = request.onProgress;
|
|
2107
2114
|
if (onProgress === undefined) {
|
|
2108
|
-
return function () {
|
|
2115
|
+
return function () {
|
|
2116
|
+
return function () {};
|
|
2117
|
+
};
|
|
2109
2118
|
}
|
|
2110
2119
|
var bytesSent = 0;
|
|
2111
|
-
return function (
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2120
|
+
return function () {
|
|
2121
|
+
var bytesSentForPart = 0;
|
|
2122
|
+
return function (bytesSentTotalForPart) {
|
|
2123
|
+
var delta = bytesSentTotalForPart - bytesSentForPart;
|
|
2124
|
+
bytesSentForPart += delta;
|
|
2125
|
+
bytesSent += delta;
|
|
2126
|
+
onProgress(_this4.makeProgressEvent(bytesSent, bytesTotal));
|
|
2127
|
+
};
|
|
2128
|
+
};
|
|
2129
|
+
}
|
|
2130
|
+
}, {
|
|
2131
|
+
key: "makeProgressEvent",
|
|
2132
|
+
value: function makeProgressEvent(bytesSent, bytesTotal) {
|
|
2133
|
+
return {
|
|
2134
|
+
bytesTotal: bytesTotal,
|
|
2135
|
+
bytesSent: bytesSent,
|
|
2136
|
+
progress: Math.round(bytesSent / bytesTotal * 100)
|
|
2118
2137
|
};
|
|
2119
2138
|
}
|
|
2120
2139
|
}, {
|
|
@@ -2137,9 +2156,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2137
2156
|
mime = _ref2.mime,
|
|
2138
2157
|
originalFileName = _ref2.originalFileName;
|
|
2139
2158
|
try {
|
|
2140
|
-
var
|
|
2141
|
-
return UploadManagerBase_await(
|
|
2142
|
-
accountId:
|
|
2159
|
+
var _this6 = this;
|
|
2160
|
+
return UploadManagerBase_await(_this6.uploadApi.beginMultipartUpload({
|
|
2161
|
+
accountId: _this6.accountId,
|
|
2143
2162
|
beginMultipartUploadRequest: {
|
|
2144
2163
|
metadata: request.metadata,
|
|
2145
2164
|
mime: mime,
|
|
@@ -2158,14 +2177,14 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2158
2177
|
key: "uploadPart",
|
|
2159
2178
|
value: function uploadPart(request, source, partIndex, uploadInfo, onProgress, addCancellationHandler) {
|
|
2160
2179
|
try {
|
|
2161
|
-
var
|
|
2162
|
-
|
|
2163
|
-
return UploadManagerBase_await(
|
|
2164
|
-
|
|
2165
|
-
return UploadManagerBase_await(
|
|
2166
|
-
|
|
2167
|
-
return UploadManagerBase_awaitIgnored(
|
|
2168
|
-
accountId:
|
|
2180
|
+
var _this8 = this;
|
|
2181
|
+
_this8.assertNotCancelled(request);
|
|
2182
|
+
return UploadManagerBase_await(_this8.getUploadPart(partIndex, uploadInfo), function (part) {
|
|
2183
|
+
_this8.assertNotCancelled(request);
|
|
2184
|
+
return UploadManagerBase_await(_this8.putUploadPart(part, source, onProgress, addCancellationHandler), function (etag) {
|
|
2185
|
+
_this8.assertNotCancelled(request);
|
|
2186
|
+
return UploadManagerBase_awaitIgnored(_this8.uploadApi.completeUploadPart({
|
|
2187
|
+
accountId: _this8.accountId,
|
|
2169
2188
|
uploadId: uploadInfo.uploadId,
|
|
2170
2189
|
uploadPartIndex: partIndex,
|
|
2171
2190
|
completeUploadPartRequest: {
|
|
@@ -2185,9 +2204,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2185
2204
|
key: "putUploadPart",
|
|
2186
2205
|
value: function putUploadPart(part, source, onProgress, addCancellationHandler) {
|
|
2187
2206
|
try {
|
|
2188
|
-
var
|
|
2207
|
+
var _this10 = this;
|
|
2189
2208
|
var contentLength = part.range.inclusiveEnd + 1 - part.range.inclusiveStart;
|
|
2190
|
-
return UploadManagerBase_await(
|
|
2209
|
+
return UploadManagerBase_await(_this10.doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler), function (_ref3) {
|
|
2191
2210
|
var status = _ref3.status,
|
|
2192
2211
|
etag = _ref3.etag;
|
|
2193
2212
|
if (Math.floor(status / 100) !== 2) {
|
|
@@ -2196,6 +2215,8 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2196
2215
|
if (etag === undefined) {
|
|
2197
2216
|
throw new Error("No 'etag' response header found in upload part response.");
|
|
2198
2217
|
}
|
|
2218
|
+
// Always send 100% for part, as some UploadManager implementations either don't report progress, or may not report the last chunk uploaded.
|
|
2219
|
+
onProgress(contentLength);
|
|
2199
2220
|
return etag;
|
|
2200
2221
|
});
|
|
2201
2222
|
} catch (e) {
|
|
@@ -2206,13 +2227,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2206
2227
|
key: "getUploadPart",
|
|
2207
2228
|
value: function getUploadPart(partIndex, uploadInfo) {
|
|
2208
2229
|
try {
|
|
2209
|
-
var
|
|
2230
|
+
var _this12 = this;
|
|
2210
2231
|
if (partIndex === 0) {
|
|
2211
2232
|
return uploadInfo.uploadParts.first;
|
|
2212
2233
|
}
|
|
2213
|
-
return UploadManagerBase_await(
|
|
2234
|
+
return UploadManagerBase_await(_this12.uploadApi.getUploadPart({
|
|
2214
2235
|
uploadId: uploadInfo.uploadId,
|
|
2215
|
-
accountId:
|
|
2236
|
+
accountId: _this12.accountId,
|
|
2216
2237
|
uploadPartIndex: partIndex
|
|
2217
2238
|
}));
|
|
2218
2239
|
} catch (e) {
|
|
@@ -2863,10 +2884,12 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
|
|
|
2863
2884
|
var _this2 = this;
|
|
2864
2885
|
// Report progress:
|
|
2865
2886
|
var hasWarned = false;
|
|
2887
|
+
var bytesSent = 0;
|
|
2866
2888
|
return UploadManagerNode_await(_this2.sliceDataForRequest(source, part), function (stream) {
|
|
2867
2889
|
var streamWithProgress = stream.on("data", function (data) {
|
|
2868
|
-
if (data.
|
|
2869
|
-
|
|
2890
|
+
if (data.byteLength !== undefined) {
|
|
2891
|
+
bytesSent += data.byteLength;
|
|
2892
|
+
onProgress(bytesSent);
|
|
2870
2893
|
} else if (!hasWarned) {
|
|
2871
2894
|
hasWarned = true;
|
|
2872
2895
|
console.warn("Expected stream to contain buffers, but it did not, so upload progress won't be reported.");
|
|
@@ -29,7 +29,11 @@ export declare abstract class UploadManagerBase<TSource, TInit> implements Uploa
|
|
|
29
29
|
protected abstract doPutUploadPart(part: UploadPart, contentLength: number, source: TSource, onProgress: (bytesSentDelta: number) => void, addCancellationHandler: AddCancellationHandler): Promise<PutUploadPartResult>;
|
|
30
30
|
private onIntervalTick;
|
|
31
31
|
private makeCancellationMethods;
|
|
32
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Returns a callback, which when called, returns a callback that can be used by ONE specific part to report its progress.
|
|
34
|
+
*/
|
|
35
|
+
private makeOnProgressForPartFactory;
|
|
36
|
+
private makeProgressEvent;
|
|
33
37
|
private assertNotCancelled;
|
|
34
38
|
private isCancelled;
|
|
35
39
|
private beginUpload;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare type OnPartProgress = (
|
|
1
|
+
export declare type OnPartProgress = (bytesSentTotalForPart: number) => void;
|
|
@@ -4,5 +4,5 @@ import { PutUploadPartResult } from "../../private/model/PutUploadPartResult";
|
|
|
4
4
|
import { AddCancellationHandler } from "../../private/model/AddCancellationHandler";
|
|
5
5
|
import { UploadManagerBrowserWorkerBase } from "../../private/UploadManagerBrowserWorkerBase";
|
|
6
6
|
export declare class UploadManager extends UploadManagerBrowserWorkerBase {
|
|
7
|
-
protected doPutUploadPart(part: UploadPart,
|
|
7
|
+
protected doPutUploadPart(part: UploadPart, _contentLength: number, source: UploadSourceProcessedBrowser, onProgress: (bytesSentDelta: number) => void, addCancellationHandler: AddCancellationHandler): Promise<PutUploadPartResult>;
|
|
8
8
|
}
|
package/dist/worker/cjs/main.js
CHANGED
|
@@ -2044,10 +2044,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2044
2044
|
_this2.assertNotCancelled(request);
|
|
2045
2045
|
var source = _this2.processUploadSource(request.data);
|
|
2046
2046
|
var preUploadInfo = _this2.getPreUploadInfo(request, source);
|
|
2047
|
-
var
|
|
2047
|
+
var bytesTotal = preUploadInfo.size;
|
|
2048
|
+
var makeOnProgressForPart = _this2.makeOnProgressForPartFactory(request, bytesTotal);
|
|
2048
2049
|
var init = _this2.preUpload(source);
|
|
2049
2050
|
// Raise initial progress event SYNCHRONOUSLY.
|
|
2050
|
-
onProgress
|
|
2051
|
+
if (request.onProgress !== undefined) {
|
|
2052
|
+
request.onProgress(_this2.makeProgressEvent(0, bytesTotal));
|
|
2053
|
+
}
|
|
2051
2054
|
return UploadManagerBase_await(_this2.beginUpload(request, preUploadInfo), function (uploadInfo) {
|
|
2052
2055
|
var partCount = uploadInfo.uploadParts.count;
|
|
2053
2056
|
var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
|
|
@@ -2057,7 +2060,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2057
2060
|
var intervalHandle = setInterval(_this2.onIntervalTick(request, cancel), _this2.intervalMs);
|
|
2058
2061
|
return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
|
|
2059
2062
|
return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
|
|
2060
|
-
return _this2.uploadPart(request, source, part, uploadInfo,
|
|
2063
|
+
return _this2.uploadPart(request, source, part, uploadInfo, makeOnProgressForPart(), addCancellationHandler);
|
|
2061
2064
|
})), function () {
|
|
2062
2065
|
return UploadManagerBase_awaitIgnored(_this2.postUpload(init));
|
|
2063
2066
|
});
|
|
@@ -2113,21 +2116,37 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2113
2116
|
addCancellationHandler: addCancellationHandler
|
|
2114
2117
|
};
|
|
2115
2118
|
}
|
|
2119
|
+
/**
|
|
2120
|
+
* Returns a callback, which when called, returns a callback that can be used by ONE specific part to report its progress.
|
|
2121
|
+
*/
|
|
2116
2122
|
}, {
|
|
2117
|
-
key: "
|
|
2118
|
-
value: function
|
|
2123
|
+
key: "makeOnProgressForPartFactory",
|
|
2124
|
+
value: function makeOnProgressForPartFactory(request, bytesTotal) {
|
|
2125
|
+
var _this4 = this;
|
|
2119
2126
|
var onProgress = request.onProgress;
|
|
2120
2127
|
if (onProgress === undefined) {
|
|
2121
|
-
return function () {
|
|
2128
|
+
return function () {
|
|
2129
|
+
return function () {};
|
|
2130
|
+
};
|
|
2122
2131
|
}
|
|
2123
2132
|
var bytesSent = 0;
|
|
2124
|
-
return function (
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2133
|
+
return function () {
|
|
2134
|
+
var bytesSentForPart = 0;
|
|
2135
|
+
return function (bytesSentTotalForPart) {
|
|
2136
|
+
var delta = bytesSentTotalForPart - bytesSentForPart;
|
|
2137
|
+
bytesSentForPart += delta;
|
|
2138
|
+
bytesSent += delta;
|
|
2139
|
+
onProgress(_this4.makeProgressEvent(bytesSent, bytesTotal));
|
|
2140
|
+
};
|
|
2141
|
+
};
|
|
2142
|
+
}
|
|
2143
|
+
}, {
|
|
2144
|
+
key: "makeProgressEvent",
|
|
2145
|
+
value: function makeProgressEvent(bytesSent, bytesTotal) {
|
|
2146
|
+
return {
|
|
2147
|
+
bytesTotal: bytesTotal,
|
|
2148
|
+
bytesSent: bytesSent,
|
|
2149
|
+
progress: Math.round(bytesSent / bytesTotal * 100)
|
|
2131
2150
|
};
|
|
2132
2151
|
}
|
|
2133
2152
|
}, {
|
|
@@ -2150,9 +2169,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2150
2169
|
mime = _ref2.mime,
|
|
2151
2170
|
originalFileName = _ref2.originalFileName;
|
|
2152
2171
|
try {
|
|
2153
|
-
var
|
|
2154
|
-
return UploadManagerBase_await(
|
|
2155
|
-
accountId:
|
|
2172
|
+
var _this6 = this;
|
|
2173
|
+
return UploadManagerBase_await(_this6.uploadApi.beginMultipartUpload({
|
|
2174
|
+
accountId: _this6.accountId,
|
|
2156
2175
|
beginMultipartUploadRequest: {
|
|
2157
2176
|
metadata: request.metadata,
|
|
2158
2177
|
mime: mime,
|
|
@@ -2171,14 +2190,14 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2171
2190
|
key: "uploadPart",
|
|
2172
2191
|
value: function uploadPart(request, source, partIndex, uploadInfo, onProgress, addCancellationHandler) {
|
|
2173
2192
|
try {
|
|
2174
|
-
var
|
|
2175
|
-
|
|
2176
|
-
return UploadManagerBase_await(
|
|
2177
|
-
|
|
2178
|
-
return UploadManagerBase_await(
|
|
2179
|
-
|
|
2180
|
-
return UploadManagerBase_awaitIgnored(
|
|
2181
|
-
accountId:
|
|
2193
|
+
var _this8 = this;
|
|
2194
|
+
_this8.assertNotCancelled(request);
|
|
2195
|
+
return UploadManagerBase_await(_this8.getUploadPart(partIndex, uploadInfo), function (part) {
|
|
2196
|
+
_this8.assertNotCancelled(request);
|
|
2197
|
+
return UploadManagerBase_await(_this8.putUploadPart(part, source, onProgress, addCancellationHandler), function (etag) {
|
|
2198
|
+
_this8.assertNotCancelled(request);
|
|
2199
|
+
return UploadManagerBase_awaitIgnored(_this8.uploadApi.completeUploadPart({
|
|
2200
|
+
accountId: _this8.accountId,
|
|
2182
2201
|
uploadId: uploadInfo.uploadId,
|
|
2183
2202
|
uploadPartIndex: partIndex,
|
|
2184
2203
|
completeUploadPartRequest: {
|
|
@@ -2198,9 +2217,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2198
2217
|
key: "putUploadPart",
|
|
2199
2218
|
value: function putUploadPart(part, source, onProgress, addCancellationHandler) {
|
|
2200
2219
|
try {
|
|
2201
|
-
var
|
|
2220
|
+
var _this10 = this;
|
|
2202
2221
|
var contentLength = part.range.inclusiveEnd + 1 - part.range.inclusiveStart;
|
|
2203
|
-
return UploadManagerBase_await(
|
|
2222
|
+
return UploadManagerBase_await(_this10.doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler), function (_ref3) {
|
|
2204
2223
|
var status = _ref3.status,
|
|
2205
2224
|
etag = _ref3.etag;
|
|
2206
2225
|
if (Math.floor(status / 100) !== 2) {
|
|
@@ -2209,6 +2228,8 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2209
2228
|
if (etag === undefined) {
|
|
2210
2229
|
throw new Error("No 'etag' response header found in upload part response.");
|
|
2211
2230
|
}
|
|
2231
|
+
// Always send 100% for part, as some UploadManager implementations either don't report progress, or may not report the last chunk uploaded.
|
|
2232
|
+
onProgress(contentLength);
|
|
2212
2233
|
return etag;
|
|
2213
2234
|
});
|
|
2214
2235
|
} catch (e) {
|
|
@@ -2219,13 +2240,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2219
2240
|
key: "getUploadPart",
|
|
2220
2241
|
value: function getUploadPart(partIndex, uploadInfo) {
|
|
2221
2242
|
try {
|
|
2222
|
-
var
|
|
2243
|
+
var _this12 = this;
|
|
2223
2244
|
if (partIndex === 0) {
|
|
2224
2245
|
return uploadInfo.uploadParts.first;
|
|
2225
2246
|
}
|
|
2226
|
-
return UploadManagerBase_await(
|
|
2247
|
+
return UploadManagerBase_await(_this12.uploadApi.getUploadPart({
|
|
2227
2248
|
uploadId: uploadInfo.uploadId,
|
|
2228
|
-
accountId:
|
|
2249
|
+
accountId: _this12.accountId,
|
|
2229
2250
|
uploadPartIndex: partIndex
|
|
2230
2251
|
}));
|
|
2231
2252
|
} catch (e) {
|
package/dist/worker/esm/main.mjs
CHANGED
|
@@ -2029,10 +2029,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2029
2029
|
_this2.assertNotCancelled(request);
|
|
2030
2030
|
var source = _this2.processUploadSource(request.data);
|
|
2031
2031
|
var preUploadInfo = _this2.getPreUploadInfo(request, source);
|
|
2032
|
-
var
|
|
2032
|
+
var bytesTotal = preUploadInfo.size;
|
|
2033
|
+
var makeOnProgressForPart = _this2.makeOnProgressForPartFactory(request, bytesTotal);
|
|
2033
2034
|
var init = _this2.preUpload(source);
|
|
2034
2035
|
// Raise initial progress event SYNCHRONOUSLY.
|
|
2035
|
-
onProgress
|
|
2036
|
+
if (request.onProgress !== undefined) {
|
|
2037
|
+
request.onProgress(_this2.makeProgressEvent(0, bytesTotal));
|
|
2038
|
+
}
|
|
2036
2039
|
return UploadManagerBase_await(_this2.beginUpload(request, preUploadInfo), function (uploadInfo) {
|
|
2037
2040
|
var partCount = uploadInfo.uploadParts.count;
|
|
2038
2041
|
var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
|
|
@@ -2042,7 +2045,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2042
2045
|
var intervalHandle = setInterval(_this2.onIntervalTick(request, cancel), _this2.intervalMs);
|
|
2043
2046
|
return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
|
|
2044
2047
|
return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
|
|
2045
|
-
return _this2.uploadPart(request, source, part, uploadInfo,
|
|
2048
|
+
return _this2.uploadPart(request, source, part, uploadInfo, makeOnProgressForPart(), addCancellationHandler);
|
|
2046
2049
|
})), function () {
|
|
2047
2050
|
return UploadManagerBase_awaitIgnored(_this2.postUpload(init));
|
|
2048
2051
|
});
|
|
@@ -2098,21 +2101,37 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2098
2101
|
addCancellationHandler: addCancellationHandler
|
|
2099
2102
|
};
|
|
2100
2103
|
}
|
|
2104
|
+
/**
|
|
2105
|
+
* Returns a callback, which when called, returns a callback that can be used by ONE specific part to report its progress.
|
|
2106
|
+
*/
|
|
2101
2107
|
}, {
|
|
2102
|
-
key: "
|
|
2103
|
-
value: function
|
|
2108
|
+
key: "makeOnProgressForPartFactory",
|
|
2109
|
+
value: function makeOnProgressForPartFactory(request, bytesTotal) {
|
|
2110
|
+
var _this4 = this;
|
|
2104
2111
|
var onProgress = request.onProgress;
|
|
2105
2112
|
if (onProgress === undefined) {
|
|
2106
|
-
return function () {
|
|
2113
|
+
return function () {
|
|
2114
|
+
return function () {};
|
|
2115
|
+
};
|
|
2107
2116
|
}
|
|
2108
2117
|
var bytesSent = 0;
|
|
2109
|
-
return function (
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2118
|
+
return function () {
|
|
2119
|
+
var bytesSentForPart = 0;
|
|
2120
|
+
return function (bytesSentTotalForPart) {
|
|
2121
|
+
var delta = bytesSentTotalForPart - bytesSentForPart;
|
|
2122
|
+
bytesSentForPart += delta;
|
|
2123
|
+
bytesSent += delta;
|
|
2124
|
+
onProgress(_this4.makeProgressEvent(bytesSent, bytesTotal));
|
|
2125
|
+
};
|
|
2126
|
+
};
|
|
2127
|
+
}
|
|
2128
|
+
}, {
|
|
2129
|
+
key: "makeProgressEvent",
|
|
2130
|
+
value: function makeProgressEvent(bytesSent, bytesTotal) {
|
|
2131
|
+
return {
|
|
2132
|
+
bytesTotal: bytesTotal,
|
|
2133
|
+
bytesSent: bytesSent,
|
|
2134
|
+
progress: Math.round(bytesSent / bytesTotal * 100)
|
|
2116
2135
|
};
|
|
2117
2136
|
}
|
|
2118
2137
|
}, {
|
|
@@ -2135,9 +2154,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2135
2154
|
mime = _ref2.mime,
|
|
2136
2155
|
originalFileName = _ref2.originalFileName;
|
|
2137
2156
|
try {
|
|
2138
|
-
var
|
|
2139
|
-
return UploadManagerBase_await(
|
|
2140
|
-
accountId:
|
|
2157
|
+
var _this6 = this;
|
|
2158
|
+
return UploadManagerBase_await(_this6.uploadApi.beginMultipartUpload({
|
|
2159
|
+
accountId: _this6.accountId,
|
|
2141
2160
|
beginMultipartUploadRequest: {
|
|
2142
2161
|
metadata: request.metadata,
|
|
2143
2162
|
mime: mime,
|
|
@@ -2156,14 +2175,14 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2156
2175
|
key: "uploadPart",
|
|
2157
2176
|
value: function uploadPart(request, source, partIndex, uploadInfo, onProgress, addCancellationHandler) {
|
|
2158
2177
|
try {
|
|
2159
|
-
var
|
|
2160
|
-
|
|
2161
|
-
return UploadManagerBase_await(
|
|
2162
|
-
|
|
2163
|
-
return UploadManagerBase_await(
|
|
2164
|
-
|
|
2165
|
-
return UploadManagerBase_awaitIgnored(
|
|
2166
|
-
accountId:
|
|
2178
|
+
var _this8 = this;
|
|
2179
|
+
_this8.assertNotCancelled(request);
|
|
2180
|
+
return UploadManagerBase_await(_this8.getUploadPart(partIndex, uploadInfo), function (part) {
|
|
2181
|
+
_this8.assertNotCancelled(request);
|
|
2182
|
+
return UploadManagerBase_await(_this8.putUploadPart(part, source, onProgress, addCancellationHandler), function (etag) {
|
|
2183
|
+
_this8.assertNotCancelled(request);
|
|
2184
|
+
return UploadManagerBase_awaitIgnored(_this8.uploadApi.completeUploadPart({
|
|
2185
|
+
accountId: _this8.accountId,
|
|
2167
2186
|
uploadId: uploadInfo.uploadId,
|
|
2168
2187
|
uploadPartIndex: partIndex,
|
|
2169
2188
|
completeUploadPartRequest: {
|
|
@@ -2183,9 +2202,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2183
2202
|
key: "putUploadPart",
|
|
2184
2203
|
value: function putUploadPart(part, source, onProgress, addCancellationHandler) {
|
|
2185
2204
|
try {
|
|
2186
|
-
var
|
|
2205
|
+
var _this10 = this;
|
|
2187
2206
|
var contentLength = part.range.inclusiveEnd + 1 - part.range.inclusiveStart;
|
|
2188
|
-
return UploadManagerBase_await(
|
|
2207
|
+
return UploadManagerBase_await(_this10.doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler), function (_ref3) {
|
|
2189
2208
|
var status = _ref3.status,
|
|
2190
2209
|
etag = _ref3.etag;
|
|
2191
2210
|
if (Math.floor(status / 100) !== 2) {
|
|
@@ -2194,6 +2213,8 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2194
2213
|
if (etag === undefined) {
|
|
2195
2214
|
throw new Error("No 'etag' response header found in upload part response.");
|
|
2196
2215
|
}
|
|
2216
|
+
// Always send 100% for part, as some UploadManager implementations either don't report progress, or may not report the last chunk uploaded.
|
|
2217
|
+
onProgress(contentLength);
|
|
2197
2218
|
return etag;
|
|
2198
2219
|
});
|
|
2199
2220
|
} catch (e) {
|
|
@@ -2204,13 +2225,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2204
2225
|
key: "getUploadPart",
|
|
2205
2226
|
value: function getUploadPart(partIndex, uploadInfo) {
|
|
2206
2227
|
try {
|
|
2207
|
-
var
|
|
2228
|
+
var _this12 = this;
|
|
2208
2229
|
if (partIndex === 0) {
|
|
2209
2230
|
return uploadInfo.uploadParts.first;
|
|
2210
2231
|
}
|
|
2211
|
-
return UploadManagerBase_await(
|
|
2232
|
+
return UploadManagerBase_await(_this12.uploadApi.getUploadPart({
|
|
2212
2233
|
uploadId: uploadInfo.uploadId,
|
|
2213
|
-
accountId:
|
|
2234
|
+
accountId: _this12.accountId,
|
|
2214
2235
|
uploadPartIndex: partIndex
|
|
2215
2236
|
}));
|
|
2216
2237
|
} catch (e) {
|