@uploadcare/upload-client 2.0.0-alpha.9 → 2.0.0
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 +35 -10
- package/dist/index.browser.cjs +70 -42
- package/dist/index.browser.js +110 -86
- package/dist/index.cjs +82 -49
- package/dist/index.js +119 -95
- package/dist/types.d.ts +72 -3
- package/package.json +32 -26
- package/CHANGELOG.md +0 -243
package/dist/index.cjs
CHANGED
|
@@ -10,6 +10,13 @@ var NodeFormData = require('form-data');
|
|
|
10
10
|
var abortController = require('abort-controller');
|
|
11
11
|
var WebSocket = require('ws');
|
|
12
12
|
|
|
13
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
|
+
|
|
15
|
+
var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
|
|
16
|
+
var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
|
|
17
|
+
var NodeFormData__default = /*#__PURE__*/_interopDefaultLegacy(NodeFormData);
|
|
18
|
+
var WebSocket__default = /*#__PURE__*/_interopDefaultLegacy(WebSocket);
|
|
19
|
+
|
|
13
20
|
/*! *****************************************************************************
|
|
14
21
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
15
22
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
@@ -60,10 +67,11 @@ function __spreadArrays() {
|
|
|
60
67
|
|
|
61
68
|
var UploadClientError = /** @class */ (function (_super) {
|
|
62
69
|
__extends(UploadClientError, _super);
|
|
63
|
-
function UploadClientError(message, request, response, headers) {
|
|
70
|
+
function UploadClientError(message, code, request, response, headers) {
|
|
64
71
|
var _this = _super.call(this) || this;
|
|
65
72
|
_this.name = 'UploadClientError';
|
|
66
73
|
_this.message = message;
|
|
74
|
+
_this.code = code;
|
|
67
75
|
_this.request = request;
|
|
68
76
|
_this.response = response;
|
|
69
77
|
_this.headers = headers;
|
|
@@ -156,8 +164,8 @@ var request = function (params) {
|
|
|
156
164
|
length || data.length;
|
|
157
165
|
}
|
|
158
166
|
var req = options.protocol !== 'https:'
|
|
159
|
-
?
|
|
160
|
-
:
|
|
167
|
+
? http__default["default"].request(options)
|
|
168
|
+
: https__default["default"].request(options);
|
|
161
169
|
onCancel(signal, function () {
|
|
162
170
|
aborted = true;
|
|
163
171
|
req.abort();
|
|
@@ -200,20 +208,27 @@ var request = function (params) {
|
|
|
200
208
|
});
|
|
201
209
|
};
|
|
202
210
|
|
|
203
|
-
|
|
211
|
+
function identity(obj) {
|
|
212
|
+
return obj;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
var transformFile = identity;
|
|
216
|
+
var getFormData = (function () { return new NodeFormData__default["default"](); });
|
|
204
217
|
|
|
218
|
+
var isFileTuple = function (tuple) {
|
|
219
|
+
return tuple[0] === 'file';
|
|
220
|
+
};
|
|
205
221
|
function buildFormData(body) {
|
|
206
222
|
var formData = getFormData();
|
|
207
|
-
var isTriple = function (tuple) {
|
|
208
|
-
return tuple[0] === 'file';
|
|
209
|
-
};
|
|
210
223
|
var _loop_1 = function (tuple) {
|
|
211
224
|
if (Array.isArray(tuple[1])) {
|
|
212
225
|
// refactor this
|
|
213
226
|
tuple[1].forEach(function (val) { return val && formData.append(tuple[0] + '[]', "" + val); });
|
|
214
227
|
}
|
|
215
|
-
else if (
|
|
216
|
-
|
|
228
|
+
else if (isFileTuple(tuple)) {
|
|
229
|
+
var name_1 = tuple[2];
|
|
230
|
+
var file = transformFile(tuple[1]); // lgtm[js/superfluous-trailing-arguments]
|
|
231
|
+
formData.append(tuple[0], file, name_1);
|
|
217
232
|
}
|
|
218
233
|
else if (tuple[1] != null) {
|
|
219
234
|
formData.append(tuple[0], "" + tuple[1]);
|
|
@@ -271,7 +286,7 @@ var defaultSettings = {
|
|
|
271
286
|
var defaultContentType = 'application/octet-stream';
|
|
272
287
|
var defaultFilename = 'original';
|
|
273
288
|
|
|
274
|
-
var version = '
|
|
289
|
+
var version = '2.0.0';
|
|
275
290
|
|
|
276
291
|
/**
|
|
277
292
|
* Returns User Agent based on version and settings.
|
|
@@ -360,7 +375,7 @@ function retrier(fn, options) {
|
|
|
360
375
|
return runAttempt(fn);
|
|
361
376
|
}
|
|
362
377
|
|
|
363
|
-
var REQUEST_WAS_THROTTLED_CODE =
|
|
378
|
+
var REQUEST_WAS_THROTTLED_CODE = 'RequestThrottledError';
|
|
364
379
|
var DEFAULT_RETRY_AFTER_TIMEOUT = 15000;
|
|
365
380
|
function getTimeoutFromThrottledRequest(error) {
|
|
366
381
|
var headers = (error || {}).headers;
|
|
@@ -372,9 +387,8 @@ function retryIfThrottled(fn, retryThrottledMaxTimes) {
|
|
|
372
387
|
return retrier(function (_a) {
|
|
373
388
|
var attempt = _a.attempt, retry = _a.retry;
|
|
374
389
|
return fn().catch(function (error) {
|
|
375
|
-
var _a;
|
|
376
390
|
if ('response' in error &&
|
|
377
|
-
(
|
|
391
|
+
(error === null || error === void 0 ? void 0 : error.code) === REQUEST_WAS_THROTTLED_CODE &&
|
|
378
392
|
attempt < retryThrottledMaxTimes) {
|
|
379
393
|
return retry(getTimeoutFromThrottledRequest(error));
|
|
380
394
|
}
|
|
@@ -416,7 +430,7 @@ function base(file, _a) {
|
|
|
416
430
|
var data = _a.data, headers = _a.headers, request = _a.request;
|
|
417
431
|
var response = camelizeKeys(JSON.parse(data));
|
|
418
432
|
if ('error' in response) {
|
|
419
|
-
throw new UploadClientError(
|
|
433
|
+
throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
|
|
420
434
|
}
|
|
421
435
|
else {
|
|
422
436
|
return response;
|
|
@@ -433,7 +447,6 @@ var TypeEnum;
|
|
|
433
447
|
/**
|
|
434
448
|
* Uploading files from URL.
|
|
435
449
|
*/
|
|
436
|
-
/* eslint @typescript-eslint/camelcase: [2, {allow: ["pub_key", "source_url", "check_URL_duplicates", "save_URL_duplicates"]}] */
|
|
437
450
|
function fromUrl(sourceUrl, _a) {
|
|
438
451
|
var publicKey = _a.publicKey, _b = _a.baseURL, baseURL = _b === void 0 ? defaultSettings.baseURL : _b, store = _a.store, fileName = _a.fileName, checkForUrlDuplicates = _a.checkForUrlDuplicates, saveUrlForRecurrentUploads = _a.saveUrlForRecurrentUploads, secureSignature = _a.secureSignature, secureExpire = _a.secureExpire, _c = _a.source, source = _c === void 0 ? 'url' : _c, signal = _a.signal, integration = _a.integration, userAgent = _a.userAgent, _d = _a.retryThrottledRequestMaxTimes, retryThrottledRequestMaxTimes = _d === void 0 ? defaultSettings.retryThrottledRequestMaxTimes : _d;
|
|
439
452
|
return retryIfThrottled(function () {
|
|
@@ -459,7 +472,7 @@ function fromUrl(sourceUrl, _a) {
|
|
|
459
472
|
var data = _a.data, headers = _a.headers, request = _a.request;
|
|
460
473
|
var response = camelizeKeys(JSON.parse(data));
|
|
461
474
|
if ('error' in response) {
|
|
462
|
-
throw new UploadClientError(
|
|
475
|
+
throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
|
|
463
476
|
}
|
|
464
477
|
else {
|
|
465
478
|
return response;
|
|
@@ -505,7 +518,7 @@ function fromUrlStatus(token, _a) {
|
|
|
505
518
|
var data = _a.data, headers = _a.headers, request = _a.request;
|
|
506
519
|
var response = camelizeKeys(JSON.parse(data));
|
|
507
520
|
if ('error' in response && !isErrorResponse(response)) {
|
|
508
|
-
throw new UploadClientError(
|
|
521
|
+
throw new UploadClientError(response.error.content, undefined, request, response, headers);
|
|
509
522
|
}
|
|
510
523
|
else {
|
|
511
524
|
return response;
|
|
@@ -517,7 +530,6 @@ function fromUrlStatus(token, _a) {
|
|
|
517
530
|
/**
|
|
518
531
|
* Create files group.
|
|
519
532
|
*/
|
|
520
|
-
/* eslint @typescript-eslint/camelcase: [2, {allow: ["pub_key"]}] */
|
|
521
533
|
function group(uuids, _a) {
|
|
522
534
|
var publicKey = _a.publicKey, _b = _a.baseURL, baseURL = _b === void 0 ? defaultSettings.baseURL : _b, jsonpCallback = _a.jsonpCallback, secureSignature = _a.secureSignature, secureExpire = _a.secureExpire, signal = _a.signal, source = _a.source, integration = _a.integration, userAgent = _a.userAgent, _c = _a.retryThrottledRequestMaxTimes, retryThrottledRequestMaxTimes = _c === void 0 ? defaultSettings.retryThrottledRequestMaxTimes : _c;
|
|
523
535
|
return retryIfThrottled(function () {
|
|
@@ -540,7 +552,7 @@ function group(uuids, _a) {
|
|
|
540
552
|
var data = _a.data, headers = _a.headers, request = _a.request;
|
|
541
553
|
var response = camelizeKeys(JSON.parse(data));
|
|
542
554
|
if ('error' in response) {
|
|
543
|
-
throw new UploadClientError(
|
|
555
|
+
throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
|
|
544
556
|
}
|
|
545
557
|
else {
|
|
546
558
|
return response;
|
|
@@ -552,7 +564,6 @@ function group(uuids, _a) {
|
|
|
552
564
|
/**
|
|
553
565
|
* Get info about group.
|
|
554
566
|
*/
|
|
555
|
-
/* eslint @typescript-eslint/camelcase: [2, {allow: ["pub_key", "group_id"]}] */
|
|
556
567
|
function groupInfo(id, _a) {
|
|
557
568
|
var publicKey = _a.publicKey, _b = _a.baseURL, baseURL = _b === void 0 ? defaultSettings.baseURL : _b, signal = _a.signal, source = _a.source, integration = _a.integration, userAgent = _a.userAgent, _c = _a.retryThrottledRequestMaxTimes, retryThrottledRequestMaxTimes = _c === void 0 ? defaultSettings.retryThrottledRequestMaxTimes : _c;
|
|
558
569
|
return retryIfThrottled(function () {
|
|
@@ -572,7 +583,7 @@ function groupInfo(id, _a) {
|
|
|
572
583
|
var data = _a.data, headers = _a.headers, request = _a.request;
|
|
573
584
|
var response = camelizeKeys(JSON.parse(data));
|
|
574
585
|
if ('error' in response) {
|
|
575
|
-
throw new UploadClientError(
|
|
586
|
+
throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
|
|
576
587
|
}
|
|
577
588
|
else {
|
|
578
589
|
return response;
|
|
@@ -584,7 +595,6 @@ function groupInfo(id, _a) {
|
|
|
584
595
|
/**
|
|
585
596
|
* Returns a JSON dictionary holding file info.
|
|
586
597
|
*/
|
|
587
|
-
/* eslint @typescript-eslint/camelcase: [2, {allow: ["pub_key", "file_id"]}] */
|
|
588
598
|
function info(uuid, _a) {
|
|
589
599
|
var publicKey = _a.publicKey, _b = _a.baseURL, baseURL = _b === void 0 ? defaultSettings.baseURL : _b, signal = _a.signal, source = _a.source, integration = _a.integration, userAgent = _a.userAgent, _c = _a.retryThrottledRequestMaxTimes, retryThrottledRequestMaxTimes = _c === void 0 ? defaultSettings.retryThrottledRequestMaxTimes : _c;
|
|
590
600
|
return retryIfThrottled(function () {
|
|
@@ -604,7 +614,7 @@ function info(uuid, _a) {
|
|
|
604
614
|
var data = _a.data, headers = _a.headers, request = _a.request;
|
|
605
615
|
var response = camelizeKeys(JSON.parse(data));
|
|
606
616
|
if ('error' in response) {
|
|
607
|
-
throw new UploadClientError(
|
|
617
|
+
throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
|
|
608
618
|
}
|
|
609
619
|
else {
|
|
610
620
|
return response;
|
|
@@ -641,7 +651,7 @@ function multipartStart(size, _a) {
|
|
|
641
651
|
var data = _a.data, headers = _a.headers, request = _a.request;
|
|
642
652
|
var response = camelizeKeys(JSON.parse(data));
|
|
643
653
|
if ('error' in response) {
|
|
644
|
-
throw new UploadClientError(
|
|
654
|
+
throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
|
|
645
655
|
}
|
|
646
656
|
else {
|
|
647
657
|
// convert to array
|
|
@@ -698,7 +708,7 @@ function multipartComplete(uuid, _a) {
|
|
|
698
708
|
var data = _a.data, headers = _a.headers, request = _a.request;
|
|
699
709
|
var response = camelizeKeys(JSON.parse(data));
|
|
700
710
|
if ('error' in response) {
|
|
701
|
-
throw new UploadClientError(
|
|
711
|
+
throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
|
|
702
712
|
}
|
|
703
713
|
else {
|
|
704
714
|
return response;
|
|
@@ -714,6 +724,7 @@ var UploadcareFile = /** @class */ (function () {
|
|
|
714
724
|
this.size = null;
|
|
715
725
|
this.isStored = null;
|
|
716
726
|
this.isImage = null;
|
|
727
|
+
this.mimeType = null;
|
|
717
728
|
this.cdnUrl = null;
|
|
718
729
|
this.cdnUrlModifiers = null;
|
|
719
730
|
this.originalUrl = null;
|
|
@@ -732,6 +743,7 @@ var UploadcareFile = /** @class */ (function () {
|
|
|
732
743
|
this.size = fileInfo.size;
|
|
733
744
|
this.isStored = fileInfo.isStored;
|
|
734
745
|
this.isImage = fileInfo.isImage;
|
|
746
|
+
this.mimeType = fileInfo.mimeType;
|
|
735
747
|
this.cdnUrl = cdnUrl;
|
|
736
748
|
this.cdnUrlModifiers = cdnUrlModifiers;
|
|
737
749
|
this.originalUrl = originalUrl;
|
|
@@ -912,7 +924,7 @@ var Pusher = /** @class */ (function () {
|
|
|
912
924
|
this.disconnectTimeoutId && clearTimeout(this.disconnectTimeoutId);
|
|
913
925
|
if (!this.isConnected && !this.ws) {
|
|
914
926
|
var pusherUrl = "wss://ws.pusherapp.com/app/" + this.key + "?protocol=5&client=js&version=1.12.2";
|
|
915
|
-
this.ws = new
|
|
927
|
+
this.ws = new WebSocket__default["default"](pusherUrl);
|
|
916
928
|
this.ws.addEventListener('error', function (error) {
|
|
917
929
|
_this.emmitter.emit('error', new Error(error.message));
|
|
918
930
|
});
|
|
@@ -922,7 +934,7 @@ var Pusher = /** @class */ (function () {
|
|
|
922
934
|
_this.queue = [];
|
|
923
935
|
});
|
|
924
936
|
this.ws.addEventListener('message', function (e) {
|
|
925
|
-
var data = JSON.parse(e.data);
|
|
937
|
+
var data = JSON.parse(e.data.toString());
|
|
926
938
|
switch (data.event) {
|
|
927
939
|
case 'pusher:connection_established': {
|
|
928
940
|
_this.emmitter.emit('connected', undefined);
|
|
@@ -1031,7 +1043,7 @@ function pollStrategy(_a) {
|
|
|
1031
1043
|
}).then(function (response) {
|
|
1032
1044
|
switch (response.status) {
|
|
1033
1045
|
case Status.Error: {
|
|
1034
|
-
return new UploadClientError(response.error);
|
|
1046
|
+
return new UploadClientError(response.error, response.errorCode);
|
|
1035
1047
|
}
|
|
1036
1048
|
case Status.Waiting: {
|
|
1037
1049
|
return false;
|
|
@@ -1059,7 +1071,7 @@ function pollStrategy(_a) {
|
|
|
1059
1071
|
});
|
|
1060
1072
|
}
|
|
1061
1073
|
var pushStrategy = function (_a) {
|
|
1062
|
-
var token = _a.token, pusherKey = _a.pusherKey, signal = _a.signal,
|
|
1074
|
+
var token = _a.token, pusherKey = _a.pusherKey, signal = _a.signal, onProgress = _a.onProgress;
|
|
1063
1075
|
return new Promise(function (resolve, reject) {
|
|
1064
1076
|
var pusher = getPusher(pusherKey);
|
|
1065
1077
|
var unsubErrorHandler = pusher.onError(reject);
|
|
@@ -1069,10 +1081,9 @@ var pushStrategy = function (_a) {
|
|
|
1069
1081
|
};
|
|
1070
1082
|
onCancel(signal, function () {
|
|
1071
1083
|
destroy();
|
|
1072
|
-
reject(cancelError('
|
|
1084
|
+
reject(cancelError('pusher cancelled'));
|
|
1073
1085
|
});
|
|
1074
1086
|
pusher.subscribe(token, function (result) {
|
|
1075
|
-
stopRace();
|
|
1076
1087
|
switch (result.status) {
|
|
1077
1088
|
case Status.Progress: {
|
|
1078
1089
|
if (onProgress) {
|
|
@@ -1089,7 +1100,7 @@ var pushStrategy = function (_a) {
|
|
|
1089
1100
|
}
|
|
1090
1101
|
case Status.Error: {
|
|
1091
1102
|
destroy();
|
|
1092
|
-
reject(new UploadClientError(result.msg));
|
|
1103
|
+
reject(new UploadClientError(result.msg, result.error_code));
|
|
1093
1104
|
}
|
|
1094
1105
|
}
|
|
1095
1106
|
});
|
|
@@ -1114,6 +1125,11 @@ var uploadFromUrl = function (sourceUrl, _a) {
|
|
|
1114
1125
|
userAgent: userAgent,
|
|
1115
1126
|
retryThrottledRequestMaxTimes: retryThrottledRequestMaxTimes
|
|
1116
1127
|
});
|
|
1128
|
+
})
|
|
1129
|
+
.catch(function (error) {
|
|
1130
|
+
var pusher = getPusher(pusherKey);
|
|
1131
|
+
pusher === null || pusher === void 0 ? void 0 : pusher.disconnect();
|
|
1132
|
+
return Promise.reject(error);
|
|
1117
1133
|
})
|
|
1118
1134
|
.then(function (urlResponse) {
|
|
1119
1135
|
if (urlResponse.type === TypeEnum.FileInfo) {
|
|
@@ -1135,11 +1151,10 @@ var uploadFromUrl = function (sourceUrl, _a) {
|
|
|
1135
1151
|
});
|
|
1136
1152
|
},
|
|
1137
1153
|
function (_a) {
|
|
1138
|
-
var
|
|
1154
|
+
var signal = _a.signal;
|
|
1139
1155
|
return pushStrategy({
|
|
1140
1156
|
token: urlResponse.token,
|
|
1141
1157
|
pusherKey: pusherKey,
|
|
1142
|
-
stopRace: stopRace,
|
|
1143
1158
|
signal: signal,
|
|
1144
1159
|
onProgress: onProgress
|
|
1145
1160
|
});
|
|
@@ -1229,6 +1244,18 @@ var isMultipart = function (fileSize, multipartMinFileSize) {
|
|
|
1229
1244
|
return fileSize >= multipartMinFileSize;
|
|
1230
1245
|
};
|
|
1231
1246
|
|
|
1247
|
+
var sliceChunk = function (file, index, fileSize, chunkSize) {
|
|
1248
|
+
var start = chunkSize * index;
|
|
1249
|
+
var end = Math.min(start + chunkSize, fileSize);
|
|
1250
|
+
return file.slice(start, end);
|
|
1251
|
+
};
|
|
1252
|
+
|
|
1253
|
+
function prepareChunks(file, fileSize, chunkSize) {
|
|
1254
|
+
return function (index) {
|
|
1255
|
+
return sliceChunk(file, index, fileSize, chunkSize);
|
|
1256
|
+
};
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1232
1259
|
var runWithConcurrency = function (concurrency, tasks) {
|
|
1233
1260
|
return new Promise(function (resolve, reject) {
|
|
1234
1261
|
var results = [];
|
|
@@ -1264,18 +1291,15 @@ var runWithConcurrency = function (concurrency, tasks) {
|
|
|
1264
1291
|
});
|
|
1265
1292
|
};
|
|
1266
1293
|
|
|
1267
|
-
var getChunk = function (file, index, fileSize, chunkSize) {
|
|
1268
|
-
var start = chunkSize * index;
|
|
1269
|
-
var end = Math.min(start + chunkSize, fileSize);
|
|
1270
|
-
return file.slice(start, end);
|
|
1271
|
-
};
|
|
1272
1294
|
var uploadPartWithRetry = function (chunk, url, _a) {
|
|
1273
|
-
var onProgress = _a.onProgress, signal = _a.signal, multipartMaxAttempts = _a.multipartMaxAttempts;
|
|
1295
|
+
var publicKey = _a.publicKey, onProgress = _a.onProgress, signal = _a.signal, integration = _a.integration, multipartMaxAttempts = _a.multipartMaxAttempts;
|
|
1274
1296
|
return retrier(function (_a) {
|
|
1275
1297
|
var attempt = _a.attempt, retry = _a.retry;
|
|
1276
1298
|
return multipartUpload(chunk, url, {
|
|
1299
|
+
publicKey: publicKey,
|
|
1277
1300
|
onProgress: onProgress,
|
|
1278
|
-
signal: signal
|
|
1301
|
+
signal: signal,
|
|
1302
|
+
integration: integration
|
|
1279
1303
|
}).catch(function (error) {
|
|
1280
1304
|
if (attempt < multipartMaxAttempts) {
|
|
1281
1305
|
return retry();
|
|
@@ -1319,12 +1343,15 @@ var uploadMultipart = function (file, _a) {
|
|
|
1319
1343
|
})
|
|
1320
1344
|
.then(function (_a) {
|
|
1321
1345
|
var uuid = _a.uuid, parts = _a.parts;
|
|
1346
|
+
var getChunk = prepareChunks(file, size, multipartChunkSize);
|
|
1322
1347
|
return Promise.all([
|
|
1323
1348
|
uuid,
|
|
1324
1349
|
runWithConcurrency(maxConcurrentRequests, parts.map(function (url, index) { return function () {
|
|
1325
|
-
return uploadPartWithRetry(getChunk(
|
|
1350
|
+
return uploadPartWithRetry(getChunk(index), url, {
|
|
1351
|
+
publicKey: publicKey,
|
|
1326
1352
|
onProgress: createProgressHandler(parts.length, index),
|
|
1327
1353
|
signal: signal,
|
|
1354
|
+
integration: integration,
|
|
1328
1355
|
multipartMaxAttempts: multipartMaxAttempts
|
|
1329
1356
|
});
|
|
1330
1357
|
}; }))
|
|
@@ -1366,7 +1393,7 @@ var uploadMultipart = function (file, _a) {
|
|
|
1366
1393
|
* Uploads file from provided data.
|
|
1367
1394
|
*/
|
|
1368
1395
|
function uploadFile(data, _a) {
|
|
1369
|
-
var publicKey = _a.publicKey, fileName = _a.fileName, _b = _a.baseURL, baseURL = _b === void 0 ? defaultSettings.baseURL : _b, secureSignature = _a.secureSignature, secureExpire = _a.secureExpire, store = _a.store, signal = _a.signal, onProgress = _a.onProgress, source = _a.source, integration = _a.integration, userAgent = _a.userAgent, retryThrottledRequestMaxTimes = _a.retryThrottledRequestMaxTimes, contentType = _a.contentType,
|
|
1396
|
+
var publicKey = _a.publicKey, fileName = _a.fileName, _b = _a.baseURL, baseURL = _b === void 0 ? defaultSettings.baseURL : _b, secureSignature = _a.secureSignature, secureExpire = _a.secureExpire, store = _a.store, signal = _a.signal, onProgress = _a.onProgress, source = _a.source, integration = _a.integration, userAgent = _a.userAgent, retryThrottledRequestMaxTimes = _a.retryThrottledRequestMaxTimes, contentType = _a.contentType, multipartChunkSize = _a.multipartChunkSize, multipartMaxAttempts = _a.multipartMaxAttempts, maxConcurrentRequests = _a.maxConcurrentRequests, _c = _a.baseCDN, baseCDN = _c === void 0 ? defaultSettings.baseCDN : _c, checkForUrlDuplicates = _a.checkForUrlDuplicates, saveUrlForRecurrentUploads = _a.saveUrlForRecurrentUploads, pusherKey = _a.pusherKey;
|
|
1370
1397
|
if (isFileData(data)) {
|
|
1371
1398
|
var fileSize = getFileSize(data);
|
|
1372
1399
|
if (isMultipart(fileSize)) {
|
|
@@ -1374,6 +1401,7 @@ function uploadFile(data, _a) {
|
|
|
1374
1401
|
publicKey: publicKey,
|
|
1375
1402
|
contentType: contentType,
|
|
1376
1403
|
multipartChunkSize: multipartChunkSize,
|
|
1404
|
+
multipartMaxAttempts: multipartMaxAttempts,
|
|
1377
1405
|
fileName: fileName,
|
|
1378
1406
|
baseURL: baseURL,
|
|
1379
1407
|
secureSignature: secureSignature,
|
|
@@ -1384,6 +1412,7 @@ function uploadFile(data, _a) {
|
|
|
1384
1412
|
source: source,
|
|
1385
1413
|
integration: integration,
|
|
1386
1414
|
userAgent: userAgent,
|
|
1415
|
+
maxConcurrentRequests: maxConcurrentRequests,
|
|
1387
1416
|
retryThrottledRequestMaxTimes: retryThrottledRequestMaxTimes,
|
|
1388
1417
|
baseCDN: baseCDN
|
|
1389
1418
|
});
|
|
@@ -1409,6 +1438,9 @@ function uploadFile(data, _a) {
|
|
|
1409
1438
|
publicKey: publicKey,
|
|
1410
1439
|
fileName: fileName,
|
|
1411
1440
|
baseURL: baseURL,
|
|
1441
|
+
baseCDN: baseCDN,
|
|
1442
|
+
checkForUrlDuplicates: checkForUrlDuplicates,
|
|
1443
|
+
saveUrlForRecurrentUploads: saveUrlForRecurrentUploads,
|
|
1412
1444
|
secureSignature: secureSignature,
|
|
1413
1445
|
secureExpire: secureExpire,
|
|
1414
1446
|
store: store,
|
|
@@ -1418,7 +1450,7 @@ function uploadFile(data, _a) {
|
|
|
1418
1450
|
integration: integration,
|
|
1419
1451
|
userAgent: userAgent,
|
|
1420
1452
|
retryThrottledRequestMaxTimes: retryThrottledRequestMaxTimes,
|
|
1421
|
-
|
|
1453
|
+
pusherKey: pusherKey
|
|
1422
1454
|
});
|
|
1423
1455
|
}
|
|
1424
1456
|
if (isUuid(data)) {
|
|
@@ -1445,8 +1477,7 @@ var UploadcareGroup = /** @class */ (function () {
|
|
|
1445
1477
|
this.filesCount = groupInfo.filesCount;
|
|
1446
1478
|
this.totalSize = Object.values(groupInfo.files).reduce(function (acc, file) { return acc + file.size; }, 0);
|
|
1447
1479
|
this.isStored = !!groupInfo.datetimeStored;
|
|
1448
|
-
this.isImage = !!Object.values(groupInfo.files).filter(function (file) { return file.isImage; })
|
|
1449
|
-
.length;
|
|
1480
|
+
this.isImage = !!Object.values(groupInfo.files).filter(function (file) { return file.isImage; }).length;
|
|
1450
1481
|
this.cdnUrl = groupInfo.cdnUrl;
|
|
1451
1482
|
this.files = files;
|
|
1452
1483
|
this.createdAt = groupInfo.datetimeCreated;
|
|
@@ -1619,9 +1650,7 @@ var UploadClient = /** @class */ (function () {
|
|
|
1619
1650
|
|
|
1620
1651
|
Object.defineProperty(exports, 'AbortController', {
|
|
1621
1652
|
enumerable: true,
|
|
1622
|
-
get: function () {
|
|
1623
|
-
return abortController.AbortController;
|
|
1624
|
-
}
|
|
1653
|
+
get: function () { return abortController.AbortController; }
|
|
1625
1654
|
});
|
|
1626
1655
|
exports.UploadClient = UploadClient;
|
|
1627
1656
|
exports.base = base;
|
|
@@ -1633,5 +1662,9 @@ exports.info = info;
|
|
|
1633
1662
|
exports.multipartComplete = multipartComplete;
|
|
1634
1663
|
exports.multipartStart = multipartStart;
|
|
1635
1664
|
exports.multipartUpload = multipartUpload;
|
|
1665
|
+
exports.uploadBase = uploadFromObject;
|
|
1636
1666
|
exports.uploadFile = uploadFile;
|
|
1637
1667
|
exports.uploadFileGroup = uploadFileGroup;
|
|
1668
|
+
exports.uploadFromUploaded = uploadFromUploaded;
|
|
1669
|
+
exports.uploadFromUrl = uploadFromUrl;
|
|
1670
|
+
exports.uploadMultipart = uploadMultipart;
|