@bytescale/sdk 3.0.0-alpha.13 → 3.0.0-alpha.15
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/README.md +5 -5
- package/dist/browser/cjs/main.js +63 -41
- package/dist/browser/esm/main.mjs +63 -41
- package/dist/node/cjs/main.js +67 -34
- package/dist/node/esm/main.mjs +67 -34
- package/dist/types/private/Mutex.d.ts +1 -1
- 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 +63 -32
- package/dist/worker/esm/main.mjs +63 -32
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -83,7 +83,7 @@ import * as Bytescale from "@bytescale/sdk";
|
|
|
83
83
|
import nodeFetch from "node-fetch";
|
|
84
84
|
|
|
85
85
|
const uploadManager = new Bytescale.UploadManager({
|
|
86
|
-
fetchApi: nodeFetch, // import nodeFetch from "node-fetch"; // Only required for Node.js
|
|
86
|
+
fetchApi: nodeFetch, // import nodeFetch from "node-fetch"; // Only required for Node.js. TypeScript: 'nodeFetch as any' may be necessary.
|
|
87
87
|
apiKey: "free" // Get API keys from: www.bytescale.com
|
|
88
88
|
});
|
|
89
89
|
|
|
@@ -242,7 +242,7 @@ import * as Bytescale from "@bytescale/sdk";
|
|
|
242
242
|
import nodeFetch from "node-fetch"; // Only required for Node.js
|
|
243
243
|
|
|
244
244
|
const fileApi = new Bytescale.FileApi({
|
|
245
|
-
fetchApi: nodeFetch, // import nodeFetch from "node-fetch"; // Only required for Node.js
|
|
245
|
+
fetchApi: nodeFetch, // import nodeFetch from "node-fetch"; // Only required for Node.js. TypeScript: 'nodeFetch as any' may be necessary.
|
|
246
246
|
apiKey: "YOUR_API_KEY" // e.g. "secret_xxxxx"
|
|
247
247
|
});
|
|
248
248
|
|
|
@@ -268,7 +268,7 @@ import fetch from "node-fetch"; // Only required for Node.js
|
|
|
268
268
|
import fs from "fs";
|
|
269
269
|
|
|
270
270
|
const fileApi = new Bytescale.FileApi({
|
|
271
|
-
fetchApi: nodeFetch, // import nodeFetch from "node-fetch"; // Only required for Node.js
|
|
271
|
+
fetchApi: nodeFetch, // import nodeFetch from "node-fetch"; // Only required for Node.js. TypeScript: 'nodeFetch as any' may be necessary.
|
|
272
272
|
apiKey: "YOUR_API_KEY" // e.g. "secret_xxxxx"
|
|
273
273
|
});
|
|
274
274
|
|
|
@@ -309,7 +309,7 @@ import * as Bytescale from "@bytescale/sdk";
|
|
|
309
309
|
import fetch from "node-fetch"; // Only required for Node.js
|
|
310
310
|
|
|
311
311
|
const fileApi = new Bytescale.FileApi({
|
|
312
|
-
fetchApi: nodeFetch, // import nodeFetch from "node-fetch"; // Only required for Node.js
|
|
312
|
+
fetchApi: nodeFetch, // import nodeFetch from "node-fetch"; // Only required for Node.js. TypeScript: 'nodeFetch as any' may be necessary.
|
|
313
313
|
apiKey: "YOUR_API_KEY" // e.g. "secret_xxxxx"
|
|
314
314
|
});
|
|
315
315
|
|
|
@@ -331,7 +331,7 @@ import * as Bytescale from "@bytescale/sdk";
|
|
|
331
331
|
import fetch from "node-fetch"; // Only required for Node.js
|
|
332
332
|
|
|
333
333
|
const folderApi = new Bytescale.FolderApi({
|
|
334
|
-
fetchApi: nodeFetch, // import nodeFetch from "node-fetch"; // Only required for Node.js
|
|
334
|
+
fetchApi: nodeFetch, // import nodeFetch from "node-fetch"; // Only required for Node.js. TypeScript: 'nodeFetch as any' may be necessary.
|
|
335
335
|
apiKey: "YOUR_API_KEY" // e.g. "secret_xxxxx"
|
|
336
336
|
});
|
|
337
337
|
|
package/dist/browser/cjs/main.js
CHANGED
|
@@ -259,7 +259,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
259
259
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
260
260
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
261
261
|
/**
|
|
262
|
-
* A lightweight mutex. (Other libraries contain too many features and we want to keep
|
|
262
|
+
* A lightweight mutex. (Other libraries contain too many features and we want to keep size down).
|
|
263
263
|
*
|
|
264
264
|
* Characteristics:
|
|
265
265
|
* - Non-reentrant.
|
|
@@ -543,7 +543,16 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
543
543
|
var _a, _b;
|
|
544
544
|
var response;
|
|
545
545
|
return runtime_continue(_catch(function () {
|
|
546
|
-
return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(_this4.config)(url, init),
|
|
546
|
+
return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(_this4.config)(url, Object.assign(Object.assign({}, init), {
|
|
547
|
+
// This is specifically added to cater for Next.js's Fetch implementation, which caches POST requests...
|
|
548
|
+
//
|
|
549
|
+
// "fetch requests that use the POST method are also automatically cached."
|
|
550
|
+
// - https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#caching-data
|
|
551
|
+
//
|
|
552
|
+
// However, this is probably a good idea, even for all GET requests, as if the user is refreshing a JWT
|
|
553
|
+
// or downloading a file via 'FileApi.downloadFile', then they'll likely want the latest.
|
|
554
|
+
cache: "no-store"
|
|
555
|
+
})), function (_BytescaleApiClientCo) {
|
|
547
556
|
response = _BytescaleApiClientCo;
|
|
548
557
|
});
|
|
549
558
|
}, function (e) {
|
|
@@ -2044,10 +2053,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2044
2053
|
_this2.assertNotCancelled(request);
|
|
2045
2054
|
var source = _this2.processUploadSource(request.data);
|
|
2046
2055
|
var preUploadInfo = _this2.getPreUploadInfo(request, source);
|
|
2047
|
-
var
|
|
2056
|
+
var bytesTotal = preUploadInfo.size;
|
|
2057
|
+
var makeOnProgressForPart = _this2.makeOnProgressForPartFactory(request, bytesTotal);
|
|
2048
2058
|
var init = _this2.preUpload(source);
|
|
2049
2059
|
// Raise initial progress event SYNCHRONOUSLY.
|
|
2050
|
-
onProgress
|
|
2060
|
+
if (request.onProgress !== undefined) {
|
|
2061
|
+
request.onProgress(_this2.makeProgressEvent(0, bytesTotal));
|
|
2062
|
+
}
|
|
2051
2063
|
return UploadManagerBase_await(_this2.beginUpload(request, preUploadInfo), function (uploadInfo) {
|
|
2052
2064
|
var partCount = uploadInfo.uploadParts.count;
|
|
2053
2065
|
var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
|
|
@@ -2057,7 +2069,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2057
2069
|
var intervalHandle = setInterval(_this2.onIntervalTick(request, cancel), _this2.intervalMs);
|
|
2058
2070
|
return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
|
|
2059
2071
|
return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
|
|
2060
|
-
return _this2.uploadPart(request, source, part, uploadInfo,
|
|
2072
|
+
return _this2.uploadPart(request, source, part, uploadInfo, makeOnProgressForPart(), addCancellationHandler);
|
|
2061
2073
|
})), function () {
|
|
2062
2074
|
return UploadManagerBase_awaitIgnored(_this2.postUpload(init));
|
|
2063
2075
|
});
|
|
@@ -2113,21 +2125,37 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2113
2125
|
addCancellationHandler: addCancellationHandler
|
|
2114
2126
|
};
|
|
2115
2127
|
}
|
|
2128
|
+
/**
|
|
2129
|
+
* Returns a callback, which when called, returns a callback that can be used by ONE specific part to report its progress.
|
|
2130
|
+
*/
|
|
2116
2131
|
}, {
|
|
2117
|
-
key: "
|
|
2118
|
-
value: function
|
|
2132
|
+
key: "makeOnProgressForPartFactory",
|
|
2133
|
+
value: function makeOnProgressForPartFactory(request, bytesTotal) {
|
|
2134
|
+
var _this4 = this;
|
|
2119
2135
|
var onProgress = request.onProgress;
|
|
2120
2136
|
if (onProgress === undefined) {
|
|
2121
|
-
return function () {
|
|
2137
|
+
return function () {
|
|
2138
|
+
return function () {};
|
|
2139
|
+
};
|
|
2122
2140
|
}
|
|
2123
2141
|
var bytesSent = 0;
|
|
2124
|
-
return function (
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2142
|
+
return function () {
|
|
2143
|
+
var bytesSentForPart = 0;
|
|
2144
|
+
return function (bytesSentTotalForPart) {
|
|
2145
|
+
var delta = bytesSentTotalForPart - bytesSentForPart;
|
|
2146
|
+
bytesSentForPart += delta;
|
|
2147
|
+
bytesSent += delta;
|
|
2148
|
+
onProgress(_this4.makeProgressEvent(bytesSent, bytesTotal));
|
|
2149
|
+
};
|
|
2150
|
+
};
|
|
2151
|
+
}
|
|
2152
|
+
}, {
|
|
2153
|
+
key: "makeProgressEvent",
|
|
2154
|
+
value: function makeProgressEvent(bytesSent, bytesTotal) {
|
|
2155
|
+
return {
|
|
2156
|
+
bytesTotal: bytesTotal,
|
|
2157
|
+
bytesSent: bytesSent,
|
|
2158
|
+
progress: Math.round(bytesSent / bytesTotal * 100)
|
|
2131
2159
|
};
|
|
2132
2160
|
}
|
|
2133
2161
|
}, {
|
|
@@ -2150,9 +2178,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2150
2178
|
mime = _ref2.mime,
|
|
2151
2179
|
originalFileName = _ref2.originalFileName;
|
|
2152
2180
|
try {
|
|
2153
|
-
var
|
|
2154
|
-
return UploadManagerBase_await(
|
|
2155
|
-
accountId:
|
|
2181
|
+
var _this6 = this;
|
|
2182
|
+
return UploadManagerBase_await(_this6.uploadApi.beginMultipartUpload({
|
|
2183
|
+
accountId: _this6.accountId,
|
|
2156
2184
|
beginMultipartUploadRequest: {
|
|
2157
2185
|
metadata: request.metadata,
|
|
2158
2186
|
mime: mime,
|
|
@@ -2171,14 +2199,14 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2171
2199
|
key: "uploadPart",
|
|
2172
2200
|
value: function uploadPart(request, source, partIndex, uploadInfo, onProgress, addCancellationHandler) {
|
|
2173
2201
|
try {
|
|
2174
|
-
var
|
|
2175
|
-
|
|
2176
|
-
return UploadManagerBase_await(
|
|
2177
|
-
|
|
2178
|
-
return UploadManagerBase_await(
|
|
2179
|
-
|
|
2180
|
-
return UploadManagerBase_awaitIgnored(
|
|
2181
|
-
accountId:
|
|
2202
|
+
var _this8 = this;
|
|
2203
|
+
_this8.assertNotCancelled(request);
|
|
2204
|
+
return UploadManagerBase_await(_this8.getUploadPart(partIndex, uploadInfo), function (part) {
|
|
2205
|
+
_this8.assertNotCancelled(request);
|
|
2206
|
+
return UploadManagerBase_await(_this8.putUploadPart(part, source, onProgress, addCancellationHandler), function (etag) {
|
|
2207
|
+
_this8.assertNotCancelled(request);
|
|
2208
|
+
return UploadManagerBase_awaitIgnored(_this8.uploadApi.completeUploadPart({
|
|
2209
|
+
accountId: _this8.accountId,
|
|
2182
2210
|
uploadId: uploadInfo.uploadId,
|
|
2183
2211
|
uploadPartIndex: partIndex,
|
|
2184
2212
|
completeUploadPartRequest: {
|
|
@@ -2198,9 +2226,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2198
2226
|
key: "putUploadPart",
|
|
2199
2227
|
value: function putUploadPart(part, source, onProgress, addCancellationHandler) {
|
|
2200
2228
|
try {
|
|
2201
|
-
var
|
|
2229
|
+
var _this10 = this;
|
|
2202
2230
|
var contentLength = part.range.inclusiveEnd + 1 - part.range.inclusiveStart;
|
|
2203
|
-
return UploadManagerBase_await(
|
|
2231
|
+
return UploadManagerBase_await(_this10.doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler), function (_ref3) {
|
|
2204
2232
|
var status = _ref3.status,
|
|
2205
2233
|
etag = _ref3.etag;
|
|
2206
2234
|
if (Math.floor(status / 100) !== 2) {
|
|
@@ -2209,6 +2237,8 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2209
2237
|
if (etag === undefined) {
|
|
2210
2238
|
throw new Error("No 'etag' response header found in upload part response.");
|
|
2211
2239
|
}
|
|
2240
|
+
// Always send 100% for part, as some UploadManager implementations either don't report progress, or may not report the last chunk uploaded.
|
|
2241
|
+
onProgress(contentLength);
|
|
2212
2242
|
return etag;
|
|
2213
2243
|
});
|
|
2214
2244
|
} catch (e) {
|
|
@@ -2219,13 +2249,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2219
2249
|
key: "getUploadPart",
|
|
2220
2250
|
value: function getUploadPart(partIndex, uploadInfo) {
|
|
2221
2251
|
try {
|
|
2222
|
-
var
|
|
2252
|
+
var _this12 = this;
|
|
2223
2253
|
if (partIndex === 0) {
|
|
2224
2254
|
return uploadInfo.uploadParts.first;
|
|
2225
2255
|
}
|
|
2226
|
-
return UploadManagerBase_await(
|
|
2256
|
+
return UploadManagerBase_await(_this12.uploadApi.getUploadPart({
|
|
2227
2257
|
uploadId: uploadInfo.uploadId,
|
|
2228
|
-
accountId:
|
|
2258
|
+
accountId: _this12.accountId,
|
|
2229
2259
|
uploadPartIndex: partIndex
|
|
2230
2260
|
}));
|
|
2231
2261
|
} catch (e) {
|
|
@@ -2413,7 +2443,7 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBrowser) {
|
|
|
2413
2443
|
}
|
|
2414
2444
|
UploadManagerBrowser_createClass(UploadManager, [{
|
|
2415
2445
|
key: "doPutUploadPart",
|
|
2416
|
-
value: function doPutUploadPart(part,
|
|
2446
|
+
value: function doPutUploadPart(part, _contentLength, source, onProgress, addCancellationHandler) {
|
|
2417
2447
|
try {
|
|
2418
2448
|
var _this2 = this;
|
|
2419
2449
|
var xhr = new XMLHttpRequest();
|
|
@@ -2423,23 +2453,15 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBrowser) {
|
|
|
2423
2453
|
xhr.abort();
|
|
2424
2454
|
}
|
|
2425
2455
|
});
|
|
2426
|
-
var lastBytesSent = 0;
|
|
2427
|
-
var setBytesSent = function setBytesSent(newBytesSent) {
|
|
2428
|
-
var delta = newBytesSent - lastBytesSent;
|
|
2429
|
-
lastBytesSent = newBytesSent;
|
|
2430
|
-
onProgress(delta);
|
|
2431
|
-
};
|
|
2432
2456
|
return UploadManagerBrowser_finallyRethrows(function () {
|
|
2433
2457
|
return UploadManagerBrowser_await(new Promise(function (resolve, reject) {
|
|
2434
2458
|
xhr.upload.addEventListener("progress", function (evt) {
|
|
2435
2459
|
if (evt.lengthComputable) {
|
|
2436
|
-
|
|
2460
|
+
onProgress(evt.loaded);
|
|
2437
2461
|
}
|
|
2438
2462
|
}, false);
|
|
2439
2463
|
xhr.addEventListener("load", function () {
|
|
2440
2464
|
var _a;
|
|
2441
|
-
// Ensure we always report the progress of a finished upload as 100%.
|
|
2442
|
-
setBytesSent(contentLength);
|
|
2443
2465
|
var etag = (_a = xhr.getResponseHeader("etag")) !== null && _a !== void 0 ? _a : undefined;
|
|
2444
2466
|
resolve({
|
|
2445
2467
|
etag: etag,
|
|
@@ -244,7 +244,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
244
244
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
245
245
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
246
246
|
/**
|
|
247
|
-
* A lightweight mutex. (Other libraries contain too many features and we want to keep
|
|
247
|
+
* A lightweight mutex. (Other libraries contain too many features and we want to keep size down).
|
|
248
248
|
*
|
|
249
249
|
* Characteristics:
|
|
250
250
|
* - Non-reentrant.
|
|
@@ -528,7 +528,16 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
528
528
|
var _a, _b;
|
|
529
529
|
var response;
|
|
530
530
|
return runtime_continue(_catch(function () {
|
|
531
|
-
return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(_this4.config)(url, init),
|
|
531
|
+
return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(_this4.config)(url, Object.assign(Object.assign({}, init), {
|
|
532
|
+
// This is specifically added to cater for Next.js's Fetch implementation, which caches POST requests...
|
|
533
|
+
//
|
|
534
|
+
// "fetch requests that use the POST method are also automatically cached."
|
|
535
|
+
// - https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#caching-data
|
|
536
|
+
//
|
|
537
|
+
// However, this is probably a good idea, even for all GET requests, as if the user is refreshing a JWT
|
|
538
|
+
// or downloading a file via 'FileApi.downloadFile', then they'll likely want the latest.
|
|
539
|
+
cache: "no-store"
|
|
540
|
+
})), function (_BytescaleApiClientCo) {
|
|
532
541
|
response = _BytescaleApiClientCo;
|
|
533
542
|
});
|
|
534
543
|
}, function (e) {
|
|
@@ -2029,10 +2038,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2029
2038
|
_this2.assertNotCancelled(request);
|
|
2030
2039
|
var source = _this2.processUploadSource(request.data);
|
|
2031
2040
|
var preUploadInfo = _this2.getPreUploadInfo(request, source);
|
|
2032
|
-
var
|
|
2041
|
+
var bytesTotal = preUploadInfo.size;
|
|
2042
|
+
var makeOnProgressForPart = _this2.makeOnProgressForPartFactory(request, bytesTotal);
|
|
2033
2043
|
var init = _this2.preUpload(source);
|
|
2034
2044
|
// Raise initial progress event SYNCHRONOUSLY.
|
|
2035
|
-
onProgress
|
|
2045
|
+
if (request.onProgress !== undefined) {
|
|
2046
|
+
request.onProgress(_this2.makeProgressEvent(0, bytesTotal));
|
|
2047
|
+
}
|
|
2036
2048
|
return UploadManagerBase_await(_this2.beginUpload(request, preUploadInfo), function (uploadInfo) {
|
|
2037
2049
|
var partCount = uploadInfo.uploadParts.count;
|
|
2038
2050
|
var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
|
|
@@ -2042,7 +2054,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2042
2054
|
var intervalHandle = setInterval(_this2.onIntervalTick(request, cancel), _this2.intervalMs);
|
|
2043
2055
|
return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
|
|
2044
2056
|
return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
|
|
2045
|
-
return _this2.uploadPart(request, source, part, uploadInfo,
|
|
2057
|
+
return _this2.uploadPart(request, source, part, uploadInfo, makeOnProgressForPart(), addCancellationHandler);
|
|
2046
2058
|
})), function () {
|
|
2047
2059
|
return UploadManagerBase_awaitIgnored(_this2.postUpload(init));
|
|
2048
2060
|
});
|
|
@@ -2098,21 +2110,37 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2098
2110
|
addCancellationHandler: addCancellationHandler
|
|
2099
2111
|
};
|
|
2100
2112
|
}
|
|
2113
|
+
/**
|
|
2114
|
+
* Returns a callback, which when called, returns a callback that can be used by ONE specific part to report its progress.
|
|
2115
|
+
*/
|
|
2101
2116
|
}, {
|
|
2102
|
-
key: "
|
|
2103
|
-
value: function
|
|
2117
|
+
key: "makeOnProgressForPartFactory",
|
|
2118
|
+
value: function makeOnProgressForPartFactory(request, bytesTotal) {
|
|
2119
|
+
var _this4 = this;
|
|
2104
2120
|
var onProgress = request.onProgress;
|
|
2105
2121
|
if (onProgress === undefined) {
|
|
2106
|
-
return function () {
|
|
2122
|
+
return function () {
|
|
2123
|
+
return function () {};
|
|
2124
|
+
};
|
|
2107
2125
|
}
|
|
2108
2126
|
var bytesSent = 0;
|
|
2109
|
-
return function (
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2127
|
+
return function () {
|
|
2128
|
+
var bytesSentForPart = 0;
|
|
2129
|
+
return function (bytesSentTotalForPart) {
|
|
2130
|
+
var delta = bytesSentTotalForPart - bytesSentForPart;
|
|
2131
|
+
bytesSentForPart += delta;
|
|
2132
|
+
bytesSent += delta;
|
|
2133
|
+
onProgress(_this4.makeProgressEvent(bytesSent, bytesTotal));
|
|
2134
|
+
};
|
|
2135
|
+
};
|
|
2136
|
+
}
|
|
2137
|
+
}, {
|
|
2138
|
+
key: "makeProgressEvent",
|
|
2139
|
+
value: function makeProgressEvent(bytesSent, bytesTotal) {
|
|
2140
|
+
return {
|
|
2141
|
+
bytesTotal: bytesTotal,
|
|
2142
|
+
bytesSent: bytesSent,
|
|
2143
|
+
progress: Math.round(bytesSent / bytesTotal * 100)
|
|
2116
2144
|
};
|
|
2117
2145
|
}
|
|
2118
2146
|
}, {
|
|
@@ -2135,9 +2163,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2135
2163
|
mime = _ref2.mime,
|
|
2136
2164
|
originalFileName = _ref2.originalFileName;
|
|
2137
2165
|
try {
|
|
2138
|
-
var
|
|
2139
|
-
return UploadManagerBase_await(
|
|
2140
|
-
accountId:
|
|
2166
|
+
var _this6 = this;
|
|
2167
|
+
return UploadManagerBase_await(_this6.uploadApi.beginMultipartUpload({
|
|
2168
|
+
accountId: _this6.accountId,
|
|
2141
2169
|
beginMultipartUploadRequest: {
|
|
2142
2170
|
metadata: request.metadata,
|
|
2143
2171
|
mime: mime,
|
|
@@ -2156,14 +2184,14 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2156
2184
|
key: "uploadPart",
|
|
2157
2185
|
value: function uploadPart(request, source, partIndex, uploadInfo, onProgress, addCancellationHandler) {
|
|
2158
2186
|
try {
|
|
2159
|
-
var
|
|
2160
|
-
|
|
2161
|
-
return UploadManagerBase_await(
|
|
2162
|
-
|
|
2163
|
-
return UploadManagerBase_await(
|
|
2164
|
-
|
|
2165
|
-
return UploadManagerBase_awaitIgnored(
|
|
2166
|
-
accountId:
|
|
2187
|
+
var _this8 = this;
|
|
2188
|
+
_this8.assertNotCancelled(request);
|
|
2189
|
+
return UploadManagerBase_await(_this8.getUploadPart(partIndex, uploadInfo), function (part) {
|
|
2190
|
+
_this8.assertNotCancelled(request);
|
|
2191
|
+
return UploadManagerBase_await(_this8.putUploadPart(part, source, onProgress, addCancellationHandler), function (etag) {
|
|
2192
|
+
_this8.assertNotCancelled(request);
|
|
2193
|
+
return UploadManagerBase_awaitIgnored(_this8.uploadApi.completeUploadPart({
|
|
2194
|
+
accountId: _this8.accountId,
|
|
2167
2195
|
uploadId: uploadInfo.uploadId,
|
|
2168
2196
|
uploadPartIndex: partIndex,
|
|
2169
2197
|
completeUploadPartRequest: {
|
|
@@ -2183,9 +2211,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2183
2211
|
key: "putUploadPart",
|
|
2184
2212
|
value: function putUploadPart(part, source, onProgress, addCancellationHandler) {
|
|
2185
2213
|
try {
|
|
2186
|
-
var
|
|
2214
|
+
var _this10 = this;
|
|
2187
2215
|
var contentLength = part.range.inclusiveEnd + 1 - part.range.inclusiveStart;
|
|
2188
|
-
return UploadManagerBase_await(
|
|
2216
|
+
return UploadManagerBase_await(_this10.doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler), function (_ref3) {
|
|
2189
2217
|
var status = _ref3.status,
|
|
2190
2218
|
etag = _ref3.etag;
|
|
2191
2219
|
if (Math.floor(status / 100) !== 2) {
|
|
@@ -2194,6 +2222,8 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2194
2222
|
if (etag === undefined) {
|
|
2195
2223
|
throw new Error("No 'etag' response header found in upload part response.");
|
|
2196
2224
|
}
|
|
2225
|
+
// Always send 100% for part, as some UploadManager implementations either don't report progress, or may not report the last chunk uploaded.
|
|
2226
|
+
onProgress(contentLength);
|
|
2197
2227
|
return etag;
|
|
2198
2228
|
});
|
|
2199
2229
|
} catch (e) {
|
|
@@ -2204,13 +2234,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2204
2234
|
key: "getUploadPart",
|
|
2205
2235
|
value: function getUploadPart(partIndex, uploadInfo) {
|
|
2206
2236
|
try {
|
|
2207
|
-
var
|
|
2237
|
+
var _this12 = this;
|
|
2208
2238
|
if (partIndex === 0) {
|
|
2209
2239
|
return uploadInfo.uploadParts.first;
|
|
2210
2240
|
}
|
|
2211
|
-
return UploadManagerBase_await(
|
|
2241
|
+
return UploadManagerBase_await(_this12.uploadApi.getUploadPart({
|
|
2212
2242
|
uploadId: uploadInfo.uploadId,
|
|
2213
|
-
accountId:
|
|
2243
|
+
accountId: _this12.accountId,
|
|
2214
2244
|
uploadPartIndex: partIndex
|
|
2215
2245
|
}));
|
|
2216
2246
|
} catch (e) {
|
|
@@ -2398,7 +2428,7 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBrowser) {
|
|
|
2398
2428
|
}
|
|
2399
2429
|
UploadManagerBrowser_createClass(UploadManager, [{
|
|
2400
2430
|
key: "doPutUploadPart",
|
|
2401
|
-
value: function doPutUploadPart(part,
|
|
2431
|
+
value: function doPutUploadPart(part, _contentLength, source, onProgress, addCancellationHandler) {
|
|
2402
2432
|
try {
|
|
2403
2433
|
var _this2 = this;
|
|
2404
2434
|
var xhr = new XMLHttpRequest();
|
|
@@ -2408,23 +2438,15 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBrowser) {
|
|
|
2408
2438
|
xhr.abort();
|
|
2409
2439
|
}
|
|
2410
2440
|
});
|
|
2411
|
-
var lastBytesSent = 0;
|
|
2412
|
-
var setBytesSent = function setBytesSent(newBytesSent) {
|
|
2413
|
-
var delta = newBytesSent - lastBytesSent;
|
|
2414
|
-
lastBytesSent = newBytesSent;
|
|
2415
|
-
onProgress(delta);
|
|
2416
|
-
};
|
|
2417
2441
|
return UploadManagerBrowser_finallyRethrows(function () {
|
|
2418
2442
|
return UploadManagerBrowser_await(new Promise(function (resolve, reject) {
|
|
2419
2443
|
xhr.upload.addEventListener("progress", function (evt) {
|
|
2420
2444
|
if (evt.lengthComputable) {
|
|
2421
|
-
|
|
2445
|
+
onProgress(evt.loaded);
|
|
2422
2446
|
}
|
|
2423
2447
|
}, false);
|
|
2424
2448
|
xhr.addEventListener("load", function () {
|
|
2425
2449
|
var _a;
|
|
2426
|
-
// Ensure we always report the progress of a finished upload as 100%.
|
|
2427
|
-
setBytesSent(contentLength);
|
|
2428
2450
|
var etag = (_a = xhr.getResponseHeader("etag")) !== null && _a !== void 0 ? _a : undefined;
|
|
2429
2451
|
resolve({
|
|
2430
2452
|
etag: etag,
|
package/dist/node/cjs/main.js
CHANGED
|
@@ -259,7 +259,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
259
259
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
260
260
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
261
261
|
/**
|
|
262
|
-
* A lightweight mutex. (Other libraries contain too many features and we want to keep
|
|
262
|
+
* A lightweight mutex. (Other libraries contain too many features and we want to keep size down).
|
|
263
263
|
*
|
|
264
264
|
* Characteristics:
|
|
265
265
|
* - Non-reentrant.
|
|
@@ -543,7 +543,16 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
543
543
|
var _a, _b;
|
|
544
544
|
var response;
|
|
545
545
|
return runtime_continue(_catch(function () {
|
|
546
|
-
return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(_this4.config)(url, init),
|
|
546
|
+
return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(_this4.config)(url, Object.assign(Object.assign({}, init), {
|
|
547
|
+
// This is specifically added to cater for Next.js's Fetch implementation, which caches POST requests...
|
|
548
|
+
//
|
|
549
|
+
// "fetch requests that use the POST method are also automatically cached."
|
|
550
|
+
// - https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#caching-data
|
|
551
|
+
//
|
|
552
|
+
// However, this is probably a good idea, even for all GET requests, as if the user is refreshing a JWT
|
|
553
|
+
// or downloading a file via 'FileApi.downloadFile', then they'll likely want the latest.
|
|
554
|
+
cache: "no-store"
|
|
555
|
+
})), function (_BytescaleApiClientCo) {
|
|
547
556
|
response = _BytescaleApiClientCo;
|
|
548
557
|
});
|
|
549
558
|
}, function (e) {
|
|
@@ -2044,10 +2053,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2044
2053
|
_this2.assertNotCancelled(request);
|
|
2045
2054
|
var source = _this2.processUploadSource(request.data);
|
|
2046
2055
|
var preUploadInfo = _this2.getPreUploadInfo(request, source);
|
|
2047
|
-
var
|
|
2056
|
+
var bytesTotal = preUploadInfo.size;
|
|
2057
|
+
var makeOnProgressForPart = _this2.makeOnProgressForPartFactory(request, bytesTotal);
|
|
2048
2058
|
var init = _this2.preUpload(source);
|
|
2049
2059
|
// Raise initial progress event SYNCHRONOUSLY.
|
|
2050
|
-
onProgress
|
|
2060
|
+
if (request.onProgress !== undefined) {
|
|
2061
|
+
request.onProgress(_this2.makeProgressEvent(0, bytesTotal));
|
|
2062
|
+
}
|
|
2051
2063
|
return UploadManagerBase_await(_this2.beginUpload(request, preUploadInfo), function (uploadInfo) {
|
|
2052
2064
|
var partCount = uploadInfo.uploadParts.count;
|
|
2053
2065
|
var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
|
|
@@ -2057,7 +2069,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2057
2069
|
var intervalHandle = setInterval(_this2.onIntervalTick(request, cancel), _this2.intervalMs);
|
|
2058
2070
|
return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
|
|
2059
2071
|
return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
|
|
2060
|
-
return _this2.uploadPart(request, source, part, uploadInfo,
|
|
2072
|
+
return _this2.uploadPart(request, source, part, uploadInfo, makeOnProgressForPart(), addCancellationHandler);
|
|
2061
2073
|
})), function () {
|
|
2062
2074
|
return UploadManagerBase_awaitIgnored(_this2.postUpload(init));
|
|
2063
2075
|
});
|
|
@@ -2113,21 +2125,37 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2113
2125
|
addCancellationHandler: addCancellationHandler
|
|
2114
2126
|
};
|
|
2115
2127
|
}
|
|
2128
|
+
/**
|
|
2129
|
+
* Returns a callback, which when called, returns a callback that can be used by ONE specific part to report its progress.
|
|
2130
|
+
*/
|
|
2116
2131
|
}, {
|
|
2117
|
-
key: "
|
|
2118
|
-
value: function
|
|
2132
|
+
key: "makeOnProgressForPartFactory",
|
|
2133
|
+
value: function makeOnProgressForPartFactory(request, bytesTotal) {
|
|
2134
|
+
var _this4 = this;
|
|
2119
2135
|
var onProgress = request.onProgress;
|
|
2120
2136
|
if (onProgress === undefined) {
|
|
2121
|
-
return function () {
|
|
2137
|
+
return function () {
|
|
2138
|
+
return function () {};
|
|
2139
|
+
};
|
|
2122
2140
|
}
|
|
2123
2141
|
var bytesSent = 0;
|
|
2124
|
-
return function (
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2142
|
+
return function () {
|
|
2143
|
+
var bytesSentForPart = 0;
|
|
2144
|
+
return function (bytesSentTotalForPart) {
|
|
2145
|
+
var delta = bytesSentTotalForPart - bytesSentForPart;
|
|
2146
|
+
bytesSentForPart += delta;
|
|
2147
|
+
bytesSent += delta;
|
|
2148
|
+
onProgress(_this4.makeProgressEvent(bytesSent, bytesTotal));
|
|
2149
|
+
};
|
|
2150
|
+
};
|
|
2151
|
+
}
|
|
2152
|
+
}, {
|
|
2153
|
+
key: "makeProgressEvent",
|
|
2154
|
+
value: function makeProgressEvent(bytesSent, bytesTotal) {
|
|
2155
|
+
return {
|
|
2156
|
+
bytesTotal: bytesTotal,
|
|
2157
|
+
bytesSent: bytesSent,
|
|
2158
|
+
progress: Math.round(bytesSent / bytesTotal * 100)
|
|
2131
2159
|
};
|
|
2132
2160
|
}
|
|
2133
2161
|
}, {
|
|
@@ -2150,9 +2178,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2150
2178
|
mime = _ref2.mime,
|
|
2151
2179
|
originalFileName = _ref2.originalFileName;
|
|
2152
2180
|
try {
|
|
2153
|
-
var
|
|
2154
|
-
return UploadManagerBase_await(
|
|
2155
|
-
accountId:
|
|
2181
|
+
var _this6 = this;
|
|
2182
|
+
return UploadManagerBase_await(_this6.uploadApi.beginMultipartUpload({
|
|
2183
|
+
accountId: _this6.accountId,
|
|
2156
2184
|
beginMultipartUploadRequest: {
|
|
2157
2185
|
metadata: request.metadata,
|
|
2158
2186
|
mime: mime,
|
|
@@ -2171,14 +2199,14 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2171
2199
|
key: "uploadPart",
|
|
2172
2200
|
value: function uploadPart(request, source, partIndex, uploadInfo, onProgress, addCancellationHandler) {
|
|
2173
2201
|
try {
|
|
2174
|
-
var
|
|
2175
|
-
|
|
2176
|
-
return UploadManagerBase_await(
|
|
2177
|
-
|
|
2178
|
-
return UploadManagerBase_await(
|
|
2179
|
-
|
|
2180
|
-
return UploadManagerBase_awaitIgnored(
|
|
2181
|
-
accountId:
|
|
2202
|
+
var _this8 = this;
|
|
2203
|
+
_this8.assertNotCancelled(request);
|
|
2204
|
+
return UploadManagerBase_await(_this8.getUploadPart(partIndex, uploadInfo), function (part) {
|
|
2205
|
+
_this8.assertNotCancelled(request);
|
|
2206
|
+
return UploadManagerBase_await(_this8.putUploadPart(part, source, onProgress, addCancellationHandler), function (etag) {
|
|
2207
|
+
_this8.assertNotCancelled(request);
|
|
2208
|
+
return UploadManagerBase_awaitIgnored(_this8.uploadApi.completeUploadPart({
|
|
2209
|
+
accountId: _this8.accountId,
|
|
2182
2210
|
uploadId: uploadInfo.uploadId,
|
|
2183
2211
|
uploadPartIndex: partIndex,
|
|
2184
2212
|
completeUploadPartRequest: {
|
|
@@ -2198,9 +2226,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2198
2226
|
key: "putUploadPart",
|
|
2199
2227
|
value: function putUploadPart(part, source, onProgress, addCancellationHandler) {
|
|
2200
2228
|
try {
|
|
2201
|
-
var
|
|
2229
|
+
var _this10 = this;
|
|
2202
2230
|
var contentLength = part.range.inclusiveEnd + 1 - part.range.inclusiveStart;
|
|
2203
|
-
return UploadManagerBase_await(
|
|
2231
|
+
return UploadManagerBase_await(_this10.doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler), function (_ref3) {
|
|
2204
2232
|
var status = _ref3.status,
|
|
2205
2233
|
etag = _ref3.etag;
|
|
2206
2234
|
if (Math.floor(status / 100) !== 2) {
|
|
@@ -2209,6 +2237,8 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2209
2237
|
if (etag === undefined) {
|
|
2210
2238
|
throw new Error("No 'etag' response header found in upload part response.");
|
|
2211
2239
|
}
|
|
2240
|
+
// Always send 100% for part, as some UploadManager implementations either don't report progress, or may not report the last chunk uploaded.
|
|
2241
|
+
onProgress(contentLength);
|
|
2212
2242
|
return etag;
|
|
2213
2243
|
});
|
|
2214
2244
|
} catch (e) {
|
|
@@ -2219,13 +2249,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2219
2249
|
key: "getUploadPart",
|
|
2220
2250
|
value: function getUploadPart(partIndex, uploadInfo) {
|
|
2221
2251
|
try {
|
|
2222
|
-
var
|
|
2252
|
+
var _this12 = this;
|
|
2223
2253
|
if (partIndex === 0) {
|
|
2224
2254
|
return uploadInfo.uploadParts.first;
|
|
2225
2255
|
}
|
|
2226
|
-
return UploadManagerBase_await(
|
|
2256
|
+
return UploadManagerBase_await(_this12.uploadApi.getUploadPart({
|
|
2227
2257
|
uploadId: uploadInfo.uploadId,
|
|
2228
|
-
accountId:
|
|
2258
|
+
accountId: _this12.accountId,
|
|
2229
2259
|
uploadPartIndex: partIndex
|
|
2230
2260
|
}));
|
|
2231
2261
|
} catch (e) {
|
|
@@ -2550,7 +2580,8 @@ var UploadManagerFetchUtils = /*#__PURE__*/function () {
|
|
|
2550
2580
|
method: "PUT",
|
|
2551
2581
|
headers: headers,
|
|
2552
2582
|
body: content,
|
|
2553
|
-
signal: signal
|
|
2583
|
+
signal: signal,
|
|
2584
|
+
cache: "no-store" // Required for Next.js's Fetch implementation, which caches POST/PUT requests by default.
|
|
2554
2585
|
}), function (response) {
|
|
2555
2586
|
return {
|
|
2556
2587
|
etag: (_a = response.headers.get("etag")) !== null && _a !== void 0 ? _a : undefined,
|
|
@@ -2872,10 +2903,12 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
|
|
|
2872
2903
|
var _this2 = this;
|
|
2873
2904
|
// Report progress:
|
|
2874
2905
|
var hasWarned = false;
|
|
2906
|
+
var bytesSent = 0;
|
|
2875
2907
|
return UploadManagerNode_await(_this2.sliceDataForRequest(source, part), function (stream) {
|
|
2876
2908
|
var streamWithProgress = stream.on("data", function (data) {
|
|
2877
|
-
if (data.
|
|
2878
|
-
|
|
2909
|
+
if (data.byteLength !== undefined) {
|
|
2910
|
+
bytesSent += data.byteLength;
|
|
2911
|
+
onProgress(bytesSent);
|
|
2879
2912
|
} else if (!hasWarned) {
|
|
2880
2913
|
hasWarned = true;
|
|
2881
2914
|
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
|
@@ -246,7 +246,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
246
246
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
247
247
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
248
248
|
/**
|
|
249
|
-
* A lightweight mutex. (Other libraries contain too many features and we want to keep
|
|
249
|
+
* A lightweight mutex. (Other libraries contain too many features and we want to keep size down).
|
|
250
250
|
*
|
|
251
251
|
* Characteristics:
|
|
252
252
|
* - Non-reentrant.
|
|
@@ -530,7 +530,16 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
530
530
|
var _a, _b;
|
|
531
531
|
var response;
|
|
532
532
|
return runtime_continue(_catch(function () {
|
|
533
|
-
return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(_this4.config)(url, init),
|
|
533
|
+
return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(_this4.config)(url, Object.assign(Object.assign({}, init), {
|
|
534
|
+
// This is specifically added to cater for Next.js's Fetch implementation, which caches POST requests...
|
|
535
|
+
//
|
|
536
|
+
// "fetch requests that use the POST method are also automatically cached."
|
|
537
|
+
// - https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#caching-data
|
|
538
|
+
//
|
|
539
|
+
// However, this is probably a good idea, even for all GET requests, as if the user is refreshing a JWT
|
|
540
|
+
// or downloading a file via 'FileApi.downloadFile', then they'll likely want the latest.
|
|
541
|
+
cache: "no-store"
|
|
542
|
+
})), function (_BytescaleApiClientCo) {
|
|
534
543
|
response = _BytescaleApiClientCo;
|
|
535
544
|
});
|
|
536
545
|
}, function (e) {
|
|
@@ -2031,10 +2040,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2031
2040
|
_this2.assertNotCancelled(request);
|
|
2032
2041
|
var source = _this2.processUploadSource(request.data);
|
|
2033
2042
|
var preUploadInfo = _this2.getPreUploadInfo(request, source);
|
|
2034
|
-
var
|
|
2043
|
+
var bytesTotal = preUploadInfo.size;
|
|
2044
|
+
var makeOnProgressForPart = _this2.makeOnProgressForPartFactory(request, bytesTotal);
|
|
2035
2045
|
var init = _this2.preUpload(source);
|
|
2036
2046
|
// Raise initial progress event SYNCHRONOUSLY.
|
|
2037
|
-
onProgress
|
|
2047
|
+
if (request.onProgress !== undefined) {
|
|
2048
|
+
request.onProgress(_this2.makeProgressEvent(0, bytesTotal));
|
|
2049
|
+
}
|
|
2038
2050
|
return UploadManagerBase_await(_this2.beginUpload(request, preUploadInfo), function (uploadInfo) {
|
|
2039
2051
|
var partCount = uploadInfo.uploadParts.count;
|
|
2040
2052
|
var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
|
|
@@ -2044,7 +2056,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2044
2056
|
var intervalHandle = setInterval(_this2.onIntervalTick(request, cancel), _this2.intervalMs);
|
|
2045
2057
|
return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
|
|
2046
2058
|
return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
|
|
2047
|
-
return _this2.uploadPart(request, source, part, uploadInfo,
|
|
2059
|
+
return _this2.uploadPart(request, source, part, uploadInfo, makeOnProgressForPart(), addCancellationHandler);
|
|
2048
2060
|
})), function () {
|
|
2049
2061
|
return UploadManagerBase_awaitIgnored(_this2.postUpload(init));
|
|
2050
2062
|
});
|
|
@@ -2100,21 +2112,37 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2100
2112
|
addCancellationHandler: addCancellationHandler
|
|
2101
2113
|
};
|
|
2102
2114
|
}
|
|
2115
|
+
/**
|
|
2116
|
+
* Returns a callback, which when called, returns a callback that can be used by ONE specific part to report its progress.
|
|
2117
|
+
*/
|
|
2103
2118
|
}, {
|
|
2104
|
-
key: "
|
|
2105
|
-
value: function
|
|
2119
|
+
key: "makeOnProgressForPartFactory",
|
|
2120
|
+
value: function makeOnProgressForPartFactory(request, bytesTotal) {
|
|
2121
|
+
var _this4 = this;
|
|
2106
2122
|
var onProgress = request.onProgress;
|
|
2107
2123
|
if (onProgress === undefined) {
|
|
2108
|
-
return function () {
|
|
2124
|
+
return function () {
|
|
2125
|
+
return function () {};
|
|
2126
|
+
};
|
|
2109
2127
|
}
|
|
2110
2128
|
var bytesSent = 0;
|
|
2111
|
-
return function (
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2129
|
+
return function () {
|
|
2130
|
+
var bytesSentForPart = 0;
|
|
2131
|
+
return function (bytesSentTotalForPart) {
|
|
2132
|
+
var delta = bytesSentTotalForPart - bytesSentForPart;
|
|
2133
|
+
bytesSentForPart += delta;
|
|
2134
|
+
bytesSent += delta;
|
|
2135
|
+
onProgress(_this4.makeProgressEvent(bytesSent, bytesTotal));
|
|
2136
|
+
};
|
|
2137
|
+
};
|
|
2138
|
+
}
|
|
2139
|
+
}, {
|
|
2140
|
+
key: "makeProgressEvent",
|
|
2141
|
+
value: function makeProgressEvent(bytesSent, bytesTotal) {
|
|
2142
|
+
return {
|
|
2143
|
+
bytesTotal: bytesTotal,
|
|
2144
|
+
bytesSent: bytesSent,
|
|
2145
|
+
progress: Math.round(bytesSent / bytesTotal * 100)
|
|
2118
2146
|
};
|
|
2119
2147
|
}
|
|
2120
2148
|
}, {
|
|
@@ -2137,9 +2165,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2137
2165
|
mime = _ref2.mime,
|
|
2138
2166
|
originalFileName = _ref2.originalFileName;
|
|
2139
2167
|
try {
|
|
2140
|
-
var
|
|
2141
|
-
return UploadManagerBase_await(
|
|
2142
|
-
accountId:
|
|
2168
|
+
var _this6 = this;
|
|
2169
|
+
return UploadManagerBase_await(_this6.uploadApi.beginMultipartUpload({
|
|
2170
|
+
accountId: _this6.accountId,
|
|
2143
2171
|
beginMultipartUploadRequest: {
|
|
2144
2172
|
metadata: request.metadata,
|
|
2145
2173
|
mime: mime,
|
|
@@ -2158,14 +2186,14 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2158
2186
|
key: "uploadPart",
|
|
2159
2187
|
value: function uploadPart(request, source, partIndex, uploadInfo, onProgress, addCancellationHandler) {
|
|
2160
2188
|
try {
|
|
2161
|
-
var
|
|
2162
|
-
|
|
2163
|
-
return UploadManagerBase_await(
|
|
2164
|
-
|
|
2165
|
-
return UploadManagerBase_await(
|
|
2166
|
-
|
|
2167
|
-
return UploadManagerBase_awaitIgnored(
|
|
2168
|
-
accountId:
|
|
2189
|
+
var _this8 = this;
|
|
2190
|
+
_this8.assertNotCancelled(request);
|
|
2191
|
+
return UploadManagerBase_await(_this8.getUploadPart(partIndex, uploadInfo), function (part) {
|
|
2192
|
+
_this8.assertNotCancelled(request);
|
|
2193
|
+
return UploadManagerBase_await(_this8.putUploadPart(part, source, onProgress, addCancellationHandler), function (etag) {
|
|
2194
|
+
_this8.assertNotCancelled(request);
|
|
2195
|
+
return UploadManagerBase_awaitIgnored(_this8.uploadApi.completeUploadPart({
|
|
2196
|
+
accountId: _this8.accountId,
|
|
2169
2197
|
uploadId: uploadInfo.uploadId,
|
|
2170
2198
|
uploadPartIndex: partIndex,
|
|
2171
2199
|
completeUploadPartRequest: {
|
|
@@ -2185,9 +2213,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2185
2213
|
key: "putUploadPart",
|
|
2186
2214
|
value: function putUploadPart(part, source, onProgress, addCancellationHandler) {
|
|
2187
2215
|
try {
|
|
2188
|
-
var
|
|
2216
|
+
var _this10 = this;
|
|
2189
2217
|
var contentLength = part.range.inclusiveEnd + 1 - part.range.inclusiveStart;
|
|
2190
|
-
return UploadManagerBase_await(
|
|
2218
|
+
return UploadManagerBase_await(_this10.doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler), function (_ref3) {
|
|
2191
2219
|
var status = _ref3.status,
|
|
2192
2220
|
etag = _ref3.etag;
|
|
2193
2221
|
if (Math.floor(status / 100) !== 2) {
|
|
@@ -2196,6 +2224,8 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2196
2224
|
if (etag === undefined) {
|
|
2197
2225
|
throw new Error("No 'etag' response header found in upload part response.");
|
|
2198
2226
|
}
|
|
2227
|
+
// Always send 100% for part, as some UploadManager implementations either don't report progress, or may not report the last chunk uploaded.
|
|
2228
|
+
onProgress(contentLength);
|
|
2199
2229
|
return etag;
|
|
2200
2230
|
});
|
|
2201
2231
|
} catch (e) {
|
|
@@ -2206,13 +2236,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2206
2236
|
key: "getUploadPart",
|
|
2207
2237
|
value: function getUploadPart(partIndex, uploadInfo) {
|
|
2208
2238
|
try {
|
|
2209
|
-
var
|
|
2239
|
+
var _this12 = this;
|
|
2210
2240
|
if (partIndex === 0) {
|
|
2211
2241
|
return uploadInfo.uploadParts.first;
|
|
2212
2242
|
}
|
|
2213
|
-
return UploadManagerBase_await(
|
|
2243
|
+
return UploadManagerBase_await(_this12.uploadApi.getUploadPart({
|
|
2214
2244
|
uploadId: uploadInfo.uploadId,
|
|
2215
|
-
accountId:
|
|
2245
|
+
accountId: _this12.accountId,
|
|
2216
2246
|
uploadPartIndex: partIndex
|
|
2217
2247
|
}));
|
|
2218
2248
|
} catch (e) {
|
|
@@ -2541,7 +2571,8 @@ var UploadManagerFetchUtils = /*#__PURE__*/function () {
|
|
|
2541
2571
|
method: "PUT",
|
|
2542
2572
|
headers: headers,
|
|
2543
2573
|
body: content,
|
|
2544
|
-
signal: signal
|
|
2574
|
+
signal: signal,
|
|
2575
|
+
cache: "no-store" // Required for Next.js's Fetch implementation, which caches POST/PUT requests by default.
|
|
2545
2576
|
}), function (response) {
|
|
2546
2577
|
return {
|
|
2547
2578
|
etag: (_a = response.headers.get("etag")) !== null && _a !== void 0 ? _a : undefined,
|
|
@@ -2863,10 +2894,12 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
|
|
|
2863
2894
|
var _this2 = this;
|
|
2864
2895
|
// Report progress:
|
|
2865
2896
|
var hasWarned = false;
|
|
2897
|
+
var bytesSent = 0;
|
|
2866
2898
|
return UploadManagerNode_await(_this2.sliceDataForRequest(source, part), function (stream) {
|
|
2867
2899
|
var streamWithProgress = stream.on("data", function (data) {
|
|
2868
|
-
if (data.
|
|
2869
|
-
|
|
2900
|
+
if (data.byteLength !== undefined) {
|
|
2901
|
+
bytesSent += data.byteLength;
|
|
2902
|
+
onProgress(bytesSent);
|
|
2870
2903
|
} else if (!hasWarned) {
|
|
2871
2904
|
hasWarned = true;
|
|
2872
2905
|
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
|
@@ -259,7 +259,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
259
259
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
260
260
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
261
261
|
/**
|
|
262
|
-
* A lightweight mutex. (Other libraries contain too many features and we want to keep
|
|
262
|
+
* A lightweight mutex. (Other libraries contain too many features and we want to keep size down).
|
|
263
263
|
*
|
|
264
264
|
* Characteristics:
|
|
265
265
|
* - Non-reentrant.
|
|
@@ -543,7 +543,16 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
543
543
|
var _a, _b;
|
|
544
544
|
var response;
|
|
545
545
|
return runtime_continue(_catch(function () {
|
|
546
|
-
return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(_this4.config)(url, init),
|
|
546
|
+
return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(_this4.config)(url, Object.assign(Object.assign({}, init), {
|
|
547
|
+
// This is specifically added to cater for Next.js's Fetch implementation, which caches POST requests...
|
|
548
|
+
//
|
|
549
|
+
// "fetch requests that use the POST method are also automatically cached."
|
|
550
|
+
// - https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#caching-data
|
|
551
|
+
//
|
|
552
|
+
// However, this is probably a good idea, even for all GET requests, as if the user is refreshing a JWT
|
|
553
|
+
// or downloading a file via 'FileApi.downloadFile', then they'll likely want the latest.
|
|
554
|
+
cache: "no-store"
|
|
555
|
+
})), function (_BytescaleApiClientCo) {
|
|
547
556
|
response = _BytescaleApiClientCo;
|
|
548
557
|
});
|
|
549
558
|
}, function (e) {
|
|
@@ -2044,10 +2053,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2044
2053
|
_this2.assertNotCancelled(request);
|
|
2045
2054
|
var source = _this2.processUploadSource(request.data);
|
|
2046
2055
|
var preUploadInfo = _this2.getPreUploadInfo(request, source);
|
|
2047
|
-
var
|
|
2056
|
+
var bytesTotal = preUploadInfo.size;
|
|
2057
|
+
var makeOnProgressForPart = _this2.makeOnProgressForPartFactory(request, bytesTotal);
|
|
2048
2058
|
var init = _this2.preUpload(source);
|
|
2049
2059
|
// Raise initial progress event SYNCHRONOUSLY.
|
|
2050
|
-
onProgress
|
|
2060
|
+
if (request.onProgress !== undefined) {
|
|
2061
|
+
request.onProgress(_this2.makeProgressEvent(0, bytesTotal));
|
|
2062
|
+
}
|
|
2051
2063
|
return UploadManagerBase_await(_this2.beginUpload(request, preUploadInfo), function (uploadInfo) {
|
|
2052
2064
|
var partCount = uploadInfo.uploadParts.count;
|
|
2053
2065
|
var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
|
|
@@ -2057,7 +2069,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2057
2069
|
var intervalHandle = setInterval(_this2.onIntervalTick(request, cancel), _this2.intervalMs);
|
|
2058
2070
|
return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
|
|
2059
2071
|
return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
|
|
2060
|
-
return _this2.uploadPart(request, source, part, uploadInfo,
|
|
2072
|
+
return _this2.uploadPart(request, source, part, uploadInfo, makeOnProgressForPart(), addCancellationHandler);
|
|
2061
2073
|
})), function () {
|
|
2062
2074
|
return UploadManagerBase_awaitIgnored(_this2.postUpload(init));
|
|
2063
2075
|
});
|
|
@@ -2113,21 +2125,37 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2113
2125
|
addCancellationHandler: addCancellationHandler
|
|
2114
2126
|
};
|
|
2115
2127
|
}
|
|
2128
|
+
/**
|
|
2129
|
+
* Returns a callback, which when called, returns a callback that can be used by ONE specific part to report its progress.
|
|
2130
|
+
*/
|
|
2116
2131
|
}, {
|
|
2117
|
-
key: "
|
|
2118
|
-
value: function
|
|
2132
|
+
key: "makeOnProgressForPartFactory",
|
|
2133
|
+
value: function makeOnProgressForPartFactory(request, bytesTotal) {
|
|
2134
|
+
var _this4 = this;
|
|
2119
2135
|
var onProgress = request.onProgress;
|
|
2120
2136
|
if (onProgress === undefined) {
|
|
2121
|
-
return function () {
|
|
2137
|
+
return function () {
|
|
2138
|
+
return function () {};
|
|
2139
|
+
};
|
|
2122
2140
|
}
|
|
2123
2141
|
var bytesSent = 0;
|
|
2124
|
-
return function (
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2142
|
+
return function () {
|
|
2143
|
+
var bytesSentForPart = 0;
|
|
2144
|
+
return function (bytesSentTotalForPart) {
|
|
2145
|
+
var delta = bytesSentTotalForPart - bytesSentForPart;
|
|
2146
|
+
bytesSentForPart += delta;
|
|
2147
|
+
bytesSent += delta;
|
|
2148
|
+
onProgress(_this4.makeProgressEvent(bytesSent, bytesTotal));
|
|
2149
|
+
};
|
|
2150
|
+
};
|
|
2151
|
+
}
|
|
2152
|
+
}, {
|
|
2153
|
+
key: "makeProgressEvent",
|
|
2154
|
+
value: function makeProgressEvent(bytesSent, bytesTotal) {
|
|
2155
|
+
return {
|
|
2156
|
+
bytesTotal: bytesTotal,
|
|
2157
|
+
bytesSent: bytesSent,
|
|
2158
|
+
progress: Math.round(bytesSent / bytesTotal * 100)
|
|
2131
2159
|
};
|
|
2132
2160
|
}
|
|
2133
2161
|
}, {
|
|
@@ -2150,9 +2178,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2150
2178
|
mime = _ref2.mime,
|
|
2151
2179
|
originalFileName = _ref2.originalFileName;
|
|
2152
2180
|
try {
|
|
2153
|
-
var
|
|
2154
|
-
return UploadManagerBase_await(
|
|
2155
|
-
accountId:
|
|
2181
|
+
var _this6 = this;
|
|
2182
|
+
return UploadManagerBase_await(_this6.uploadApi.beginMultipartUpload({
|
|
2183
|
+
accountId: _this6.accountId,
|
|
2156
2184
|
beginMultipartUploadRequest: {
|
|
2157
2185
|
metadata: request.metadata,
|
|
2158
2186
|
mime: mime,
|
|
@@ -2171,14 +2199,14 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2171
2199
|
key: "uploadPart",
|
|
2172
2200
|
value: function uploadPart(request, source, partIndex, uploadInfo, onProgress, addCancellationHandler) {
|
|
2173
2201
|
try {
|
|
2174
|
-
var
|
|
2175
|
-
|
|
2176
|
-
return UploadManagerBase_await(
|
|
2177
|
-
|
|
2178
|
-
return UploadManagerBase_await(
|
|
2179
|
-
|
|
2180
|
-
return UploadManagerBase_awaitIgnored(
|
|
2181
|
-
accountId:
|
|
2202
|
+
var _this8 = this;
|
|
2203
|
+
_this8.assertNotCancelled(request);
|
|
2204
|
+
return UploadManagerBase_await(_this8.getUploadPart(partIndex, uploadInfo), function (part) {
|
|
2205
|
+
_this8.assertNotCancelled(request);
|
|
2206
|
+
return UploadManagerBase_await(_this8.putUploadPart(part, source, onProgress, addCancellationHandler), function (etag) {
|
|
2207
|
+
_this8.assertNotCancelled(request);
|
|
2208
|
+
return UploadManagerBase_awaitIgnored(_this8.uploadApi.completeUploadPart({
|
|
2209
|
+
accountId: _this8.accountId,
|
|
2182
2210
|
uploadId: uploadInfo.uploadId,
|
|
2183
2211
|
uploadPartIndex: partIndex,
|
|
2184
2212
|
completeUploadPartRequest: {
|
|
@@ -2198,9 +2226,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2198
2226
|
key: "putUploadPart",
|
|
2199
2227
|
value: function putUploadPart(part, source, onProgress, addCancellationHandler) {
|
|
2200
2228
|
try {
|
|
2201
|
-
var
|
|
2229
|
+
var _this10 = this;
|
|
2202
2230
|
var contentLength = part.range.inclusiveEnd + 1 - part.range.inclusiveStart;
|
|
2203
|
-
return UploadManagerBase_await(
|
|
2231
|
+
return UploadManagerBase_await(_this10.doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler), function (_ref3) {
|
|
2204
2232
|
var status = _ref3.status,
|
|
2205
2233
|
etag = _ref3.etag;
|
|
2206
2234
|
if (Math.floor(status / 100) !== 2) {
|
|
@@ -2209,6 +2237,8 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2209
2237
|
if (etag === undefined) {
|
|
2210
2238
|
throw new Error("No 'etag' response header found in upload part response.");
|
|
2211
2239
|
}
|
|
2240
|
+
// Always send 100% for part, as some UploadManager implementations either don't report progress, or may not report the last chunk uploaded.
|
|
2241
|
+
onProgress(contentLength);
|
|
2212
2242
|
return etag;
|
|
2213
2243
|
});
|
|
2214
2244
|
} catch (e) {
|
|
@@ -2219,13 +2249,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2219
2249
|
key: "getUploadPart",
|
|
2220
2250
|
value: function getUploadPart(partIndex, uploadInfo) {
|
|
2221
2251
|
try {
|
|
2222
|
-
var
|
|
2252
|
+
var _this12 = this;
|
|
2223
2253
|
if (partIndex === 0) {
|
|
2224
2254
|
return uploadInfo.uploadParts.first;
|
|
2225
2255
|
}
|
|
2226
|
-
return UploadManagerBase_await(
|
|
2256
|
+
return UploadManagerBase_await(_this12.uploadApi.getUploadPart({
|
|
2227
2257
|
uploadId: uploadInfo.uploadId,
|
|
2228
|
-
accountId:
|
|
2258
|
+
accountId: _this12.accountId,
|
|
2229
2259
|
uploadPartIndex: partIndex
|
|
2230
2260
|
}));
|
|
2231
2261
|
} catch (e) {
|
|
@@ -2405,7 +2435,8 @@ var UploadManagerFetchUtils = /*#__PURE__*/function () {
|
|
|
2405
2435
|
method: "PUT",
|
|
2406
2436
|
headers: headers,
|
|
2407
2437
|
body: content,
|
|
2408
|
-
signal: signal
|
|
2438
|
+
signal: signal,
|
|
2439
|
+
cache: "no-store" // Required for Next.js's Fetch implementation, which caches POST/PUT requests by default.
|
|
2409
2440
|
}), function (response) {
|
|
2410
2441
|
return {
|
|
2411
2442
|
etag: (_a = response.headers.get("etag")) !== null && _a !== void 0 ? _a : undefined,
|
package/dist/worker/esm/main.mjs
CHANGED
|
@@ -244,7 +244,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
244
244
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
245
245
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
246
246
|
/**
|
|
247
|
-
* A lightweight mutex. (Other libraries contain too many features and we want to keep
|
|
247
|
+
* A lightweight mutex. (Other libraries contain too many features and we want to keep size down).
|
|
248
248
|
*
|
|
249
249
|
* Characteristics:
|
|
250
250
|
* - Non-reentrant.
|
|
@@ -528,7 +528,16 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
528
528
|
var _a, _b;
|
|
529
529
|
var response;
|
|
530
530
|
return runtime_continue(_catch(function () {
|
|
531
|
-
return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(_this4.config)(url, init),
|
|
531
|
+
return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(_this4.config)(url, Object.assign(Object.assign({}, init), {
|
|
532
|
+
// This is specifically added to cater for Next.js's Fetch implementation, which caches POST requests...
|
|
533
|
+
//
|
|
534
|
+
// "fetch requests that use the POST method are also automatically cached."
|
|
535
|
+
// - https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#caching-data
|
|
536
|
+
//
|
|
537
|
+
// However, this is probably a good idea, even for all GET requests, as if the user is refreshing a JWT
|
|
538
|
+
// or downloading a file via 'FileApi.downloadFile', then they'll likely want the latest.
|
|
539
|
+
cache: "no-store"
|
|
540
|
+
})), function (_BytescaleApiClientCo) {
|
|
532
541
|
response = _BytescaleApiClientCo;
|
|
533
542
|
});
|
|
534
543
|
}, function (e) {
|
|
@@ -2029,10 +2038,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2029
2038
|
_this2.assertNotCancelled(request);
|
|
2030
2039
|
var source = _this2.processUploadSource(request.data);
|
|
2031
2040
|
var preUploadInfo = _this2.getPreUploadInfo(request, source);
|
|
2032
|
-
var
|
|
2041
|
+
var bytesTotal = preUploadInfo.size;
|
|
2042
|
+
var makeOnProgressForPart = _this2.makeOnProgressForPartFactory(request, bytesTotal);
|
|
2033
2043
|
var init = _this2.preUpload(source);
|
|
2034
2044
|
// Raise initial progress event SYNCHRONOUSLY.
|
|
2035
|
-
onProgress
|
|
2045
|
+
if (request.onProgress !== undefined) {
|
|
2046
|
+
request.onProgress(_this2.makeProgressEvent(0, bytesTotal));
|
|
2047
|
+
}
|
|
2036
2048
|
return UploadManagerBase_await(_this2.beginUpload(request, preUploadInfo), function (uploadInfo) {
|
|
2037
2049
|
var partCount = uploadInfo.uploadParts.count;
|
|
2038
2050
|
var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
|
|
@@ -2042,7 +2054,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2042
2054
|
var intervalHandle = setInterval(_this2.onIntervalTick(request, cancel), _this2.intervalMs);
|
|
2043
2055
|
return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
|
|
2044
2056
|
return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
|
|
2045
|
-
return _this2.uploadPart(request, source, part, uploadInfo,
|
|
2057
|
+
return _this2.uploadPart(request, source, part, uploadInfo, makeOnProgressForPart(), addCancellationHandler);
|
|
2046
2058
|
})), function () {
|
|
2047
2059
|
return UploadManagerBase_awaitIgnored(_this2.postUpload(init));
|
|
2048
2060
|
});
|
|
@@ -2098,21 +2110,37 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2098
2110
|
addCancellationHandler: addCancellationHandler
|
|
2099
2111
|
};
|
|
2100
2112
|
}
|
|
2113
|
+
/**
|
|
2114
|
+
* Returns a callback, which when called, returns a callback that can be used by ONE specific part to report its progress.
|
|
2115
|
+
*/
|
|
2101
2116
|
}, {
|
|
2102
|
-
key: "
|
|
2103
|
-
value: function
|
|
2117
|
+
key: "makeOnProgressForPartFactory",
|
|
2118
|
+
value: function makeOnProgressForPartFactory(request, bytesTotal) {
|
|
2119
|
+
var _this4 = this;
|
|
2104
2120
|
var onProgress = request.onProgress;
|
|
2105
2121
|
if (onProgress === undefined) {
|
|
2106
|
-
return function () {
|
|
2122
|
+
return function () {
|
|
2123
|
+
return function () {};
|
|
2124
|
+
};
|
|
2107
2125
|
}
|
|
2108
2126
|
var bytesSent = 0;
|
|
2109
|
-
return function (
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2127
|
+
return function () {
|
|
2128
|
+
var bytesSentForPart = 0;
|
|
2129
|
+
return function (bytesSentTotalForPart) {
|
|
2130
|
+
var delta = bytesSentTotalForPart - bytesSentForPart;
|
|
2131
|
+
bytesSentForPart += delta;
|
|
2132
|
+
bytesSent += delta;
|
|
2133
|
+
onProgress(_this4.makeProgressEvent(bytesSent, bytesTotal));
|
|
2134
|
+
};
|
|
2135
|
+
};
|
|
2136
|
+
}
|
|
2137
|
+
}, {
|
|
2138
|
+
key: "makeProgressEvent",
|
|
2139
|
+
value: function makeProgressEvent(bytesSent, bytesTotal) {
|
|
2140
|
+
return {
|
|
2141
|
+
bytesTotal: bytesTotal,
|
|
2142
|
+
bytesSent: bytesSent,
|
|
2143
|
+
progress: Math.round(bytesSent / bytesTotal * 100)
|
|
2116
2144
|
};
|
|
2117
2145
|
}
|
|
2118
2146
|
}, {
|
|
@@ -2135,9 +2163,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2135
2163
|
mime = _ref2.mime,
|
|
2136
2164
|
originalFileName = _ref2.originalFileName;
|
|
2137
2165
|
try {
|
|
2138
|
-
var
|
|
2139
|
-
return UploadManagerBase_await(
|
|
2140
|
-
accountId:
|
|
2166
|
+
var _this6 = this;
|
|
2167
|
+
return UploadManagerBase_await(_this6.uploadApi.beginMultipartUpload({
|
|
2168
|
+
accountId: _this6.accountId,
|
|
2141
2169
|
beginMultipartUploadRequest: {
|
|
2142
2170
|
metadata: request.metadata,
|
|
2143
2171
|
mime: mime,
|
|
@@ -2156,14 +2184,14 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2156
2184
|
key: "uploadPart",
|
|
2157
2185
|
value: function uploadPart(request, source, partIndex, uploadInfo, onProgress, addCancellationHandler) {
|
|
2158
2186
|
try {
|
|
2159
|
-
var
|
|
2160
|
-
|
|
2161
|
-
return UploadManagerBase_await(
|
|
2162
|
-
|
|
2163
|
-
return UploadManagerBase_await(
|
|
2164
|
-
|
|
2165
|
-
return UploadManagerBase_awaitIgnored(
|
|
2166
|
-
accountId:
|
|
2187
|
+
var _this8 = this;
|
|
2188
|
+
_this8.assertNotCancelled(request);
|
|
2189
|
+
return UploadManagerBase_await(_this8.getUploadPart(partIndex, uploadInfo), function (part) {
|
|
2190
|
+
_this8.assertNotCancelled(request);
|
|
2191
|
+
return UploadManagerBase_await(_this8.putUploadPart(part, source, onProgress, addCancellationHandler), function (etag) {
|
|
2192
|
+
_this8.assertNotCancelled(request);
|
|
2193
|
+
return UploadManagerBase_awaitIgnored(_this8.uploadApi.completeUploadPart({
|
|
2194
|
+
accountId: _this8.accountId,
|
|
2167
2195
|
uploadId: uploadInfo.uploadId,
|
|
2168
2196
|
uploadPartIndex: partIndex,
|
|
2169
2197
|
completeUploadPartRequest: {
|
|
@@ -2183,9 +2211,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2183
2211
|
key: "putUploadPart",
|
|
2184
2212
|
value: function putUploadPart(part, source, onProgress, addCancellationHandler) {
|
|
2185
2213
|
try {
|
|
2186
|
-
var
|
|
2214
|
+
var _this10 = this;
|
|
2187
2215
|
var contentLength = part.range.inclusiveEnd + 1 - part.range.inclusiveStart;
|
|
2188
|
-
return UploadManagerBase_await(
|
|
2216
|
+
return UploadManagerBase_await(_this10.doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler), function (_ref3) {
|
|
2189
2217
|
var status = _ref3.status,
|
|
2190
2218
|
etag = _ref3.etag;
|
|
2191
2219
|
if (Math.floor(status / 100) !== 2) {
|
|
@@ -2194,6 +2222,8 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2194
2222
|
if (etag === undefined) {
|
|
2195
2223
|
throw new Error("No 'etag' response header found in upload part response.");
|
|
2196
2224
|
}
|
|
2225
|
+
// Always send 100% for part, as some UploadManager implementations either don't report progress, or may not report the last chunk uploaded.
|
|
2226
|
+
onProgress(contentLength);
|
|
2197
2227
|
return etag;
|
|
2198
2228
|
});
|
|
2199
2229
|
} catch (e) {
|
|
@@ -2204,13 +2234,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2204
2234
|
key: "getUploadPart",
|
|
2205
2235
|
value: function getUploadPart(partIndex, uploadInfo) {
|
|
2206
2236
|
try {
|
|
2207
|
-
var
|
|
2237
|
+
var _this12 = this;
|
|
2208
2238
|
if (partIndex === 0) {
|
|
2209
2239
|
return uploadInfo.uploadParts.first;
|
|
2210
2240
|
}
|
|
2211
|
-
return UploadManagerBase_await(
|
|
2241
|
+
return UploadManagerBase_await(_this12.uploadApi.getUploadPart({
|
|
2212
2242
|
uploadId: uploadInfo.uploadId,
|
|
2213
|
-
accountId:
|
|
2243
|
+
accountId: _this12.accountId,
|
|
2214
2244
|
uploadPartIndex: partIndex
|
|
2215
2245
|
}));
|
|
2216
2246
|
} catch (e) {
|
|
@@ -2390,7 +2420,8 @@ var UploadManagerFetchUtils = /*#__PURE__*/function () {
|
|
|
2390
2420
|
method: "PUT",
|
|
2391
2421
|
headers: headers,
|
|
2392
2422
|
body: content,
|
|
2393
|
-
signal: signal
|
|
2423
|
+
signal: signal,
|
|
2424
|
+
cache: "no-store" // Required for Next.js's Fetch implementation, which caches POST/PUT requests by default.
|
|
2394
2425
|
}), function (response) {
|
|
2395
2426
|
return {
|
|
2396
2427
|
etag: (_a = response.headers.get("etag")) !== null && _a !== void 0 ? _a : undefined,
|