@uploadcare/upload-client 3.1.2-alpha.0 → 4.1.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 +4 -4
- package/dist/index.browser.js +1443 -1461
- package/dist/{index.js → index.node.js} +1470 -1478
- package/dist/index.react-native.js +1545 -0
- package/dist/types.d.ts +45 -37
- package/package.json +23 -55
- package/LICENSE +0 -21
- package/dist/index.browser.cjs +0 -1753
- package/dist/index.cjs +0 -1790
package/dist/index.browser.cjs
DELETED
|
@@ -1,1753 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
/*! *****************************************************************************
|
|
6
|
-
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
7
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
8
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
9
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
|
|
11
|
-
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
12
|
-
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
13
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
14
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
15
|
-
|
|
16
|
-
See the Apache Version 2.0 License for specific language governing permissions
|
|
17
|
-
and limitations under the License.
|
|
18
|
-
***************************************************************************** */
|
|
19
|
-
/* global Reflect, Promise */
|
|
20
|
-
|
|
21
|
-
var extendStatics = function(d, b) {
|
|
22
|
-
extendStatics = Object.setPrototypeOf ||
|
|
23
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
24
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
25
|
-
return extendStatics(d, b);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
function __extends(d, b) {
|
|
29
|
-
extendStatics(d, b);
|
|
30
|
-
function __() { this.constructor = d; }
|
|
31
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
var __assign = function() {
|
|
35
|
-
__assign = Object.assign || function __assign(t) {
|
|
36
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
37
|
-
s = arguments[i];
|
|
38
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
39
|
-
}
|
|
40
|
-
return t;
|
|
41
|
-
};
|
|
42
|
-
return __assign.apply(this, arguments);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
function __spreadArrays() {
|
|
46
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
47
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
48
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
49
|
-
r[k] = a[j];
|
|
50
|
-
return r;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
var UploadClientError = /** @class */ (function (_super) {
|
|
54
|
-
__extends(UploadClientError, _super);
|
|
55
|
-
function UploadClientError(message, code, request, response, headers) {
|
|
56
|
-
var _this = _super.call(this) || this;
|
|
57
|
-
_this.name = 'UploadClientError';
|
|
58
|
-
_this.message = message;
|
|
59
|
-
_this.code = code;
|
|
60
|
-
_this.request = request;
|
|
61
|
-
_this.response = response;
|
|
62
|
-
_this.headers = headers;
|
|
63
|
-
Object.setPrototypeOf(_this, UploadClientError.prototype);
|
|
64
|
-
return _this;
|
|
65
|
-
}
|
|
66
|
-
return UploadClientError;
|
|
67
|
-
}(Error));
|
|
68
|
-
var cancelError = function (message) {
|
|
69
|
-
if (message === void 0) { message = 'Request canceled'; }
|
|
70
|
-
var error = new UploadClientError(message);
|
|
71
|
-
error.isCancel = true;
|
|
72
|
-
return error;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
var onCancel = function (signal, callback) {
|
|
76
|
-
if (signal) {
|
|
77
|
-
if (signal.aborted) {
|
|
78
|
-
Promise.resolve().then(callback);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
signal.addEventListener('abort', function () { return callback(); }, { once: true });
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
var request = function (_a) {
|
|
87
|
-
var method = _a.method, url = _a.url, data = _a.data, _b = _a.headers, headers = _b === void 0 ? {} : _b, signal = _a.signal, onProgress = _a.onProgress;
|
|
88
|
-
return new Promise(function (resolve, reject) {
|
|
89
|
-
var xhr = new XMLHttpRequest();
|
|
90
|
-
var requestMethod = (method === null || method === void 0 ? void 0 : method.toUpperCase()) || 'GET';
|
|
91
|
-
var aborted = false;
|
|
92
|
-
xhr.open(requestMethod, url);
|
|
93
|
-
if (headers) {
|
|
94
|
-
Object.entries(headers).forEach(function (entry) {
|
|
95
|
-
var key = entry[0], value = entry[1];
|
|
96
|
-
typeof value !== 'undefined' &&
|
|
97
|
-
!Array.isArray(value) &&
|
|
98
|
-
xhr.setRequestHeader(key, value);
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
xhr.responseType = 'text';
|
|
102
|
-
onCancel(signal, function () {
|
|
103
|
-
aborted = true;
|
|
104
|
-
xhr.abort();
|
|
105
|
-
reject(cancelError());
|
|
106
|
-
});
|
|
107
|
-
xhr.onload = function () {
|
|
108
|
-
if (xhr.status != 200) {
|
|
109
|
-
// analyze HTTP status of the response
|
|
110
|
-
reject(new Error("Error " + xhr.status + ": " + xhr.statusText)); // e.g. 404: Not Found
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
var request_1 = {
|
|
114
|
-
method: requestMethod,
|
|
115
|
-
url: url,
|
|
116
|
-
data: data,
|
|
117
|
-
headers: headers || undefined,
|
|
118
|
-
signal: signal,
|
|
119
|
-
onProgress: onProgress
|
|
120
|
-
};
|
|
121
|
-
// Convert the header string into an array
|
|
122
|
-
// of individual headers
|
|
123
|
-
var headersArray = xhr
|
|
124
|
-
.getAllResponseHeaders()
|
|
125
|
-
.trim()
|
|
126
|
-
.split(/[\r\n]+/);
|
|
127
|
-
// Create a map of header names to values
|
|
128
|
-
var responseHeaders_1 = {};
|
|
129
|
-
headersArray.forEach(function (line) {
|
|
130
|
-
var parts = line.split(': ');
|
|
131
|
-
var header = parts.shift();
|
|
132
|
-
var value = parts.join(': ');
|
|
133
|
-
if (header && typeof header !== 'undefined') {
|
|
134
|
-
responseHeaders_1[header] = value;
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
var responseData = xhr.response;
|
|
138
|
-
var responseStatus = xhr.status;
|
|
139
|
-
resolve({
|
|
140
|
-
request: request_1,
|
|
141
|
-
data: responseData,
|
|
142
|
-
headers: responseHeaders_1,
|
|
143
|
-
status: responseStatus
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
xhr.onerror = function () {
|
|
148
|
-
if (aborted)
|
|
149
|
-
return;
|
|
150
|
-
// only triggers if the request couldn't be made at all
|
|
151
|
-
reject(new Error('Network error'));
|
|
152
|
-
};
|
|
153
|
-
if (onProgress && typeof onProgress === 'function') {
|
|
154
|
-
xhr.upload.onprogress = function (event) {
|
|
155
|
-
if (event.lengthComputable) {
|
|
156
|
-
onProgress({
|
|
157
|
-
isComputable: true,
|
|
158
|
-
value: event.loaded / event.total
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
onProgress({ isComputable: false });
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
if (data) {
|
|
167
|
-
xhr.send(data);
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
xhr.send();
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
function identity(obj) {
|
|
176
|
-
return obj;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
var getFileOptions = function (_a) {
|
|
180
|
-
var name = _a.name;
|
|
181
|
-
return name ? [name] : [];
|
|
182
|
-
};
|
|
183
|
-
var transformFile = identity;
|
|
184
|
-
var getFormData = (function () { return new FormData(); });
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* FileData type guard.
|
|
188
|
-
*/
|
|
189
|
-
var isFileData = function (data) {
|
|
190
|
-
return (data !== undefined &&
|
|
191
|
-
((typeof Blob !== 'undefined' && data instanceof Blob) ||
|
|
192
|
-
(typeof File !== 'undefined' && data instanceof File) ||
|
|
193
|
-
(typeof Buffer !== 'undefined' && data instanceof Buffer)));
|
|
194
|
-
};
|
|
195
|
-
/**
|
|
196
|
-
* Uuid type guard.
|
|
197
|
-
*/
|
|
198
|
-
var isUuid = function (data) {
|
|
199
|
-
var UUID_REGEX = '[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}';
|
|
200
|
-
var regExp = new RegExp(UUID_REGEX);
|
|
201
|
-
return !isFileData(data) && regExp.test(data);
|
|
202
|
-
};
|
|
203
|
-
/**
|
|
204
|
-
* Url type guard.
|
|
205
|
-
*
|
|
206
|
-
* @param {NodeFile | BrowserFile | Url | Uuid} data
|
|
207
|
-
*/
|
|
208
|
-
var isUrl = function (data) {
|
|
209
|
-
var URL_REGEX = '^(?:\\w+:)?\\/\\/([^\\s\\.]+\\.\\S{2}|localhost[\\:?\\d]*)\\S*$';
|
|
210
|
-
var regExp = new RegExp(URL_REGEX);
|
|
211
|
-
return !isFileData(data) && regExp.test(data);
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
var isSimpleValue = function (value) {
|
|
215
|
-
return (typeof value === 'string' ||
|
|
216
|
-
typeof value === 'number' ||
|
|
217
|
-
typeof value === 'undefined');
|
|
218
|
-
};
|
|
219
|
-
var isObjectValue = function (value) {
|
|
220
|
-
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
221
|
-
};
|
|
222
|
-
var isFileValue = function (value) {
|
|
223
|
-
return !!value &&
|
|
224
|
-
typeof value === 'object' &&
|
|
225
|
-
'data' in value &&
|
|
226
|
-
isFileData(value.data);
|
|
227
|
-
};
|
|
228
|
-
function collectParams(params, inputKey, inputValue) {
|
|
229
|
-
if (isFileValue(inputValue)) {
|
|
230
|
-
var name_1 = inputValue.name, contentType = inputValue.contentType;
|
|
231
|
-
var file = transformFile(inputValue.data); // lgtm [js/superfluous-trailing-arguments]
|
|
232
|
-
var options = getFileOptions({ name: name_1, contentType: contentType });
|
|
233
|
-
params.push(__spreadArrays([inputKey, file], options));
|
|
234
|
-
}
|
|
235
|
-
else if (isObjectValue(inputValue)) {
|
|
236
|
-
for (var _i = 0, _a = Object.entries(inputValue); _i < _a.length; _i++) {
|
|
237
|
-
var _b = _a[_i], key = _b[0], value = _b[1];
|
|
238
|
-
if (typeof value !== 'undefined') {
|
|
239
|
-
params.push([inputKey + "[" + key + "]", String(value)]);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
else if (isSimpleValue(inputValue) && inputValue) {
|
|
244
|
-
params.push([inputKey, inputValue.toString()]);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
function getFormDataParams(options) {
|
|
248
|
-
var params = [];
|
|
249
|
-
for (var _i = 0, _a = Object.entries(options); _i < _a.length; _i++) {
|
|
250
|
-
var _b = _a[_i], key = _b[0], value = _b[1];
|
|
251
|
-
collectParams(params, key, value);
|
|
252
|
-
}
|
|
253
|
-
return params;
|
|
254
|
-
}
|
|
255
|
-
function buildFormData(options) {
|
|
256
|
-
var formData = getFormData();
|
|
257
|
-
var paramsList = getFormDataParams(options);
|
|
258
|
-
for (var _i = 0, paramsList_1 = paramsList; _i < paramsList_1.length; _i++) {
|
|
259
|
-
var params = paramsList_1[_i];
|
|
260
|
-
var key = params[0], value = params[1], options_1 = params.slice(2);
|
|
261
|
-
// node form-data has another signature for append
|
|
262
|
-
formData.append.apply(formData, __spreadArrays([key, value], options_1));
|
|
263
|
-
}
|
|
264
|
-
return formData;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
var serializePair = function (key, value) {
|
|
268
|
-
return typeof value !== 'undefined' ? key + "=" + encodeURIComponent(value) : null;
|
|
269
|
-
};
|
|
270
|
-
// TODO: generalize value transforming logic and use it here and inside `buildFormData`
|
|
271
|
-
var createQuery = function (query) {
|
|
272
|
-
return Object.entries(query)
|
|
273
|
-
.reduce(function (params, _a) {
|
|
274
|
-
var key = _a[0], value = _a[1];
|
|
275
|
-
var param;
|
|
276
|
-
if (typeof value === 'object' && !Array.isArray(value)) {
|
|
277
|
-
param = Object.entries(value)
|
|
278
|
-
.filter(function (entry) { return typeof entry[1] !== 'undefined'; })
|
|
279
|
-
.map(function (entry) {
|
|
280
|
-
return serializePair(key + "[" + entry[0] + "]", String(entry[1]));
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
else if (Array.isArray(value)) {
|
|
284
|
-
param = value.map(function (val) { return serializePair(key + "[]", val); });
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
param = serializePair(key, value);
|
|
288
|
-
}
|
|
289
|
-
return params.concat(param);
|
|
290
|
-
}, [])
|
|
291
|
-
.filter(function (x) { return !!x; })
|
|
292
|
-
.join('&');
|
|
293
|
-
};
|
|
294
|
-
var getUrl = function (base, path, query) {
|
|
295
|
-
return [
|
|
296
|
-
base,
|
|
297
|
-
path,
|
|
298
|
-
query && Object.keys(query).length > 0 ? '?' : '',
|
|
299
|
-
query && createQuery(query)
|
|
300
|
-
]
|
|
301
|
-
.filter(Boolean)
|
|
302
|
-
.join('');
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
/*
|
|
306
|
-
Settings for future support:
|
|
307
|
-
parallelDirectUploads: 10,
|
|
308
|
-
*/
|
|
309
|
-
var defaultSettings = {
|
|
310
|
-
baseCDN: 'https://ucarecdn.com',
|
|
311
|
-
baseURL: 'https://upload.uploadcare.com',
|
|
312
|
-
maxContentLength: 50 * 1024 * 1024,
|
|
313
|
-
retryThrottledRequestMaxTimes: 1,
|
|
314
|
-
multipartMinFileSize: 25 * 1024 * 1024,
|
|
315
|
-
multipartChunkSize: 5 * 1024 * 1024,
|
|
316
|
-
multipartMinLastPartSize: 1024 * 1024,
|
|
317
|
-
maxConcurrentRequests: 4,
|
|
318
|
-
multipartMaxAttempts: 3,
|
|
319
|
-
pollingTimeoutMilliseconds: 10000,
|
|
320
|
-
pusherKey: '79ae88bd931ea68464d9'
|
|
321
|
-
};
|
|
322
|
-
var defaultContentType = 'application/octet-stream';
|
|
323
|
-
var defaultFilename = 'original';
|
|
324
|
-
|
|
325
|
-
var version = '3.1.1';
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Returns User Agent based on version and settings.
|
|
329
|
-
*/
|
|
330
|
-
function getUserAgent(_a) {
|
|
331
|
-
var _b = _a === void 0 ? {} : _a, userAgent = _b.userAgent, _c = _b.publicKey, publicKey = _c === void 0 ? '' : _c, _d = _b.integration, integration = _d === void 0 ? '' : _d;
|
|
332
|
-
var libraryName = 'UploadcareUploadClient';
|
|
333
|
-
var libraryVersion = version;
|
|
334
|
-
var languageName = 'JavaScript';
|
|
335
|
-
if (typeof userAgent === 'string') {
|
|
336
|
-
return userAgent;
|
|
337
|
-
}
|
|
338
|
-
if (typeof userAgent === 'function') {
|
|
339
|
-
return userAgent({
|
|
340
|
-
publicKey: publicKey,
|
|
341
|
-
libraryName: libraryName,
|
|
342
|
-
libraryVersion: libraryVersion,
|
|
343
|
-
languageName: languageName,
|
|
344
|
-
integration: integration
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
var mainInfo = [libraryName, libraryVersion, publicKey]
|
|
348
|
-
.filter(Boolean)
|
|
349
|
-
.join('/');
|
|
350
|
-
var additionInfo = [languageName, integration].filter(Boolean).join('; ');
|
|
351
|
-
return mainInfo + " (" + additionInfo + ")";
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
var SEPARATOR = /\W|_/g;
|
|
355
|
-
/**
|
|
356
|
-
* Transforms a string to camelCased.
|
|
357
|
-
*/
|
|
358
|
-
function camelize(text) {
|
|
359
|
-
return text
|
|
360
|
-
.split(SEPARATOR)
|
|
361
|
-
.map(function (word, index) {
|
|
362
|
-
return word.charAt(0)[index > 0 ? 'toUpperCase' : 'toLowerCase']() +
|
|
363
|
-
word.slice(1);
|
|
364
|
-
})
|
|
365
|
-
.join('');
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Transforms keys of an object to camelCased recursively.
|
|
369
|
-
*/
|
|
370
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
371
|
-
function camelizeKeys(source) {
|
|
372
|
-
if (!source || typeof source !== 'object') {
|
|
373
|
-
return source;
|
|
374
|
-
}
|
|
375
|
-
return Object.keys(source).reduce(function (accumulator, key) {
|
|
376
|
-
accumulator[camelize(key)] =
|
|
377
|
-
typeof source[key] === 'object' ? camelizeKeys(source[key]) : source[key];
|
|
378
|
-
return accumulator;
|
|
379
|
-
}, {});
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* setTimeout as Promise.
|
|
384
|
-
*
|
|
385
|
-
* @param {number} ms Timeout in milliseconds.
|
|
386
|
-
*/
|
|
387
|
-
var delay = function (ms) {
|
|
388
|
-
return new Promise(function (resolve) { return setTimeout(resolve, ms); });
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
var defaultOptions = {
|
|
392
|
-
factor: 2,
|
|
393
|
-
time: 100
|
|
394
|
-
};
|
|
395
|
-
function retrier(fn, options) {
|
|
396
|
-
if (options === void 0) { options = defaultOptions; }
|
|
397
|
-
var attempts = 0;
|
|
398
|
-
function runAttempt(fn) {
|
|
399
|
-
var defaultDelayTime = Math.round(options.time * Math.pow(options.factor, attempts));
|
|
400
|
-
var retry = function (ms) {
|
|
401
|
-
return delay(ms !== null && ms !== void 0 ? ms : defaultDelayTime).then(function () {
|
|
402
|
-
attempts += 1;
|
|
403
|
-
return runAttempt(fn);
|
|
404
|
-
});
|
|
405
|
-
};
|
|
406
|
-
return fn({
|
|
407
|
-
attempt: attempts,
|
|
408
|
-
retry: retry
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
return runAttempt(fn);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
var REQUEST_WAS_THROTTLED_CODE = 'RequestThrottledError';
|
|
415
|
-
var DEFAULT_RETRY_AFTER_TIMEOUT = 15000;
|
|
416
|
-
function getTimeoutFromThrottledRequest(error) {
|
|
417
|
-
var headers = (error || {}).headers;
|
|
418
|
-
return ((headers &&
|
|
419
|
-
Number.parseInt(headers['x-throttle-wait-seconds']) * 1000) ||
|
|
420
|
-
DEFAULT_RETRY_AFTER_TIMEOUT);
|
|
421
|
-
}
|
|
422
|
-
function retryIfThrottled(fn, retryThrottledMaxTimes) {
|
|
423
|
-
return retrier(function (_a) {
|
|
424
|
-
var attempt = _a.attempt, retry = _a.retry;
|
|
425
|
-
return fn().catch(function (error) {
|
|
426
|
-
if ('response' in error &&
|
|
427
|
-
(error === null || error === void 0 ? void 0 : error.code) === REQUEST_WAS_THROTTLED_CODE &&
|
|
428
|
-
attempt < retryThrottledMaxTimes) {
|
|
429
|
-
return retry(getTimeoutFromThrottledRequest(error));
|
|
430
|
-
}
|
|
431
|
-
throw error;
|
|
432
|
-
});
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
function getStoreValue(store) {
|
|
437
|
-
return typeof store === 'undefined' ? 'auto' : store ? '1' : '0';
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Performs file uploading request to Uploadcare Upload API.
|
|
442
|
-
* Can be canceled and has progress.
|
|
443
|
-
*/
|
|
444
|
-
function base(file, _a) {
|
|
445
|
-
var publicKey = _a.publicKey, fileName = _a.fileName, contentType = _a.contentType, _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, _c = _a.source, source = _c === void 0 ? 'local' : _c, integration = _a.integration, userAgent = _a.userAgent, _d = _a.retryThrottledRequestMaxTimes, retryThrottledRequestMaxTimes = _d === void 0 ? defaultSettings.retryThrottledRequestMaxTimes : _d, metadata = _a.metadata;
|
|
446
|
-
return retryIfThrottled(function () {
|
|
447
|
-
var _a;
|
|
448
|
-
return request({
|
|
449
|
-
method: 'POST',
|
|
450
|
-
url: getUrl(baseURL, '/base/', {
|
|
451
|
-
jsonerrors: 1
|
|
452
|
-
}),
|
|
453
|
-
headers: {
|
|
454
|
-
'X-UC-User-Agent': getUserAgent({ publicKey: publicKey, integration: integration, userAgent: userAgent })
|
|
455
|
-
},
|
|
456
|
-
data: buildFormData({
|
|
457
|
-
file: {
|
|
458
|
-
data: file,
|
|
459
|
-
name: (_a = fileName !== null && fileName !== void 0 ? fileName : file.name) !== null && _a !== void 0 ? _a : defaultFilename,
|
|
460
|
-
contentType: contentType
|
|
461
|
-
},
|
|
462
|
-
UPLOADCARE_PUB_KEY: publicKey,
|
|
463
|
-
UPLOADCARE_STORE: getStoreValue(store),
|
|
464
|
-
signature: secureSignature,
|
|
465
|
-
expire: secureExpire,
|
|
466
|
-
source: source,
|
|
467
|
-
metadata: metadata
|
|
468
|
-
}),
|
|
469
|
-
signal: signal,
|
|
470
|
-
onProgress: onProgress
|
|
471
|
-
}).then(function (_a) {
|
|
472
|
-
var data = _a.data, headers = _a.headers, request = _a.request;
|
|
473
|
-
var response = camelizeKeys(JSON.parse(data));
|
|
474
|
-
if ('error' in response) {
|
|
475
|
-
throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
|
|
476
|
-
}
|
|
477
|
-
else {
|
|
478
|
-
return response;
|
|
479
|
-
}
|
|
480
|
-
});
|
|
481
|
-
}, retryThrottledRequestMaxTimes);
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
var TypeEnum;
|
|
485
|
-
(function (TypeEnum) {
|
|
486
|
-
TypeEnum["Token"] = "token";
|
|
487
|
-
TypeEnum["FileInfo"] = "file_info";
|
|
488
|
-
})(TypeEnum || (TypeEnum = {}));
|
|
489
|
-
/**
|
|
490
|
-
* Uploading files from URL.
|
|
491
|
-
*/
|
|
492
|
-
function fromUrl(sourceUrl, _a) {
|
|
493
|
-
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, metadata = _a.metadata;
|
|
494
|
-
return retryIfThrottled(function () {
|
|
495
|
-
return request({
|
|
496
|
-
method: 'POST',
|
|
497
|
-
headers: {
|
|
498
|
-
'X-UC-User-Agent': getUserAgent({ publicKey: publicKey, integration: integration, userAgent: userAgent })
|
|
499
|
-
},
|
|
500
|
-
url: getUrl(baseURL, '/from_url/', {
|
|
501
|
-
jsonerrors: 1,
|
|
502
|
-
pub_key: publicKey,
|
|
503
|
-
source_url: sourceUrl,
|
|
504
|
-
store: getStoreValue(store),
|
|
505
|
-
filename: fileName,
|
|
506
|
-
check_URL_duplicates: checkForUrlDuplicates ? 1 : undefined,
|
|
507
|
-
save_URL_duplicates: saveUrlForRecurrentUploads ? 1 : undefined,
|
|
508
|
-
signature: secureSignature,
|
|
509
|
-
expire: secureExpire,
|
|
510
|
-
source: source,
|
|
511
|
-
metadata: metadata
|
|
512
|
-
}),
|
|
513
|
-
signal: signal
|
|
514
|
-
}).then(function (_a) {
|
|
515
|
-
var data = _a.data, headers = _a.headers, request = _a.request;
|
|
516
|
-
var response = camelizeKeys(JSON.parse(data));
|
|
517
|
-
if ('error' in response) {
|
|
518
|
-
throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
|
|
519
|
-
}
|
|
520
|
-
else {
|
|
521
|
-
return response;
|
|
522
|
-
}
|
|
523
|
-
});
|
|
524
|
-
}, retryThrottledRequestMaxTimes);
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
var Status;
|
|
528
|
-
(function (Status) {
|
|
529
|
-
Status["Unknown"] = "unknown";
|
|
530
|
-
Status["Waiting"] = "waiting";
|
|
531
|
-
Status["Progress"] = "progress";
|
|
532
|
-
Status["Error"] = "error";
|
|
533
|
-
Status["Success"] = "success";
|
|
534
|
-
})(Status || (Status = {}));
|
|
535
|
-
var isErrorResponse = function (response) {
|
|
536
|
-
return 'status' in response && response.status === Status.Error;
|
|
537
|
-
};
|
|
538
|
-
/**
|
|
539
|
-
* Checking upload status and working with file tokens.
|
|
540
|
-
*/
|
|
541
|
-
function fromUrlStatus(token, _a) {
|
|
542
|
-
var _b = _a === void 0 ? {} : _a, publicKey = _b.publicKey, _c = _b.baseURL, baseURL = _c === void 0 ? defaultSettings.baseURL : _c, signal = _b.signal, integration = _b.integration, userAgent = _b.userAgent, _d = _b.retryThrottledRequestMaxTimes, retryThrottledRequestMaxTimes = _d === void 0 ? defaultSettings.retryThrottledRequestMaxTimes : _d;
|
|
543
|
-
return retryIfThrottled(function () {
|
|
544
|
-
return request({
|
|
545
|
-
method: 'GET',
|
|
546
|
-
headers: publicKey
|
|
547
|
-
? {
|
|
548
|
-
'X-UC-User-Agent': getUserAgent({
|
|
549
|
-
publicKey: publicKey,
|
|
550
|
-
integration: integration,
|
|
551
|
-
userAgent: userAgent
|
|
552
|
-
})
|
|
553
|
-
}
|
|
554
|
-
: undefined,
|
|
555
|
-
url: getUrl(baseURL, '/from_url/status/', {
|
|
556
|
-
jsonerrors: 1,
|
|
557
|
-
token: token
|
|
558
|
-
}),
|
|
559
|
-
signal: signal
|
|
560
|
-
}).then(function (_a) {
|
|
561
|
-
var data = _a.data, headers = _a.headers, request = _a.request;
|
|
562
|
-
var response = camelizeKeys(JSON.parse(data));
|
|
563
|
-
if ('error' in response && !isErrorResponse(response)) {
|
|
564
|
-
throw new UploadClientError(response.error.content, undefined, request, response, headers);
|
|
565
|
-
}
|
|
566
|
-
else {
|
|
567
|
-
return response;
|
|
568
|
-
}
|
|
569
|
-
});
|
|
570
|
-
}, retryThrottledRequestMaxTimes);
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
/**
|
|
574
|
-
* Create files group.
|
|
575
|
-
*/
|
|
576
|
-
function group(uuids, _a) {
|
|
577
|
-
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;
|
|
578
|
-
return retryIfThrottled(function () {
|
|
579
|
-
return request({
|
|
580
|
-
method: 'POST',
|
|
581
|
-
headers: {
|
|
582
|
-
'X-UC-User-Agent': getUserAgent({ publicKey: publicKey, integration: integration, userAgent: userAgent })
|
|
583
|
-
},
|
|
584
|
-
url: getUrl(baseURL, '/group/', {
|
|
585
|
-
jsonerrors: 1,
|
|
586
|
-
pub_key: publicKey,
|
|
587
|
-
files: uuids,
|
|
588
|
-
callback: jsonpCallback,
|
|
589
|
-
signature: secureSignature,
|
|
590
|
-
expire: secureExpire,
|
|
591
|
-
source: source
|
|
592
|
-
}),
|
|
593
|
-
signal: signal
|
|
594
|
-
}).then(function (_a) {
|
|
595
|
-
var data = _a.data, headers = _a.headers, request = _a.request;
|
|
596
|
-
var response = camelizeKeys(JSON.parse(data));
|
|
597
|
-
if ('error' in response) {
|
|
598
|
-
throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
|
|
599
|
-
}
|
|
600
|
-
else {
|
|
601
|
-
return response;
|
|
602
|
-
}
|
|
603
|
-
});
|
|
604
|
-
}, retryThrottledRequestMaxTimes);
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
/**
|
|
608
|
-
* Get info about group.
|
|
609
|
-
*/
|
|
610
|
-
function groupInfo(id, _a) {
|
|
611
|
-
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;
|
|
612
|
-
return retryIfThrottled(function () {
|
|
613
|
-
return request({
|
|
614
|
-
method: 'GET',
|
|
615
|
-
headers: {
|
|
616
|
-
'X-UC-User-Agent': getUserAgent({ publicKey: publicKey, integration: integration, userAgent: userAgent })
|
|
617
|
-
},
|
|
618
|
-
url: getUrl(baseURL, '/group/info/', {
|
|
619
|
-
jsonerrors: 1,
|
|
620
|
-
pub_key: publicKey,
|
|
621
|
-
group_id: id,
|
|
622
|
-
source: source
|
|
623
|
-
}),
|
|
624
|
-
signal: signal
|
|
625
|
-
}).then(function (_a) {
|
|
626
|
-
var data = _a.data, headers = _a.headers, request = _a.request;
|
|
627
|
-
var response = camelizeKeys(JSON.parse(data));
|
|
628
|
-
if ('error' in response) {
|
|
629
|
-
throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
|
|
630
|
-
}
|
|
631
|
-
else {
|
|
632
|
-
return response;
|
|
633
|
-
}
|
|
634
|
-
});
|
|
635
|
-
}, retryThrottledRequestMaxTimes);
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
/**
|
|
639
|
-
* Returns a JSON dictionary holding file info.
|
|
640
|
-
*/
|
|
641
|
-
function info(uuid, _a) {
|
|
642
|
-
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;
|
|
643
|
-
return retryIfThrottled(function () {
|
|
644
|
-
return request({
|
|
645
|
-
method: 'GET',
|
|
646
|
-
headers: {
|
|
647
|
-
'X-UC-User-Agent': getUserAgent({ publicKey: publicKey, integration: integration, userAgent: userAgent })
|
|
648
|
-
},
|
|
649
|
-
url: getUrl(baseURL, '/info/', {
|
|
650
|
-
jsonerrors: 1,
|
|
651
|
-
pub_key: publicKey,
|
|
652
|
-
file_id: uuid,
|
|
653
|
-
source: source
|
|
654
|
-
}),
|
|
655
|
-
signal: signal
|
|
656
|
-
}).then(function (_a) {
|
|
657
|
-
var data = _a.data, headers = _a.headers, request = _a.request;
|
|
658
|
-
var response = camelizeKeys(JSON.parse(data));
|
|
659
|
-
if ('error' in response) {
|
|
660
|
-
throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
|
|
661
|
-
}
|
|
662
|
-
else {
|
|
663
|
-
return response;
|
|
664
|
-
}
|
|
665
|
-
});
|
|
666
|
-
}, retryThrottledRequestMaxTimes);
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
/**
|
|
670
|
-
* Start multipart uploading.
|
|
671
|
-
*/
|
|
672
|
-
function multipartStart(size, _a) {
|
|
673
|
-
var publicKey = _a.publicKey, contentType = _a.contentType, fileName = _a.fileName, _b = _a.multipartChunkSize, multipartChunkSize = _b === void 0 ? defaultSettings.multipartChunkSize : _b, _c = _a.baseURL, baseURL = _c === void 0 ? '' : _c, secureSignature = _a.secureSignature, secureExpire = _a.secureExpire, store = _a.store, signal = _a.signal, _d = _a.source, source = _d === void 0 ? 'local' : _d, integration = _a.integration, userAgent = _a.userAgent, _e = _a.retryThrottledRequestMaxTimes, retryThrottledRequestMaxTimes = _e === void 0 ? defaultSettings.retryThrottledRequestMaxTimes : _e, metadata = _a.metadata;
|
|
674
|
-
return retryIfThrottled(function () {
|
|
675
|
-
return request({
|
|
676
|
-
method: 'POST',
|
|
677
|
-
url: getUrl(baseURL, '/multipart/start/', { jsonerrors: 1 }),
|
|
678
|
-
headers: {
|
|
679
|
-
'X-UC-User-Agent': getUserAgent({ publicKey: publicKey, integration: integration, userAgent: userAgent })
|
|
680
|
-
},
|
|
681
|
-
data: buildFormData({
|
|
682
|
-
filename: fileName !== null && fileName !== void 0 ? fileName : defaultFilename,
|
|
683
|
-
size: size,
|
|
684
|
-
content_type: contentType !== null && contentType !== void 0 ? contentType : defaultContentType,
|
|
685
|
-
part_size: multipartChunkSize,
|
|
686
|
-
UPLOADCARE_STORE: getStoreValue(store),
|
|
687
|
-
UPLOADCARE_PUB_KEY: publicKey,
|
|
688
|
-
signature: secureSignature,
|
|
689
|
-
expire: secureExpire,
|
|
690
|
-
source: source,
|
|
691
|
-
metadata: metadata
|
|
692
|
-
}),
|
|
693
|
-
signal: signal
|
|
694
|
-
}).then(function (_a) {
|
|
695
|
-
var data = _a.data, headers = _a.headers, request = _a.request;
|
|
696
|
-
var response = camelizeKeys(JSON.parse(data));
|
|
697
|
-
if ('error' in response) {
|
|
698
|
-
throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
|
|
699
|
-
}
|
|
700
|
-
else {
|
|
701
|
-
// convert to array
|
|
702
|
-
response.parts = Object.keys(response.parts).map(function (key) { return response.parts[key]; });
|
|
703
|
-
return response;
|
|
704
|
-
}
|
|
705
|
-
});
|
|
706
|
-
}, retryThrottledRequestMaxTimes);
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
/**
|
|
710
|
-
* Complete multipart uploading.
|
|
711
|
-
*/
|
|
712
|
-
function multipartUpload(part, url, _a) {
|
|
713
|
-
var signal = _a.signal, onProgress = _a.onProgress;
|
|
714
|
-
return request({
|
|
715
|
-
method: 'PUT',
|
|
716
|
-
url: url,
|
|
717
|
-
data: part,
|
|
718
|
-
// Upload request can't be non-computable because we always know exact size
|
|
719
|
-
onProgress: onProgress,
|
|
720
|
-
signal: signal
|
|
721
|
-
})
|
|
722
|
-
.then(function (result) {
|
|
723
|
-
// hack for node ¯\_(ツ)_/¯
|
|
724
|
-
if (onProgress)
|
|
725
|
-
onProgress({
|
|
726
|
-
isComputable: true,
|
|
727
|
-
value: 1
|
|
728
|
-
});
|
|
729
|
-
return result;
|
|
730
|
-
})
|
|
731
|
-
.then(function (_a) {
|
|
732
|
-
var status = _a.status;
|
|
733
|
-
return ({ code: status });
|
|
734
|
-
});
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
/**
|
|
738
|
-
* Complete multipart uploading.
|
|
739
|
-
*/
|
|
740
|
-
function multipartComplete(uuid, _a) {
|
|
741
|
-
var publicKey = _a.publicKey, _b = _a.baseURL, baseURL = _b === void 0 ? defaultSettings.baseURL : _b, _c = _a.source, source = _c === void 0 ? 'local' : _c, signal = _a.signal, integration = _a.integration, userAgent = _a.userAgent, _d = _a.retryThrottledRequestMaxTimes, retryThrottledRequestMaxTimes = _d === void 0 ? defaultSettings.retryThrottledRequestMaxTimes : _d;
|
|
742
|
-
return retryIfThrottled(function () {
|
|
743
|
-
return request({
|
|
744
|
-
method: 'POST',
|
|
745
|
-
url: getUrl(baseURL, '/multipart/complete/', { jsonerrors: 1 }),
|
|
746
|
-
headers: {
|
|
747
|
-
'X-UC-User-Agent': getUserAgent({ publicKey: publicKey, integration: integration, userAgent: userAgent })
|
|
748
|
-
},
|
|
749
|
-
data: buildFormData({
|
|
750
|
-
uuid: uuid,
|
|
751
|
-
UPLOADCARE_PUB_KEY: publicKey,
|
|
752
|
-
source: source
|
|
753
|
-
}),
|
|
754
|
-
signal: signal
|
|
755
|
-
}).then(function (_a) {
|
|
756
|
-
var data = _a.data, headers = _a.headers, request = _a.request;
|
|
757
|
-
var response = camelizeKeys(JSON.parse(data));
|
|
758
|
-
if ('error' in response) {
|
|
759
|
-
throw new UploadClientError(response.error.content, response.error.errorCode, request, response, headers);
|
|
760
|
-
}
|
|
761
|
-
else {
|
|
762
|
-
return response;
|
|
763
|
-
}
|
|
764
|
-
});
|
|
765
|
-
}, retryThrottledRequestMaxTimes);
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
var UploadcareFile = /** @class */ (function () {
|
|
769
|
-
function UploadcareFile(fileInfo, _a) {
|
|
770
|
-
var baseCDN = _a.baseCDN, defaultEffects = _a.defaultEffects, fileName = _a.fileName;
|
|
771
|
-
this.name = null;
|
|
772
|
-
this.size = null;
|
|
773
|
-
this.isStored = null;
|
|
774
|
-
this.isImage = null;
|
|
775
|
-
this.mimeType = null;
|
|
776
|
-
this.cdnUrl = null;
|
|
777
|
-
this.cdnUrlModifiers = null;
|
|
778
|
-
this.originalUrl = null;
|
|
779
|
-
this.originalFilename = null;
|
|
780
|
-
this.imageInfo = null;
|
|
781
|
-
this.videoInfo = null;
|
|
782
|
-
this.contentInfo = null;
|
|
783
|
-
this.metadata = null;
|
|
784
|
-
var uuid = fileInfo.uuid, s3Bucket = fileInfo.s3Bucket;
|
|
785
|
-
var urlBase = s3Bucket
|
|
786
|
-
? "https://" + s3Bucket + ".s3.amazonaws.com/" + uuid + "/" + fileInfo.filename
|
|
787
|
-
: baseCDN + "/" + uuid + "/";
|
|
788
|
-
var cdnUrlModifiers = defaultEffects ? "-/" + defaultEffects : null;
|
|
789
|
-
var cdnUrl = "" + urlBase + (cdnUrlModifiers || '');
|
|
790
|
-
var originalUrl = uuid ? urlBase : null;
|
|
791
|
-
this.uuid = uuid;
|
|
792
|
-
this.name = fileName || fileInfo.filename;
|
|
793
|
-
this.size = fileInfo.size;
|
|
794
|
-
this.isStored = fileInfo.isStored;
|
|
795
|
-
this.isImage = fileInfo.isImage;
|
|
796
|
-
this.mimeType = fileInfo.mimeType;
|
|
797
|
-
this.cdnUrl = cdnUrl;
|
|
798
|
-
this.cdnUrlModifiers = cdnUrlModifiers;
|
|
799
|
-
this.originalUrl = originalUrl;
|
|
800
|
-
this.originalFilename = fileInfo.originalFilename;
|
|
801
|
-
this.imageInfo = camelizeKeys(fileInfo.imageInfo);
|
|
802
|
-
this.videoInfo = camelizeKeys(fileInfo.videoInfo);
|
|
803
|
-
this.contentInfo = camelizeKeys(fileInfo.contentInfo);
|
|
804
|
-
this.metadata = fileInfo.metadata || null;
|
|
805
|
-
}
|
|
806
|
-
return UploadcareFile;
|
|
807
|
-
}());
|
|
808
|
-
|
|
809
|
-
var DEFAULT_INTERVAL = 500;
|
|
810
|
-
var poll = function (_a) {
|
|
811
|
-
var check = _a.check, _b = _a.interval, interval = _b === void 0 ? DEFAULT_INTERVAL : _b, signal = _a.signal;
|
|
812
|
-
return new Promise(function (resolve, reject) {
|
|
813
|
-
var timeoutId;
|
|
814
|
-
onCancel(signal, function () {
|
|
815
|
-
timeoutId && clearTimeout(timeoutId);
|
|
816
|
-
reject(cancelError('Poll cancelled'));
|
|
817
|
-
});
|
|
818
|
-
var tick = function () {
|
|
819
|
-
try {
|
|
820
|
-
Promise.resolve(check(signal))
|
|
821
|
-
.then(function (result) {
|
|
822
|
-
if (result) {
|
|
823
|
-
resolve(result);
|
|
824
|
-
}
|
|
825
|
-
else {
|
|
826
|
-
timeoutId = setTimeout(tick, interval);
|
|
827
|
-
}
|
|
828
|
-
})
|
|
829
|
-
.catch(function (error) { return reject(error); });
|
|
830
|
-
}
|
|
831
|
-
catch (error) {
|
|
832
|
-
reject(error);
|
|
833
|
-
}
|
|
834
|
-
};
|
|
835
|
-
timeoutId = setTimeout(tick, 0);
|
|
836
|
-
});
|
|
837
|
-
};
|
|
838
|
-
|
|
839
|
-
function isReadyPoll(_a) {
|
|
840
|
-
var file = _a.file, publicKey = _a.publicKey, baseURL = _a.baseURL, source = _a.source, integration = _a.integration, userAgent = _a.userAgent, retryThrottledRequestMaxTimes = _a.retryThrottledRequestMaxTimes, signal = _a.signal, onProgress = _a.onProgress;
|
|
841
|
-
return poll({
|
|
842
|
-
check: function (signal) {
|
|
843
|
-
return info(file, {
|
|
844
|
-
publicKey: publicKey,
|
|
845
|
-
baseURL: baseURL,
|
|
846
|
-
signal: signal,
|
|
847
|
-
source: source,
|
|
848
|
-
integration: integration,
|
|
849
|
-
userAgent: userAgent,
|
|
850
|
-
retryThrottledRequestMaxTimes: retryThrottledRequestMaxTimes
|
|
851
|
-
}).then(function (response) {
|
|
852
|
-
if (response.isReady) {
|
|
853
|
-
return response;
|
|
854
|
-
}
|
|
855
|
-
onProgress && onProgress({ isComputable: true, value: 1 });
|
|
856
|
-
return false;
|
|
857
|
-
});
|
|
858
|
-
},
|
|
859
|
-
signal: signal
|
|
860
|
-
});
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
var uploadFromObject = function (file, _a) {
|
|
864
|
-
var publicKey = _a.publicKey, fileName = _a.fileName, baseURL = _a.baseURL, secureSignature = _a.secureSignature, secureExpire = _a.secureExpire, store = _a.store, contentType = _a.contentType, signal = _a.signal, onProgress = _a.onProgress, source = _a.source, integration = _a.integration, userAgent = _a.userAgent, retryThrottledRequestMaxTimes = _a.retryThrottledRequestMaxTimes, baseCDN = _a.baseCDN, metadata = _a.metadata;
|
|
865
|
-
return base(file, {
|
|
866
|
-
publicKey: publicKey,
|
|
867
|
-
fileName: fileName,
|
|
868
|
-
contentType: contentType,
|
|
869
|
-
baseURL: baseURL,
|
|
870
|
-
secureSignature: secureSignature,
|
|
871
|
-
secureExpire: secureExpire,
|
|
872
|
-
store: store,
|
|
873
|
-
signal: signal,
|
|
874
|
-
onProgress: onProgress,
|
|
875
|
-
source: source,
|
|
876
|
-
integration: integration,
|
|
877
|
-
userAgent: userAgent,
|
|
878
|
-
retryThrottledRequestMaxTimes: retryThrottledRequestMaxTimes,
|
|
879
|
-
metadata: metadata
|
|
880
|
-
})
|
|
881
|
-
.then(function (_a) {
|
|
882
|
-
var file = _a.file;
|
|
883
|
-
return isReadyPoll({
|
|
884
|
-
file: file,
|
|
885
|
-
publicKey: publicKey,
|
|
886
|
-
baseURL: baseURL,
|
|
887
|
-
source: source,
|
|
888
|
-
integration: integration,
|
|
889
|
-
userAgent: userAgent,
|
|
890
|
-
retryThrottledRequestMaxTimes: retryThrottledRequestMaxTimes,
|
|
891
|
-
onProgress: onProgress,
|
|
892
|
-
signal: signal
|
|
893
|
-
});
|
|
894
|
-
})
|
|
895
|
-
.then(function (fileInfo) { return new UploadcareFile(fileInfo, { baseCDN: baseCDN }); });
|
|
896
|
-
};
|
|
897
|
-
|
|
898
|
-
/*globals self, window */
|
|
899
|
-
|
|
900
|
-
/*eslint-disable @mysticatea/prettier */
|
|
901
|
-
const { AbortController, AbortSignal } =
|
|
902
|
-
typeof self !== "undefined" ? self :
|
|
903
|
-
typeof window !== "undefined" ? window :
|
|
904
|
-
/* otherwise */ undefined;
|
|
905
|
-
|
|
906
|
-
var race = function (fns, _a) {
|
|
907
|
-
var signal = (_a === void 0 ? {} : _a).signal;
|
|
908
|
-
var lastError = null;
|
|
909
|
-
var winnerIndex = null;
|
|
910
|
-
var controllers = fns.map(function () { return new AbortController(); });
|
|
911
|
-
var createStopRaceCallback = function (i) { return function () {
|
|
912
|
-
winnerIndex = i;
|
|
913
|
-
controllers.forEach(function (controller, index) { return index !== i && controller.abort(); });
|
|
914
|
-
}; };
|
|
915
|
-
onCancel(signal, function () {
|
|
916
|
-
controllers.forEach(function (controller) { return controller.abort(); });
|
|
917
|
-
});
|
|
918
|
-
return Promise.all(fns.map(function (fn, i) {
|
|
919
|
-
var stopRace = createStopRaceCallback(i);
|
|
920
|
-
return Promise.resolve()
|
|
921
|
-
.then(function () { return fn({ stopRace: stopRace, signal: controllers[i].signal }); })
|
|
922
|
-
.then(function (result) {
|
|
923
|
-
stopRace();
|
|
924
|
-
return result;
|
|
925
|
-
})
|
|
926
|
-
.catch(function (error) {
|
|
927
|
-
lastError = error;
|
|
928
|
-
return null;
|
|
929
|
-
});
|
|
930
|
-
})).then(function (results) {
|
|
931
|
-
if (winnerIndex === null) {
|
|
932
|
-
throw lastError;
|
|
933
|
-
}
|
|
934
|
-
else {
|
|
935
|
-
return results[winnerIndex];
|
|
936
|
-
}
|
|
937
|
-
});
|
|
938
|
-
};
|
|
939
|
-
|
|
940
|
-
var WebSocket = window.WebSocket;
|
|
941
|
-
|
|
942
|
-
var Events = /** @class */ (function () {
|
|
943
|
-
function Events() {
|
|
944
|
-
this.events = Object.create({});
|
|
945
|
-
}
|
|
946
|
-
Events.prototype.emit = function (event, data) {
|
|
947
|
-
var _a;
|
|
948
|
-
(_a = this.events[event]) === null || _a === void 0 ? void 0 : _a.forEach(function (fn) { return fn(data); });
|
|
949
|
-
};
|
|
950
|
-
Events.prototype.on = function (event, callback) {
|
|
951
|
-
this.events[event] = this.events[event] || [];
|
|
952
|
-
this.events[event].push(callback);
|
|
953
|
-
};
|
|
954
|
-
Events.prototype.off = function (event, callback) {
|
|
955
|
-
if (callback) {
|
|
956
|
-
this.events[event] = this.events[event].filter(function (fn) { return fn !== callback; });
|
|
957
|
-
}
|
|
958
|
-
else {
|
|
959
|
-
this.events[event] = [];
|
|
960
|
-
}
|
|
961
|
-
};
|
|
962
|
-
return Events;
|
|
963
|
-
}());
|
|
964
|
-
|
|
965
|
-
var response = function (type, data) {
|
|
966
|
-
if (type === 'success') {
|
|
967
|
-
return __assign({ status: Status.Success }, data);
|
|
968
|
-
}
|
|
969
|
-
if (type === 'progress') {
|
|
970
|
-
return __assign({ status: Status.Progress }, data);
|
|
971
|
-
}
|
|
972
|
-
return __assign({ status: Status.Error }, data);
|
|
973
|
-
};
|
|
974
|
-
var Pusher = /** @class */ (function () {
|
|
975
|
-
function Pusher(pusherKey, disconnectTime) {
|
|
976
|
-
if (disconnectTime === void 0) { disconnectTime = 30000; }
|
|
977
|
-
this.ws = undefined;
|
|
978
|
-
this.queue = [];
|
|
979
|
-
this.isConnected = false;
|
|
980
|
-
this.subscribers = 0;
|
|
981
|
-
this.emmitter = new Events();
|
|
982
|
-
this.disconnectTimeoutId = null;
|
|
983
|
-
this.key = pusherKey;
|
|
984
|
-
this.disconnectTime = disconnectTime;
|
|
985
|
-
}
|
|
986
|
-
Pusher.prototype.connect = function () {
|
|
987
|
-
var _this = this;
|
|
988
|
-
this.disconnectTimeoutId && clearTimeout(this.disconnectTimeoutId);
|
|
989
|
-
if (!this.isConnected && !this.ws) {
|
|
990
|
-
var pusherUrl = "wss://ws.pusherapp.com/app/" + this.key + "?protocol=5&client=js&version=1.12.2";
|
|
991
|
-
this.ws = new WebSocket(pusherUrl);
|
|
992
|
-
this.ws.addEventListener('error', function (error) {
|
|
993
|
-
_this.emmitter.emit('error', new Error(error.message));
|
|
994
|
-
});
|
|
995
|
-
this.emmitter.on('connected', function () {
|
|
996
|
-
_this.isConnected = true;
|
|
997
|
-
_this.queue.forEach(function (message) { return _this.send(message.event, message.data); });
|
|
998
|
-
_this.queue = [];
|
|
999
|
-
});
|
|
1000
|
-
this.ws.addEventListener('message', function (e) {
|
|
1001
|
-
var data = JSON.parse(e.data.toString());
|
|
1002
|
-
switch (data.event) {
|
|
1003
|
-
case 'pusher:connection_established': {
|
|
1004
|
-
_this.emmitter.emit('connected', undefined);
|
|
1005
|
-
break;
|
|
1006
|
-
}
|
|
1007
|
-
case 'pusher:ping': {
|
|
1008
|
-
_this.send('pusher:pong', {});
|
|
1009
|
-
break;
|
|
1010
|
-
}
|
|
1011
|
-
case 'progress':
|
|
1012
|
-
case 'success':
|
|
1013
|
-
case 'fail': {
|
|
1014
|
-
_this.emmitter.emit(data.channel, response(data.event, JSON.parse(data.data)));
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
});
|
|
1018
|
-
}
|
|
1019
|
-
};
|
|
1020
|
-
Pusher.prototype.disconnect = function () {
|
|
1021
|
-
var _this = this;
|
|
1022
|
-
var actualDisconect = function () {
|
|
1023
|
-
var _a;
|
|
1024
|
-
(_a = _this.ws) === null || _a === void 0 ? void 0 : _a.close();
|
|
1025
|
-
_this.ws = undefined;
|
|
1026
|
-
_this.isConnected = false;
|
|
1027
|
-
};
|
|
1028
|
-
if (this.disconnectTime) {
|
|
1029
|
-
this.disconnectTimeoutId = setTimeout(function () {
|
|
1030
|
-
actualDisconect();
|
|
1031
|
-
}, this.disconnectTime);
|
|
1032
|
-
}
|
|
1033
|
-
else {
|
|
1034
|
-
actualDisconect();
|
|
1035
|
-
}
|
|
1036
|
-
};
|
|
1037
|
-
Pusher.prototype.send = function (event, data) {
|
|
1038
|
-
var _a;
|
|
1039
|
-
var str = JSON.stringify({ event: event, data: data });
|
|
1040
|
-
(_a = this.ws) === null || _a === void 0 ? void 0 : _a.send(str);
|
|
1041
|
-
};
|
|
1042
|
-
Pusher.prototype.subscribe = function (token, handler) {
|
|
1043
|
-
this.subscribers += 1;
|
|
1044
|
-
this.connect();
|
|
1045
|
-
var channel = "task-status-" + token;
|
|
1046
|
-
var message = {
|
|
1047
|
-
event: 'pusher:subscribe',
|
|
1048
|
-
data: { channel: channel }
|
|
1049
|
-
};
|
|
1050
|
-
this.emmitter.on(channel, handler);
|
|
1051
|
-
if (this.isConnected) {
|
|
1052
|
-
this.send(message.event, message.data);
|
|
1053
|
-
}
|
|
1054
|
-
else {
|
|
1055
|
-
this.queue.push(message);
|
|
1056
|
-
}
|
|
1057
|
-
};
|
|
1058
|
-
Pusher.prototype.unsubscribe = function (token) {
|
|
1059
|
-
this.subscribers -= 1;
|
|
1060
|
-
var channel = "task-status-" + token;
|
|
1061
|
-
var message = {
|
|
1062
|
-
event: 'pusher:unsubscribe',
|
|
1063
|
-
data: { channel: channel }
|
|
1064
|
-
};
|
|
1065
|
-
this.emmitter.off(channel);
|
|
1066
|
-
if (this.isConnected) {
|
|
1067
|
-
this.send(message.event, message.data);
|
|
1068
|
-
}
|
|
1069
|
-
else {
|
|
1070
|
-
this.queue = this.queue.filter(function (msg) { return msg.data.channel !== channel; });
|
|
1071
|
-
}
|
|
1072
|
-
if (this.subscribers === 0) {
|
|
1073
|
-
this.disconnect();
|
|
1074
|
-
}
|
|
1075
|
-
};
|
|
1076
|
-
Pusher.prototype.onError = function (callback) {
|
|
1077
|
-
var _this = this;
|
|
1078
|
-
this.emmitter.on('error', callback);
|
|
1079
|
-
return function () { return _this.emmitter.off('error', callback); };
|
|
1080
|
-
};
|
|
1081
|
-
return Pusher;
|
|
1082
|
-
}());
|
|
1083
|
-
var pusher = null;
|
|
1084
|
-
var getPusher = function (key) {
|
|
1085
|
-
if (!pusher) {
|
|
1086
|
-
// no timeout for nodeJS and 30000 ms for browser
|
|
1087
|
-
var disconectTimeout = typeof window === 'undefined' ? 0 : 30000;
|
|
1088
|
-
pusher = new Pusher(key, disconectTimeout);
|
|
1089
|
-
}
|
|
1090
|
-
return pusher;
|
|
1091
|
-
};
|
|
1092
|
-
var preconnect = function (key) {
|
|
1093
|
-
getPusher(key).connect();
|
|
1094
|
-
};
|
|
1095
|
-
|
|
1096
|
-
function pollStrategy(_a) {
|
|
1097
|
-
var token = _a.token, publicKey = _a.publicKey, baseURL = _a.baseURL, integration = _a.integration, userAgent = _a.userAgent, retryThrottledRequestMaxTimes = _a.retryThrottledRequestMaxTimes, onProgress = _a.onProgress, signal = _a.signal;
|
|
1098
|
-
return poll({
|
|
1099
|
-
check: function (signal) {
|
|
1100
|
-
return fromUrlStatus(token, {
|
|
1101
|
-
publicKey: publicKey,
|
|
1102
|
-
baseURL: baseURL,
|
|
1103
|
-
integration: integration,
|
|
1104
|
-
userAgent: userAgent,
|
|
1105
|
-
retryThrottledRequestMaxTimes: retryThrottledRequestMaxTimes,
|
|
1106
|
-
signal: signal
|
|
1107
|
-
}).then(function (response) {
|
|
1108
|
-
switch (response.status) {
|
|
1109
|
-
case Status.Error: {
|
|
1110
|
-
return new UploadClientError(response.error, response.errorCode);
|
|
1111
|
-
}
|
|
1112
|
-
case Status.Waiting: {
|
|
1113
|
-
return false;
|
|
1114
|
-
}
|
|
1115
|
-
case Status.Unknown: {
|
|
1116
|
-
return new UploadClientError("Token \"" + token + "\" was not found.");
|
|
1117
|
-
}
|
|
1118
|
-
case Status.Progress: {
|
|
1119
|
-
if (onProgress) {
|
|
1120
|
-
if (response.total === 'unknown') {
|
|
1121
|
-
onProgress({ isComputable: false });
|
|
1122
|
-
}
|
|
1123
|
-
else {
|
|
1124
|
-
onProgress({
|
|
1125
|
-
isComputable: true,
|
|
1126
|
-
value: response.done / response.total
|
|
1127
|
-
});
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
return false;
|
|
1131
|
-
}
|
|
1132
|
-
case Status.Success: {
|
|
1133
|
-
if (onProgress)
|
|
1134
|
-
onProgress({
|
|
1135
|
-
isComputable: true,
|
|
1136
|
-
value: response.done / response.total
|
|
1137
|
-
});
|
|
1138
|
-
return response;
|
|
1139
|
-
}
|
|
1140
|
-
default: {
|
|
1141
|
-
throw new Error('Unknown status');
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
});
|
|
1145
|
-
},
|
|
1146
|
-
signal: signal
|
|
1147
|
-
});
|
|
1148
|
-
}
|
|
1149
|
-
var pushStrategy = function (_a) {
|
|
1150
|
-
var token = _a.token, pusherKey = _a.pusherKey, signal = _a.signal, onProgress = _a.onProgress;
|
|
1151
|
-
return new Promise(function (resolve, reject) {
|
|
1152
|
-
var pusher = getPusher(pusherKey);
|
|
1153
|
-
var unsubErrorHandler = pusher.onError(reject);
|
|
1154
|
-
var destroy = function () {
|
|
1155
|
-
unsubErrorHandler();
|
|
1156
|
-
pusher.unsubscribe(token);
|
|
1157
|
-
};
|
|
1158
|
-
onCancel(signal, function () {
|
|
1159
|
-
destroy();
|
|
1160
|
-
reject(cancelError('pusher cancelled'));
|
|
1161
|
-
});
|
|
1162
|
-
pusher.subscribe(token, function (result) {
|
|
1163
|
-
switch (result.status) {
|
|
1164
|
-
case Status.Progress: {
|
|
1165
|
-
if (onProgress) {
|
|
1166
|
-
if (result.total === 'unknown') {
|
|
1167
|
-
onProgress({ isComputable: false });
|
|
1168
|
-
}
|
|
1169
|
-
else {
|
|
1170
|
-
onProgress({
|
|
1171
|
-
isComputable: true,
|
|
1172
|
-
value: result.done / result.total
|
|
1173
|
-
});
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
break;
|
|
1177
|
-
}
|
|
1178
|
-
case Status.Success: {
|
|
1179
|
-
destroy();
|
|
1180
|
-
if (onProgress)
|
|
1181
|
-
onProgress({
|
|
1182
|
-
isComputable: true,
|
|
1183
|
-
value: result.done / result.total
|
|
1184
|
-
});
|
|
1185
|
-
resolve(result);
|
|
1186
|
-
break;
|
|
1187
|
-
}
|
|
1188
|
-
case Status.Error: {
|
|
1189
|
-
destroy();
|
|
1190
|
-
reject(new UploadClientError(result.msg, result.error_code));
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
});
|
|
1194
|
-
});
|
|
1195
|
-
};
|
|
1196
|
-
var uploadFromUrl = function (sourceUrl, _a) {
|
|
1197
|
-
var publicKey = _a.publicKey, fileName = _a.fileName, baseURL = _a.baseURL, baseCDN = _a.baseCDN, checkForUrlDuplicates = _a.checkForUrlDuplicates, saveUrlForRecurrentUploads = _a.saveUrlForRecurrentUploads, 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, _b = _a.pusherKey, pusherKey = _b === void 0 ? defaultSettings.pusherKey : _b, metadata = _a.metadata;
|
|
1198
|
-
return Promise.resolve(preconnect(pusherKey))
|
|
1199
|
-
.then(function () {
|
|
1200
|
-
return fromUrl(sourceUrl, {
|
|
1201
|
-
publicKey: publicKey,
|
|
1202
|
-
fileName: fileName,
|
|
1203
|
-
baseURL: baseURL,
|
|
1204
|
-
checkForUrlDuplicates: checkForUrlDuplicates,
|
|
1205
|
-
saveUrlForRecurrentUploads: saveUrlForRecurrentUploads,
|
|
1206
|
-
secureSignature: secureSignature,
|
|
1207
|
-
secureExpire: secureExpire,
|
|
1208
|
-
store: store,
|
|
1209
|
-
signal: signal,
|
|
1210
|
-
source: source,
|
|
1211
|
-
integration: integration,
|
|
1212
|
-
userAgent: userAgent,
|
|
1213
|
-
retryThrottledRequestMaxTimes: retryThrottledRequestMaxTimes,
|
|
1214
|
-
metadata: metadata
|
|
1215
|
-
});
|
|
1216
|
-
})
|
|
1217
|
-
.catch(function (error) {
|
|
1218
|
-
var pusher = getPusher(pusherKey);
|
|
1219
|
-
pusher === null || pusher === void 0 ? void 0 : pusher.disconnect();
|
|
1220
|
-
return Promise.reject(error);
|
|
1221
|
-
})
|
|
1222
|
-
.then(function (urlResponse) {
|
|
1223
|
-
if (urlResponse.type === TypeEnum.FileInfo) {
|
|
1224
|
-
return urlResponse;
|
|
1225
|
-
}
|
|
1226
|
-
else {
|
|
1227
|
-
return race([
|
|
1228
|
-
function (_a) {
|
|
1229
|
-
var signal = _a.signal;
|
|
1230
|
-
return pollStrategy({
|
|
1231
|
-
token: urlResponse.token,
|
|
1232
|
-
publicKey: publicKey,
|
|
1233
|
-
baseURL: baseURL,
|
|
1234
|
-
integration: integration,
|
|
1235
|
-
userAgent: userAgent,
|
|
1236
|
-
retryThrottledRequestMaxTimes: retryThrottledRequestMaxTimes,
|
|
1237
|
-
onProgress: onProgress,
|
|
1238
|
-
signal: signal
|
|
1239
|
-
});
|
|
1240
|
-
},
|
|
1241
|
-
function (_a) {
|
|
1242
|
-
var signal = _a.signal;
|
|
1243
|
-
return pushStrategy({
|
|
1244
|
-
token: urlResponse.token,
|
|
1245
|
-
pusherKey: pusherKey,
|
|
1246
|
-
signal: signal,
|
|
1247
|
-
onProgress: onProgress
|
|
1248
|
-
});
|
|
1249
|
-
}
|
|
1250
|
-
], { signal: signal });
|
|
1251
|
-
}
|
|
1252
|
-
})
|
|
1253
|
-
.then(function (result) {
|
|
1254
|
-
if (result instanceof UploadClientError)
|
|
1255
|
-
throw result;
|
|
1256
|
-
return result;
|
|
1257
|
-
})
|
|
1258
|
-
.then(function (result) {
|
|
1259
|
-
return isReadyPoll({
|
|
1260
|
-
file: result.uuid,
|
|
1261
|
-
publicKey: publicKey,
|
|
1262
|
-
baseURL: baseURL,
|
|
1263
|
-
integration: integration,
|
|
1264
|
-
userAgent: userAgent,
|
|
1265
|
-
retryThrottledRequestMaxTimes: retryThrottledRequestMaxTimes,
|
|
1266
|
-
onProgress: onProgress,
|
|
1267
|
-
signal: signal
|
|
1268
|
-
});
|
|
1269
|
-
})
|
|
1270
|
-
.then(function (fileInfo) { return new UploadcareFile(fileInfo, { baseCDN: baseCDN }); });
|
|
1271
|
-
};
|
|
1272
|
-
|
|
1273
|
-
var uploadFromUploaded = function (uuid, _a) {
|
|
1274
|
-
var publicKey = _a.publicKey, fileName = _a.fileName, baseURL = _a.baseURL, signal = _a.signal, onProgress = _a.onProgress, source = _a.source, integration = _a.integration, userAgent = _a.userAgent, retryThrottledRequestMaxTimes = _a.retryThrottledRequestMaxTimes, baseCDN = _a.baseCDN;
|
|
1275
|
-
return info(uuid, {
|
|
1276
|
-
publicKey: publicKey,
|
|
1277
|
-
baseURL: baseURL,
|
|
1278
|
-
signal: signal,
|
|
1279
|
-
source: source,
|
|
1280
|
-
integration: integration,
|
|
1281
|
-
userAgent: userAgent,
|
|
1282
|
-
retryThrottledRequestMaxTimes: retryThrottledRequestMaxTimes
|
|
1283
|
-
})
|
|
1284
|
-
.then(function (fileInfo) { return new UploadcareFile(fileInfo, { baseCDN: baseCDN, fileName: fileName }); })
|
|
1285
|
-
.then(function (result) {
|
|
1286
|
-
// hack for node ¯\_(ツ)_/¯
|
|
1287
|
-
if (onProgress)
|
|
1288
|
-
onProgress({
|
|
1289
|
-
isComputable: true,
|
|
1290
|
-
value: 1
|
|
1291
|
-
});
|
|
1292
|
-
return result;
|
|
1293
|
-
});
|
|
1294
|
-
};
|
|
1295
|
-
|
|
1296
|
-
/**
|
|
1297
|
-
* Get file size.
|
|
1298
|
-
*/
|
|
1299
|
-
var getFileSize = function (file) {
|
|
1300
|
-
return file.length || file.size;
|
|
1301
|
-
};
|
|
1302
|
-
/**
|
|
1303
|
-
* Check if FileData is multipart data.
|
|
1304
|
-
*/
|
|
1305
|
-
var isMultipart = function (fileSize, multipartMinFileSize) {
|
|
1306
|
-
if (multipartMinFileSize === void 0) { multipartMinFileSize = defaultSettings.multipartMinFileSize; }
|
|
1307
|
-
return fileSize >= multipartMinFileSize;
|
|
1308
|
-
};
|
|
1309
|
-
|
|
1310
|
-
var sliceChunk = function (file, index, fileSize, chunkSize) {
|
|
1311
|
-
var start = chunkSize * index;
|
|
1312
|
-
var end = Math.min(start + chunkSize, fileSize);
|
|
1313
|
-
return file.slice(start, end);
|
|
1314
|
-
};
|
|
1315
|
-
|
|
1316
|
-
function prepareChunks(file, fileSize, chunkSize) {
|
|
1317
|
-
return function (index) {
|
|
1318
|
-
return sliceChunk(file, index, fileSize, chunkSize);
|
|
1319
|
-
};
|
|
1320
|
-
}
|
|
1321
|
-
|
|
1322
|
-
var runWithConcurrency = function (concurrency, tasks) {
|
|
1323
|
-
return new Promise(function (resolve, reject) {
|
|
1324
|
-
var results = [];
|
|
1325
|
-
var rejected = false;
|
|
1326
|
-
var settled = tasks.length;
|
|
1327
|
-
var forRun = __spreadArrays(tasks);
|
|
1328
|
-
var run = function () {
|
|
1329
|
-
var index = tasks.length - forRun.length;
|
|
1330
|
-
var next = forRun.shift();
|
|
1331
|
-
if (next) {
|
|
1332
|
-
next()
|
|
1333
|
-
.then(function (result) {
|
|
1334
|
-
if (rejected)
|
|
1335
|
-
return;
|
|
1336
|
-
results[index] = result;
|
|
1337
|
-
settled -= 1;
|
|
1338
|
-
if (settled) {
|
|
1339
|
-
run();
|
|
1340
|
-
}
|
|
1341
|
-
else {
|
|
1342
|
-
resolve(results);
|
|
1343
|
-
}
|
|
1344
|
-
})
|
|
1345
|
-
.catch(function (error) {
|
|
1346
|
-
rejected = true;
|
|
1347
|
-
reject(error);
|
|
1348
|
-
});
|
|
1349
|
-
}
|
|
1350
|
-
};
|
|
1351
|
-
for (var i = 0; i < concurrency; i++) {
|
|
1352
|
-
run();
|
|
1353
|
-
}
|
|
1354
|
-
});
|
|
1355
|
-
};
|
|
1356
|
-
|
|
1357
|
-
var uploadPartWithRetry = function (chunk, url, _a) {
|
|
1358
|
-
var publicKey = _a.publicKey, onProgress = _a.onProgress, signal = _a.signal, integration = _a.integration, multipartMaxAttempts = _a.multipartMaxAttempts;
|
|
1359
|
-
return retrier(function (_a) {
|
|
1360
|
-
var attempt = _a.attempt, retry = _a.retry;
|
|
1361
|
-
return multipartUpload(chunk, url, {
|
|
1362
|
-
publicKey: publicKey,
|
|
1363
|
-
onProgress: onProgress,
|
|
1364
|
-
signal: signal,
|
|
1365
|
-
integration: integration
|
|
1366
|
-
}).catch(function (error) {
|
|
1367
|
-
if (attempt < multipartMaxAttempts) {
|
|
1368
|
-
return retry();
|
|
1369
|
-
}
|
|
1370
|
-
throw error;
|
|
1371
|
-
});
|
|
1372
|
-
});
|
|
1373
|
-
};
|
|
1374
|
-
var uploadMultipart = function (file, _a) {
|
|
1375
|
-
var publicKey = _a.publicKey, fileName = _a.fileName, fileSize = _a.fileSize, baseURL = _a.baseURL, 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, _b = _a.multipartChunkSize, multipartChunkSize = _b === void 0 ? defaultSettings.multipartChunkSize : _b, _c = _a.maxConcurrentRequests, maxConcurrentRequests = _c === void 0 ? defaultSettings.maxConcurrentRequests : _c, _d = _a.multipartMaxAttempts, multipartMaxAttempts = _d === void 0 ? defaultSettings.multipartMaxAttempts : _d, baseCDN = _a.baseCDN, metadata = _a.metadata;
|
|
1376
|
-
var size = fileSize || getFileSize(file);
|
|
1377
|
-
var progressValues;
|
|
1378
|
-
var createProgressHandler = function (totalChunks, chunkIdx) {
|
|
1379
|
-
if (!onProgress)
|
|
1380
|
-
return;
|
|
1381
|
-
if (!progressValues) {
|
|
1382
|
-
progressValues = Array(totalChunks).fill(0);
|
|
1383
|
-
}
|
|
1384
|
-
var sum = function (values) {
|
|
1385
|
-
return values.reduce(function (sum, next) { return sum + next; }, 0);
|
|
1386
|
-
};
|
|
1387
|
-
return function (info) {
|
|
1388
|
-
if (!info.isComputable) {
|
|
1389
|
-
return;
|
|
1390
|
-
}
|
|
1391
|
-
progressValues[chunkIdx] = info.value;
|
|
1392
|
-
onProgress({
|
|
1393
|
-
isComputable: true,
|
|
1394
|
-
value: sum(progressValues) / totalChunks
|
|
1395
|
-
});
|
|
1396
|
-
};
|
|
1397
|
-
};
|
|
1398
|
-
return multipartStart(size, {
|
|
1399
|
-
publicKey: publicKey,
|
|
1400
|
-
contentType: contentType,
|
|
1401
|
-
fileName: fileName !== null && fileName !== void 0 ? fileName : file.name,
|
|
1402
|
-
baseURL: baseURL,
|
|
1403
|
-
secureSignature: secureSignature,
|
|
1404
|
-
secureExpire: secureExpire,
|
|
1405
|
-
store: store,
|
|
1406
|
-
signal: signal,
|
|
1407
|
-
source: source,
|
|
1408
|
-
integration: integration,
|
|
1409
|
-
userAgent: userAgent,
|
|
1410
|
-
retryThrottledRequestMaxTimes: retryThrottledRequestMaxTimes,
|
|
1411
|
-
metadata: metadata
|
|
1412
|
-
})
|
|
1413
|
-
.then(function (_a) {
|
|
1414
|
-
var uuid = _a.uuid, parts = _a.parts;
|
|
1415
|
-
var getChunk = prepareChunks(file, size, multipartChunkSize);
|
|
1416
|
-
return Promise.all([
|
|
1417
|
-
uuid,
|
|
1418
|
-
runWithConcurrency(maxConcurrentRequests, parts.map(function (url, index) { return function () {
|
|
1419
|
-
return uploadPartWithRetry(getChunk(index), url, {
|
|
1420
|
-
publicKey: publicKey,
|
|
1421
|
-
onProgress: createProgressHandler(parts.length, index),
|
|
1422
|
-
signal: signal,
|
|
1423
|
-
integration: integration,
|
|
1424
|
-
multipartMaxAttempts: multipartMaxAttempts
|
|
1425
|
-
});
|
|
1426
|
-
}; }))
|
|
1427
|
-
]);
|
|
1428
|
-
})
|
|
1429
|
-
.then(function (_a) {
|
|
1430
|
-
var uuid = _a[0];
|
|
1431
|
-
return multipartComplete(uuid, {
|
|
1432
|
-
publicKey: publicKey,
|
|
1433
|
-
baseURL: baseURL,
|
|
1434
|
-
source: source,
|
|
1435
|
-
integration: integration,
|
|
1436
|
-
userAgent: userAgent,
|
|
1437
|
-
retryThrottledRequestMaxTimes: retryThrottledRequestMaxTimes
|
|
1438
|
-
});
|
|
1439
|
-
})
|
|
1440
|
-
.then(function (fileInfo) {
|
|
1441
|
-
if (fileInfo.isReady) {
|
|
1442
|
-
return fileInfo;
|
|
1443
|
-
}
|
|
1444
|
-
else {
|
|
1445
|
-
return isReadyPoll({
|
|
1446
|
-
file: fileInfo.uuid,
|
|
1447
|
-
publicKey: publicKey,
|
|
1448
|
-
baseURL: baseURL,
|
|
1449
|
-
source: source,
|
|
1450
|
-
integration: integration,
|
|
1451
|
-
userAgent: userAgent,
|
|
1452
|
-
retryThrottledRequestMaxTimes: retryThrottledRequestMaxTimes,
|
|
1453
|
-
onProgress: onProgress,
|
|
1454
|
-
signal: signal
|
|
1455
|
-
});
|
|
1456
|
-
}
|
|
1457
|
-
})
|
|
1458
|
-
.then(function (fileInfo) { return new UploadcareFile(fileInfo, { baseCDN: baseCDN }); });
|
|
1459
|
-
};
|
|
1460
|
-
|
|
1461
|
-
/**
|
|
1462
|
-
* Uploads file from provided data.
|
|
1463
|
-
*/
|
|
1464
|
-
function uploadFile(data, _a) {
|
|
1465
|
-
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, multipartMinFileSize = _a.multipartMinFileSize, 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, metadata = _a.metadata;
|
|
1466
|
-
if (isFileData(data)) {
|
|
1467
|
-
var fileSize = getFileSize(data);
|
|
1468
|
-
if (isMultipart(fileSize, multipartMinFileSize)) {
|
|
1469
|
-
return uploadMultipart(data, {
|
|
1470
|
-
publicKey: publicKey,
|
|
1471
|
-
contentType: contentType,
|
|
1472
|
-
multipartChunkSize: multipartChunkSize,
|
|
1473
|
-
multipartMaxAttempts: multipartMaxAttempts,
|
|
1474
|
-
fileName: fileName,
|
|
1475
|
-
baseURL: baseURL,
|
|
1476
|
-
secureSignature: secureSignature,
|
|
1477
|
-
secureExpire: secureExpire,
|
|
1478
|
-
store: store,
|
|
1479
|
-
signal: signal,
|
|
1480
|
-
onProgress: onProgress,
|
|
1481
|
-
source: source,
|
|
1482
|
-
integration: integration,
|
|
1483
|
-
userAgent: userAgent,
|
|
1484
|
-
maxConcurrentRequests: maxConcurrentRequests,
|
|
1485
|
-
retryThrottledRequestMaxTimes: retryThrottledRequestMaxTimes,
|
|
1486
|
-
baseCDN: baseCDN,
|
|
1487
|
-
metadata: metadata
|
|
1488
|
-
});
|
|
1489
|
-
}
|
|
1490
|
-
return uploadFromObject(data, {
|
|
1491
|
-
publicKey: publicKey,
|
|
1492
|
-
fileName: fileName,
|
|
1493
|
-
contentType: contentType,
|
|
1494
|
-
baseURL: baseURL,
|
|
1495
|
-
secureSignature: secureSignature,
|
|
1496
|
-
secureExpire: secureExpire,
|
|
1497
|
-
store: store,
|
|
1498
|
-
signal: signal,
|
|
1499
|
-
onProgress: onProgress,
|
|
1500
|
-
source: source,
|
|
1501
|
-
integration: integration,
|
|
1502
|
-
userAgent: userAgent,
|
|
1503
|
-
retryThrottledRequestMaxTimes: retryThrottledRequestMaxTimes,
|
|
1504
|
-
baseCDN: baseCDN,
|
|
1505
|
-
metadata: metadata
|
|
1506
|
-
});
|
|
1507
|
-
}
|
|
1508
|
-
if (isUrl(data)) {
|
|
1509
|
-
return uploadFromUrl(data, {
|
|
1510
|
-
publicKey: publicKey,
|
|
1511
|
-
fileName: fileName,
|
|
1512
|
-
baseURL: baseURL,
|
|
1513
|
-
baseCDN: baseCDN,
|
|
1514
|
-
checkForUrlDuplicates: checkForUrlDuplicates,
|
|
1515
|
-
saveUrlForRecurrentUploads: saveUrlForRecurrentUploads,
|
|
1516
|
-
secureSignature: secureSignature,
|
|
1517
|
-
secureExpire: secureExpire,
|
|
1518
|
-
store: store,
|
|
1519
|
-
signal: signal,
|
|
1520
|
-
onProgress: onProgress,
|
|
1521
|
-
source: source,
|
|
1522
|
-
integration: integration,
|
|
1523
|
-
userAgent: userAgent,
|
|
1524
|
-
retryThrottledRequestMaxTimes: retryThrottledRequestMaxTimes,
|
|
1525
|
-
pusherKey: pusherKey,
|
|
1526
|
-
metadata: metadata
|
|
1527
|
-
});
|
|
1528
|
-
}
|
|
1529
|
-
if (isUuid(data)) {
|
|
1530
|
-
return uploadFromUploaded(data, {
|
|
1531
|
-
publicKey: publicKey,
|
|
1532
|
-
fileName: fileName,
|
|
1533
|
-
baseURL: baseURL,
|
|
1534
|
-
signal: signal,
|
|
1535
|
-
onProgress: onProgress,
|
|
1536
|
-
source: source,
|
|
1537
|
-
integration: integration,
|
|
1538
|
-
userAgent: userAgent,
|
|
1539
|
-
retryThrottledRequestMaxTimes: retryThrottledRequestMaxTimes,
|
|
1540
|
-
baseCDN: baseCDN
|
|
1541
|
-
});
|
|
1542
|
-
}
|
|
1543
|
-
throw new TypeError("File uploading from \"" + data + "\" is not supported");
|
|
1544
|
-
}
|
|
1545
|
-
|
|
1546
|
-
var UploadcareGroup = /** @class */ (function () {
|
|
1547
|
-
function UploadcareGroup(groupInfo, files) {
|
|
1548
|
-
this.storedAt = null;
|
|
1549
|
-
this.uuid = groupInfo.id;
|
|
1550
|
-
this.filesCount = groupInfo.filesCount;
|
|
1551
|
-
this.totalSize = Object.values(groupInfo.files).reduce(function (acc, file) { return acc + file.size; }, 0);
|
|
1552
|
-
this.isStored = !!groupInfo.datetimeStored;
|
|
1553
|
-
this.isImage = !!Object.values(groupInfo.files).filter(function (file) { return file.isImage; }).length;
|
|
1554
|
-
this.cdnUrl = groupInfo.cdnUrl;
|
|
1555
|
-
this.files = files;
|
|
1556
|
-
this.createdAt = groupInfo.datetimeCreated;
|
|
1557
|
-
this.storedAt = groupInfo.datetimeStored;
|
|
1558
|
-
}
|
|
1559
|
-
return UploadcareGroup;
|
|
1560
|
-
}());
|
|
1561
|
-
|
|
1562
|
-
/**
|
|
1563
|
-
* FileData type guard.
|
|
1564
|
-
*/
|
|
1565
|
-
var isFileDataArray = function (data) {
|
|
1566
|
-
for (var _i = 0, data_1 = data; _i < data_1.length; _i++) {
|
|
1567
|
-
var item = data_1[_i];
|
|
1568
|
-
if (!isFileData(item)) {
|
|
1569
|
-
return false;
|
|
1570
|
-
}
|
|
1571
|
-
}
|
|
1572
|
-
return true;
|
|
1573
|
-
};
|
|
1574
|
-
/**
|
|
1575
|
-
* Uuid type guard.
|
|
1576
|
-
*/
|
|
1577
|
-
var isUuidArray = function (data) {
|
|
1578
|
-
for (var _i = 0, data_2 = data; _i < data_2.length; _i++) {
|
|
1579
|
-
var item = data_2[_i];
|
|
1580
|
-
if (!isUuid(item)) {
|
|
1581
|
-
return false;
|
|
1582
|
-
}
|
|
1583
|
-
}
|
|
1584
|
-
return true;
|
|
1585
|
-
};
|
|
1586
|
-
/**
|
|
1587
|
-
* Url type guard.
|
|
1588
|
-
*/
|
|
1589
|
-
var isUrlArray = function (data) {
|
|
1590
|
-
for (var _i = 0, data_3 = data; _i < data_3.length; _i++) {
|
|
1591
|
-
var item = data_3[_i];
|
|
1592
|
-
if (!isUrl(item)) {
|
|
1593
|
-
return false;
|
|
1594
|
-
}
|
|
1595
|
-
}
|
|
1596
|
-
return true;
|
|
1597
|
-
};
|
|
1598
|
-
|
|
1599
|
-
function uploadFileGroup(data, _a) {
|
|
1600
|
-
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, _c = _a.multipartChunkSize, multipartChunkSize = _c === void 0 ? defaultSettings.multipartChunkSize : _c, _d = _a.baseCDN, baseCDN = _d === void 0 ? defaultSettings.baseCDN : _d, jsonpCallback = _a.jsonpCallback, defaultEffects = _a.defaultEffects;
|
|
1601
|
-
if (!isFileDataArray(data) && !isUrlArray(data) && !isUuidArray(data)) {
|
|
1602
|
-
throw new TypeError("Group uploading from \"" + data + "\" is not supported");
|
|
1603
|
-
}
|
|
1604
|
-
var progressValues;
|
|
1605
|
-
var isStillComputable = true;
|
|
1606
|
-
var filesCount = data.length;
|
|
1607
|
-
var createProgressHandler = function (size, index) {
|
|
1608
|
-
if (!onProgress)
|
|
1609
|
-
return;
|
|
1610
|
-
if (!progressValues) {
|
|
1611
|
-
progressValues = Array(size).fill(0);
|
|
1612
|
-
}
|
|
1613
|
-
var normalize = function (values) {
|
|
1614
|
-
return values.reduce(function (sum, next) { return sum + next; }) / size;
|
|
1615
|
-
};
|
|
1616
|
-
return function (info) {
|
|
1617
|
-
if (!info.isComputable || !isStillComputable) {
|
|
1618
|
-
isStillComputable = false;
|
|
1619
|
-
onProgress({ isComputable: false });
|
|
1620
|
-
return;
|
|
1621
|
-
}
|
|
1622
|
-
progressValues[index] = info.value;
|
|
1623
|
-
onProgress({ isComputable: true, value: normalize(progressValues) });
|
|
1624
|
-
};
|
|
1625
|
-
};
|
|
1626
|
-
return Promise.all(data.map(function (file, index) {
|
|
1627
|
-
return uploadFile(file, {
|
|
1628
|
-
publicKey: publicKey,
|
|
1629
|
-
fileName: fileName,
|
|
1630
|
-
baseURL: baseURL,
|
|
1631
|
-
secureSignature: secureSignature,
|
|
1632
|
-
secureExpire: secureExpire,
|
|
1633
|
-
store: store,
|
|
1634
|
-
signal: signal,
|
|
1635
|
-
onProgress: createProgressHandler(filesCount, index),
|
|
1636
|
-
source: source,
|
|
1637
|
-
integration: integration,
|
|
1638
|
-
userAgent: userAgent,
|
|
1639
|
-
retryThrottledRequestMaxTimes: retryThrottledRequestMaxTimes,
|
|
1640
|
-
contentType: contentType,
|
|
1641
|
-
multipartChunkSize: multipartChunkSize,
|
|
1642
|
-
baseCDN: baseCDN
|
|
1643
|
-
});
|
|
1644
|
-
})).then(function (files) {
|
|
1645
|
-
var uuids = files.map(function (file) { return file.uuid; });
|
|
1646
|
-
var addDefaultEffects = function (file) {
|
|
1647
|
-
var cdnUrlModifiers = defaultEffects ? "-/" + defaultEffects : null;
|
|
1648
|
-
var cdnUrl = "" + file.urlBase + (cdnUrlModifiers || '');
|
|
1649
|
-
return __assign(__assign({}, file), { cdnUrlModifiers: cdnUrlModifiers,
|
|
1650
|
-
cdnUrl: cdnUrl });
|
|
1651
|
-
};
|
|
1652
|
-
var filesInGroup = defaultEffects ? files.map(addDefaultEffects) : files;
|
|
1653
|
-
return group(uuids, {
|
|
1654
|
-
publicKey: publicKey,
|
|
1655
|
-
baseURL: baseURL,
|
|
1656
|
-
jsonpCallback: jsonpCallback,
|
|
1657
|
-
secureSignature: secureSignature,
|
|
1658
|
-
secureExpire: secureExpire,
|
|
1659
|
-
signal: signal,
|
|
1660
|
-
source: source,
|
|
1661
|
-
integration: integration,
|
|
1662
|
-
userAgent: userAgent,
|
|
1663
|
-
retryThrottledRequestMaxTimes: retryThrottledRequestMaxTimes
|
|
1664
|
-
})
|
|
1665
|
-
.then(function (groupInfo) { return new UploadcareGroup(groupInfo, filesInGroup); })
|
|
1666
|
-
.then(function (group) {
|
|
1667
|
-
onProgress && onProgress({ isComputable: true, value: 1 });
|
|
1668
|
-
return group;
|
|
1669
|
-
});
|
|
1670
|
-
});
|
|
1671
|
-
}
|
|
1672
|
-
|
|
1673
|
-
/**
|
|
1674
|
-
* Populate options with settings.
|
|
1675
|
-
*/
|
|
1676
|
-
var populateOptionsWithSettings = function (options, settings) { return (__assign(__assign({}, settings), options)); };
|
|
1677
|
-
var UploadClient = /** @class */ (function () {
|
|
1678
|
-
function UploadClient(settings) {
|
|
1679
|
-
this.settings = Object.assign({}, defaultSettings, settings);
|
|
1680
|
-
}
|
|
1681
|
-
UploadClient.prototype.updateSettings = function (newSettings) {
|
|
1682
|
-
this.settings = Object.assign(this.settings, newSettings);
|
|
1683
|
-
};
|
|
1684
|
-
UploadClient.prototype.getSettings = function () {
|
|
1685
|
-
return this.settings;
|
|
1686
|
-
};
|
|
1687
|
-
UploadClient.prototype.base = function (file, options) {
|
|
1688
|
-
var settings = this.getSettings();
|
|
1689
|
-
return base(file, populateOptionsWithSettings(options, settings));
|
|
1690
|
-
};
|
|
1691
|
-
UploadClient.prototype.info = function (uuid, options) {
|
|
1692
|
-
var settings = this.getSettings();
|
|
1693
|
-
return info(uuid, populateOptionsWithSettings(options, settings));
|
|
1694
|
-
};
|
|
1695
|
-
UploadClient.prototype.fromUrl = function (sourceUrl, options) {
|
|
1696
|
-
var settings = this.getSettings();
|
|
1697
|
-
return fromUrl(sourceUrl, populateOptionsWithSettings(options, settings));
|
|
1698
|
-
};
|
|
1699
|
-
UploadClient.prototype.fromUrlStatus = function (token, options) {
|
|
1700
|
-
var settings = this.getSettings();
|
|
1701
|
-
return fromUrlStatus(token, populateOptionsWithSettings(options, settings));
|
|
1702
|
-
};
|
|
1703
|
-
UploadClient.prototype.group = function (uuids, options) {
|
|
1704
|
-
var settings = this.getSettings();
|
|
1705
|
-
return group(uuids, populateOptionsWithSettings(options, settings));
|
|
1706
|
-
};
|
|
1707
|
-
UploadClient.prototype.groupInfo = function (id, options) {
|
|
1708
|
-
var settings = this.getSettings();
|
|
1709
|
-
return groupInfo(id, populateOptionsWithSettings(options, settings));
|
|
1710
|
-
};
|
|
1711
|
-
UploadClient.prototype.multipartStart = function (size, options) {
|
|
1712
|
-
var settings = this.getSettings();
|
|
1713
|
-
return multipartStart(size, populateOptionsWithSettings(options, settings));
|
|
1714
|
-
};
|
|
1715
|
-
UploadClient.prototype.multipartUpload = function (part, url, options) {
|
|
1716
|
-
var settings = this.getSettings();
|
|
1717
|
-
return multipartUpload(part, url, populateOptionsWithSettings(options, settings));
|
|
1718
|
-
};
|
|
1719
|
-
UploadClient.prototype.multipartComplete = function (uuid, options) {
|
|
1720
|
-
var settings = this.getSettings();
|
|
1721
|
-
return multipartComplete(uuid, populateOptionsWithSettings(options, settings));
|
|
1722
|
-
};
|
|
1723
|
-
UploadClient.prototype.uploadFile = function (data, options) {
|
|
1724
|
-
var settings = this.getSettings();
|
|
1725
|
-
return uploadFile(data, populateOptionsWithSettings(options, settings));
|
|
1726
|
-
};
|
|
1727
|
-
UploadClient.prototype.uploadFileGroup = function (data, options) {
|
|
1728
|
-
var settings = this.getSettings();
|
|
1729
|
-
return uploadFileGroup(data, populateOptionsWithSettings(options, settings));
|
|
1730
|
-
};
|
|
1731
|
-
return UploadClient;
|
|
1732
|
-
}());
|
|
1733
|
-
|
|
1734
|
-
exports.AbortController = AbortController;
|
|
1735
|
-
exports.UploadClient = UploadClient;
|
|
1736
|
-
exports.UploadClientError = UploadClientError;
|
|
1737
|
-
exports.UploadcareFile = UploadcareFile;
|
|
1738
|
-
exports.UploadcareGroup = UploadcareGroup;
|
|
1739
|
-
exports.base = base;
|
|
1740
|
-
exports.fromUrl = fromUrl;
|
|
1741
|
-
exports.fromUrlStatus = fromUrlStatus;
|
|
1742
|
-
exports.group = group;
|
|
1743
|
-
exports.groupInfo = groupInfo;
|
|
1744
|
-
exports.info = info;
|
|
1745
|
-
exports.multipartComplete = multipartComplete;
|
|
1746
|
-
exports.multipartStart = multipartStart;
|
|
1747
|
-
exports.multipartUpload = multipartUpload;
|
|
1748
|
-
exports.uploadBase = uploadFromObject;
|
|
1749
|
-
exports.uploadFile = uploadFile;
|
|
1750
|
-
exports.uploadFileGroup = uploadFileGroup;
|
|
1751
|
-
exports.uploadFromUploaded = uploadFromUploaded;
|
|
1752
|
-
exports.uploadFromUrl = uploadFromUrl;
|
|
1753
|
-
exports.uploadMultipart = uploadMultipart;
|