@firebase/storage 0.13.2 → 0.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.cjs.js +806 -975
- package/dist/index.browser.cjs.js.map +1 -1
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm2017.js +2 -2
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.node.cjs.js +3 -5
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/node-esm/index.node.esm.js +3 -5
- package/dist/node-esm/index.node.esm.js.map +1 -1
- package/dist/node-esm/src/platform/node/connection.d.ts +1 -3
- package/dist/src/platform/node/connection.d.ts +1 -3
- package/package.json +9 -9
- package/dist/index.esm5.js +0 -3810
- package/dist/index.esm5.js.map +0 -1
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var app = require('@firebase/app');
|
|
6
|
-
var tslib = require('tslib');
|
|
7
6
|
var util = require('@firebase/util');
|
|
8
7
|
var component = require('@firebase/component');
|
|
9
8
|
|
|
@@ -29,27 +28,27 @@ var component = require('@firebase/component');
|
|
|
29
28
|
/**
|
|
30
29
|
* Domain name for firebase storage.
|
|
31
30
|
*/
|
|
32
|
-
|
|
31
|
+
const DEFAULT_HOST = 'firebasestorage.googleapis.com';
|
|
33
32
|
/**
|
|
34
33
|
* The key in Firebase config json for the storage bucket.
|
|
35
34
|
*/
|
|
36
|
-
|
|
35
|
+
const CONFIG_STORAGE_BUCKET_KEY = 'storageBucket';
|
|
37
36
|
/**
|
|
38
37
|
* 2 minutes
|
|
39
38
|
*
|
|
40
39
|
* The timeout for all operations except upload.
|
|
41
40
|
*/
|
|
42
|
-
|
|
41
|
+
const DEFAULT_MAX_OPERATION_RETRY_TIME = 2 * 60 * 1000;
|
|
43
42
|
/**
|
|
44
43
|
* 10 minutes
|
|
45
44
|
*
|
|
46
45
|
* The timeout for upload.
|
|
47
46
|
*/
|
|
48
|
-
|
|
47
|
+
const DEFAULT_MAX_UPLOAD_RETRY_TIME = 10 * 60 * 1000;
|
|
49
48
|
/**
|
|
50
49
|
* 1 second
|
|
51
50
|
*/
|
|
52
|
-
|
|
51
|
+
const DEFAULT_MIN_SLEEP_TIME_MILLIS = 1000;
|
|
53
52
|
|
|
54
53
|
/**
|
|
55
54
|
* @license
|
|
@@ -71,65 +70,53 @@ var DEFAULT_MIN_SLEEP_TIME_MILLIS = 1000;
|
|
|
71
70
|
* An error returned by the Firebase Storage SDK.
|
|
72
71
|
* @public
|
|
73
72
|
*/
|
|
74
|
-
|
|
75
|
-
tslib.__extends(StorageError, _super);
|
|
73
|
+
class StorageError extends util.FirebaseError {
|
|
76
74
|
/**
|
|
77
75
|
* @param code - A `StorageErrorCode` string to be prefixed with 'storage/' and
|
|
78
76
|
* added to the end of the message.
|
|
79
77
|
* @param message - Error message.
|
|
80
78
|
* @param status_ - Corresponding HTTP Status Code
|
|
81
79
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
_this.status_ = status_;
|
|
80
|
+
constructor(code, message, status_ = 0) {
|
|
81
|
+
super(prependCode(code), `Firebase Storage: ${message} (${prependCode(code)})`);
|
|
82
|
+
this.status_ = status_;
|
|
86
83
|
/**
|
|
87
84
|
* Stores custom error data unique to the `StorageError`.
|
|
88
85
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
this.customData = { serverResponse: null };
|
|
87
|
+
this._baseMessage = this.message;
|
|
91
88
|
// Without this, `instanceof StorageError`, in tests for example,
|
|
92
89
|
// returns false.
|
|
93
|
-
Object.setPrototypeOf(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
this.status_ = status;
|
|
102
|
-
},
|
|
103
|
-
enumerable: false,
|
|
104
|
-
configurable: true
|
|
105
|
-
});
|
|
90
|
+
Object.setPrototypeOf(this, StorageError.prototype);
|
|
91
|
+
}
|
|
92
|
+
get status() {
|
|
93
|
+
return this.status_;
|
|
94
|
+
}
|
|
95
|
+
set status(status) {
|
|
96
|
+
this.status_ = status;
|
|
97
|
+
}
|
|
106
98
|
/**
|
|
107
99
|
* Compares a `StorageErrorCode` against this error's code, filtering out the prefix.
|
|
108
100
|
*/
|
|
109
|
-
|
|
101
|
+
_codeEquals(code) {
|
|
110
102
|
return prependCode(code) === this.code;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
enumerable: false,
|
|
129
|
-
configurable: true
|
|
130
|
-
});
|
|
131
|
-
return StorageError;
|
|
132
|
-
}(util.FirebaseError));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Optional response message that was added by the server.
|
|
106
|
+
*/
|
|
107
|
+
get serverResponse() {
|
|
108
|
+
return this.customData.serverResponse;
|
|
109
|
+
}
|
|
110
|
+
set serverResponse(serverResponse) {
|
|
111
|
+
this.customData.serverResponse = serverResponse;
|
|
112
|
+
if (this.customData.serverResponse) {
|
|
113
|
+
this.message = `${this._baseMessage}\n${this.customData.serverResponse}`;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
this.message = this._baseMessage;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
133
120
|
/**
|
|
134
121
|
* @public
|
|
135
122
|
* Error codes that can be attached to `StorageError` objects.
|
|
@@ -168,7 +155,7 @@ function prependCode(code) {
|
|
|
168
155
|
return 'storage/' + code;
|
|
169
156
|
}
|
|
170
157
|
function unknown() {
|
|
171
|
-
|
|
158
|
+
const message = 'An unknown error occurred, please check the error payload for ' +
|
|
172
159
|
'server response.';
|
|
173
160
|
return new StorageError(exports.StorageErrorCode.UNKNOWN, message);
|
|
174
161
|
}
|
|
@@ -182,7 +169,7 @@ function quotaExceeded(bucket) {
|
|
|
182
169
|
'https://firebase.google.com/pricing/.');
|
|
183
170
|
}
|
|
184
171
|
function unauthenticated() {
|
|
185
|
-
|
|
172
|
+
const message = 'User is not authenticated, please authenticate using Firebase ' +
|
|
186
173
|
'Authentication and try again.';
|
|
187
174
|
return new StorageError(exports.StorageErrorCode.UNAUTHENTICATED, message);
|
|
188
175
|
}
|
|
@@ -220,7 +207,7 @@ function noDownloadURL() {
|
|
|
220
207
|
return new StorageError(exports.StorageErrorCode.NO_DOWNLOAD_URL, 'The given file does not have any download URLs.');
|
|
221
208
|
}
|
|
222
209
|
function missingPolyFill(polyFill) {
|
|
223
|
-
return new StorageError(exports.StorageErrorCode.UNSUPPORTED_ENVIRONMENT,
|
|
210
|
+
return new StorageError(exports.StorageErrorCode.UNSUPPORTED_ENVIRONMENT, `${polyFill} is missing. Make sure to install the required polyfills. See https://firebase.google.com/docs/web/environments-js-sdk#polyfills for more information.`);
|
|
224
211
|
}
|
|
225
212
|
/**
|
|
226
213
|
* @internal
|
|
@@ -277,35 +264,27 @@ function internalError(message) {
|
|
|
277
264
|
*
|
|
278
265
|
* @internal
|
|
279
266
|
*/
|
|
280
|
-
|
|
281
|
-
|
|
267
|
+
class Location {
|
|
268
|
+
constructor(bucket, path) {
|
|
282
269
|
this.bucket = bucket;
|
|
283
270
|
this.path_ = path;
|
|
284
271
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
get: function () {
|
|
294
|
-
return this.path.length === 0;
|
|
295
|
-
},
|
|
296
|
-
enumerable: false,
|
|
297
|
-
configurable: true
|
|
298
|
-
});
|
|
299
|
-
Location.prototype.fullServerUrl = function () {
|
|
300
|
-
var encode = encodeURIComponent;
|
|
272
|
+
get path() {
|
|
273
|
+
return this.path_;
|
|
274
|
+
}
|
|
275
|
+
get isRoot() {
|
|
276
|
+
return this.path.length === 0;
|
|
277
|
+
}
|
|
278
|
+
fullServerUrl() {
|
|
279
|
+
const encode = encodeURIComponent;
|
|
301
280
|
return '/b/' + encode(this.bucket) + '/o/' + encode(this.path);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
|
|
281
|
+
}
|
|
282
|
+
bucketOnlyServerUrl() {
|
|
283
|
+
const encode = encodeURIComponent;
|
|
305
284
|
return '/b/' + encode(this.bucket) + '/o';
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
|
|
285
|
+
}
|
|
286
|
+
static makeFromBucketSpec(bucketString, host) {
|
|
287
|
+
let bucketLocation;
|
|
309
288
|
try {
|
|
310
289
|
bucketLocation = Location.makeFromUrl(bucketString, host);
|
|
311
290
|
}
|
|
@@ -320,33 +299,33 @@ var Location = /** @class */ (function () {
|
|
|
320
299
|
else {
|
|
321
300
|
throw invalidDefaultBucket(bucketString);
|
|
322
301
|
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
302
|
+
}
|
|
303
|
+
static makeFromUrl(url, host) {
|
|
304
|
+
let location = null;
|
|
305
|
+
const bucketDomain = '([A-Za-z0-9.\\-_]+)';
|
|
327
306
|
function gsModify(loc) {
|
|
328
307
|
if (loc.path.charAt(loc.path.length - 1) === '/') {
|
|
329
308
|
loc.path_ = loc.path_.slice(0, -1);
|
|
330
309
|
}
|
|
331
310
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
311
|
+
const gsPath = '(/(.*))?$';
|
|
312
|
+
const gsRegex = new RegExp('^gs://' + bucketDomain + gsPath, 'i');
|
|
313
|
+
const gsIndices = { bucket: 1, path: 3 };
|
|
335
314
|
function httpModify(loc) {
|
|
336
315
|
loc.path_ = decodeURIComponent(loc.path);
|
|
337
316
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
317
|
+
const version = 'v[A-Za-z0-9_]+';
|
|
318
|
+
const firebaseStorageHost = host.replace(/[.]/g, '\\.');
|
|
319
|
+
const firebaseStoragePath = '(/([^?#]*).*)?$';
|
|
320
|
+
const firebaseStorageRegExp = new RegExp(`^https?://${firebaseStorageHost}/${version}/b/${bucketDomain}/o${firebaseStoragePath}`, 'i');
|
|
321
|
+
const firebaseStorageIndices = { bucket: 1, path: 3 };
|
|
322
|
+
const cloudStorageHost = host === DEFAULT_HOST
|
|
344
323
|
? '(?:storage.googleapis.com|storage.cloud.google.com)'
|
|
345
324
|
: host;
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
325
|
+
const cloudStoragePath = '([^?#]*)';
|
|
326
|
+
const cloudStorageRegExp = new RegExp(`^https?://${cloudStorageHost}/${bucketDomain}/${cloudStoragePath}`, 'i');
|
|
327
|
+
const cloudStorageIndices = { bucket: 1, path: 2 };
|
|
328
|
+
const groups = [
|
|
350
329
|
{ regex: gsRegex, indices: gsIndices, postModify: gsModify },
|
|
351
330
|
{
|
|
352
331
|
regex: firebaseStorageRegExp,
|
|
@@ -359,12 +338,12 @@ var Location = /** @class */ (function () {
|
|
|
359
338
|
postModify: httpModify
|
|
360
339
|
}
|
|
361
340
|
];
|
|
362
|
-
for (
|
|
363
|
-
|
|
364
|
-
|
|
341
|
+
for (let i = 0; i < groups.length; i++) {
|
|
342
|
+
const group = groups[i];
|
|
343
|
+
const captures = group.regex.exec(url);
|
|
365
344
|
if (captures) {
|
|
366
|
-
|
|
367
|
-
|
|
345
|
+
const bucketValue = captures[group.indices.bucket];
|
|
346
|
+
let pathValue = captures[group.indices.path];
|
|
368
347
|
if (!pathValue) {
|
|
369
348
|
pathValue = '';
|
|
370
349
|
}
|
|
@@ -377,26 +356,23 @@ var Location = /** @class */ (function () {
|
|
|
377
356
|
throw invalidUrl(url);
|
|
378
357
|
}
|
|
379
358
|
return location;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
}());
|
|
359
|
+
}
|
|
360
|
+
}
|
|
383
361
|
|
|
384
362
|
/**
|
|
385
363
|
* A request whose promise always fails.
|
|
386
364
|
*/
|
|
387
|
-
|
|
388
|
-
|
|
365
|
+
class FailRequest {
|
|
366
|
+
constructor(error) {
|
|
389
367
|
this.promise_ = Promise.reject(error);
|
|
390
368
|
}
|
|
391
369
|
/** @inheritDoc */
|
|
392
|
-
|
|
370
|
+
getPromise() {
|
|
393
371
|
return this.promise_;
|
|
394
|
-
}
|
|
372
|
+
}
|
|
395
373
|
/** @inheritDoc */
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
return FailRequest;
|
|
399
|
-
}());
|
|
374
|
+
cancel(_appDelete = false) { }
|
|
375
|
+
}
|
|
400
376
|
|
|
401
377
|
/**
|
|
402
378
|
* @license
|
|
@@ -431,31 +407,27 @@ function start(doRequest,
|
|
|
431
407
|
backoffCompleteCb, timeout) {
|
|
432
408
|
// TODO(andysoto): make this code cleaner (probably refactor into an actual
|
|
433
409
|
// type instead of a bunch of functions with state shared in the closure)
|
|
434
|
-
|
|
410
|
+
let waitSeconds = 1;
|
|
435
411
|
// Would type this as "number" but that doesn't work for Node so ¯\_(ツ)_/¯
|
|
436
412
|
// TODO: find a way to exclude Node type definition for storage because storage only works in browser
|
|
437
413
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
438
|
-
|
|
414
|
+
let retryTimeoutId = null;
|
|
439
415
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
416
|
+
let globalTimeoutId = null;
|
|
417
|
+
let hitTimeout = false;
|
|
418
|
+
let cancelState = 0;
|
|
443
419
|
function canceled() {
|
|
444
420
|
return cancelState === 2;
|
|
445
421
|
}
|
|
446
|
-
|
|
447
|
-
function triggerCallback() {
|
|
448
|
-
var args = [];
|
|
449
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
450
|
-
args[_i] = arguments[_i];
|
|
451
|
-
}
|
|
422
|
+
let triggeredCallback = false;
|
|
423
|
+
function triggerCallback(...args) {
|
|
452
424
|
if (!triggeredCallback) {
|
|
453
425
|
triggeredCallback = true;
|
|
454
426
|
backoffCompleteCb.apply(null, args);
|
|
455
427
|
}
|
|
456
428
|
}
|
|
457
429
|
function callWithDelay(millis) {
|
|
458
|
-
retryTimeoutId = setTimeout(
|
|
430
|
+
retryTimeoutId = setTimeout(() => {
|
|
459
431
|
retryTimeoutId = null;
|
|
460
432
|
doRequest(responseHandler, canceled());
|
|
461
433
|
}, millis);
|
|
@@ -465,31 +437,27 @@ backoffCompleteCb, timeout) {
|
|
|
465
437
|
clearTimeout(globalTimeoutId);
|
|
466
438
|
}
|
|
467
439
|
}
|
|
468
|
-
function responseHandler(success) {
|
|
469
|
-
var args = [];
|
|
470
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
471
|
-
args[_i - 1] = arguments[_i];
|
|
472
|
-
}
|
|
440
|
+
function responseHandler(success, ...args) {
|
|
473
441
|
if (triggeredCallback) {
|
|
474
442
|
clearGlobalTimeout();
|
|
475
443
|
return;
|
|
476
444
|
}
|
|
477
445
|
if (success) {
|
|
478
446
|
clearGlobalTimeout();
|
|
479
|
-
triggerCallback.call
|
|
447
|
+
triggerCallback.call(null, success, ...args);
|
|
480
448
|
return;
|
|
481
449
|
}
|
|
482
|
-
|
|
450
|
+
const mustStop = canceled() || hitTimeout;
|
|
483
451
|
if (mustStop) {
|
|
484
452
|
clearGlobalTimeout();
|
|
485
|
-
triggerCallback.call
|
|
453
|
+
triggerCallback.call(null, success, ...args);
|
|
486
454
|
return;
|
|
487
455
|
}
|
|
488
456
|
if (waitSeconds < 64) {
|
|
489
457
|
/* TODO(andysoto): don't back off so quickly if we know we're offline. */
|
|
490
458
|
waitSeconds *= 2;
|
|
491
459
|
}
|
|
492
|
-
|
|
460
|
+
let waitMillis;
|
|
493
461
|
if (cancelState === 1) {
|
|
494
462
|
cancelState = 2;
|
|
495
463
|
waitMillis = 0;
|
|
@@ -499,7 +467,7 @@ backoffCompleteCb, timeout) {
|
|
|
499
467
|
}
|
|
500
468
|
callWithDelay(waitMillis);
|
|
501
469
|
}
|
|
502
|
-
|
|
470
|
+
let stopped = false;
|
|
503
471
|
function stop(wasTimeout) {
|
|
504
472
|
if (stopped) {
|
|
505
473
|
return;
|
|
@@ -523,7 +491,7 @@ backoffCompleteCb, timeout) {
|
|
|
523
491
|
}
|
|
524
492
|
}
|
|
525
493
|
callWithDelay(0);
|
|
526
|
-
globalTimeoutId = setTimeout(
|
|
494
|
+
globalTimeoutId = setTimeout(() => {
|
|
527
495
|
hitTimeout = true;
|
|
528
496
|
stop(true);
|
|
529
497
|
}, timeout);
|
|
@@ -577,10 +545,10 @@ function isNativeBlobDefined() {
|
|
|
577
545
|
}
|
|
578
546
|
function validateNumber(argument, minValue, maxValue, value) {
|
|
579
547
|
if (value < minValue) {
|
|
580
|
-
throw invalidArgument(
|
|
548
|
+
throw invalidArgument(`Invalid value for '${argument}'. Expected ${minValue} or greater.`);
|
|
581
549
|
}
|
|
582
550
|
if (value > maxValue) {
|
|
583
|
-
throw invalidArgument(
|
|
551
|
+
throw invalidArgument(`Invalid value for '${argument}'. Expected ${maxValue} or less.`);
|
|
584
552
|
}
|
|
585
553
|
}
|
|
586
554
|
|
|
@@ -601,18 +569,18 @@ function validateNumber(argument, minValue, maxValue, value) {
|
|
|
601
569
|
* limitations under the License.
|
|
602
570
|
*/
|
|
603
571
|
function makeUrl(urlPart, host, protocol) {
|
|
604
|
-
|
|
572
|
+
let origin = host;
|
|
605
573
|
if (protocol == null) {
|
|
606
|
-
origin =
|
|
574
|
+
origin = `https://${host}`;
|
|
607
575
|
}
|
|
608
|
-
return
|
|
576
|
+
return `${protocol}://${origin}/v0${urlPart}`;
|
|
609
577
|
}
|
|
610
578
|
function makeQueryString(params) {
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
for (
|
|
579
|
+
const encode = encodeURIComponent;
|
|
580
|
+
let queryPart = '?';
|
|
581
|
+
for (const key in params) {
|
|
614
582
|
if (params.hasOwnProperty(key)) {
|
|
615
|
-
|
|
583
|
+
const nextPart = encode(key) + '=' + encode(params[key]);
|
|
616
584
|
queryPart = queryPart + nextPart + '&';
|
|
617
585
|
}
|
|
618
586
|
}
|
|
@@ -656,15 +624,15 @@ var ErrorCode;
|
|
|
656
624
|
function isRetryStatusCode(status, additionalRetryCodes) {
|
|
657
625
|
// The codes for which to retry came from this page:
|
|
658
626
|
// https://cloud.google.com/storage/docs/exponential-backoff
|
|
659
|
-
|
|
660
|
-
|
|
627
|
+
const isFiveHundredCode = status >= 500 && status < 600;
|
|
628
|
+
const extraRetryCodes = [
|
|
661
629
|
// Request Timeout: web server didn't receive full request in time.
|
|
662
630
|
408,
|
|
663
631
|
// Too Many Requests: you're getting rate-limited, basically.
|
|
664
632
|
429
|
|
665
633
|
];
|
|
666
|
-
|
|
667
|
-
|
|
634
|
+
const isExtraRetryCode = extraRetryCodes.indexOf(status) !== -1;
|
|
635
|
+
const isAdditionalRetryCode = additionalRetryCodes.indexOf(status) !== -1;
|
|
668
636
|
return isFiveHundredCode || isExtraRetryCode || isAdditionalRetryCode;
|
|
669
637
|
}
|
|
670
638
|
|
|
@@ -692,10 +660,8 @@ function isRetryStatusCode(status, additionalRetryCodes) {
|
|
|
692
660
|
* @param - O the output type used by the rest of the SDK. The conversion
|
|
693
661
|
* happens in the specified `callback_`.
|
|
694
662
|
*/
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
if (retry === void 0) { retry = true; }
|
|
698
|
-
var _this = this;
|
|
663
|
+
class NetworkRequest {
|
|
664
|
+
constructor(url_, method_, headers_, body_, successCodes_, additionalRetryCodes_, callback_, errorCallback_, timeout_, progressCallback_, connectionFactory_, retry = true) {
|
|
699
665
|
this.url_ = url_;
|
|
700
666
|
this.method_ = method_;
|
|
701
667
|
this.headers_ = headers_;
|
|
@@ -712,53 +678,52 @@ var NetworkRequest = /** @class */ (function () {
|
|
|
712
678
|
this.backoffId_ = null;
|
|
713
679
|
this.canceled_ = false;
|
|
714
680
|
this.appDelete_ = false;
|
|
715
|
-
this.promise_ = new Promise(
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
681
|
+
this.promise_ = new Promise((resolve, reject) => {
|
|
682
|
+
this.resolve_ = resolve;
|
|
683
|
+
this.reject_ = reject;
|
|
684
|
+
this.start_();
|
|
719
685
|
});
|
|
720
686
|
}
|
|
721
687
|
/**
|
|
722
688
|
* Actually starts the retry loop.
|
|
723
689
|
*/
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
var doTheRequest = function (backoffCallback, canceled) {
|
|
690
|
+
start_() {
|
|
691
|
+
const doTheRequest = (backoffCallback, canceled) => {
|
|
727
692
|
if (canceled) {
|
|
728
693
|
backoffCallback(false, new RequestEndStatus(false, null, true));
|
|
729
694
|
return;
|
|
730
695
|
}
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
if (
|
|
737
|
-
|
|
696
|
+
const connection = this.connectionFactory_();
|
|
697
|
+
this.pendingConnection_ = connection;
|
|
698
|
+
const progressListener = progressEvent => {
|
|
699
|
+
const loaded = progressEvent.loaded;
|
|
700
|
+
const total = progressEvent.lengthComputable ? progressEvent.total : -1;
|
|
701
|
+
if (this.progressCallback_ !== null) {
|
|
702
|
+
this.progressCallback_(loaded, total);
|
|
738
703
|
}
|
|
739
704
|
};
|
|
740
|
-
if (
|
|
705
|
+
if (this.progressCallback_ !== null) {
|
|
741
706
|
connection.addUploadProgressListener(progressListener);
|
|
742
707
|
}
|
|
743
708
|
// connection.send() never rejects, so we don't need to have a error handler or use catch on the returned promise.
|
|
744
709
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
745
710
|
connection
|
|
746
|
-
.send(
|
|
747
|
-
.then(
|
|
748
|
-
if (
|
|
711
|
+
.send(this.url_, this.method_, this.body_, this.headers_)
|
|
712
|
+
.then(() => {
|
|
713
|
+
if (this.progressCallback_ !== null) {
|
|
749
714
|
connection.removeUploadProgressListener(progressListener);
|
|
750
715
|
}
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
716
|
+
this.pendingConnection_ = null;
|
|
717
|
+
const hitServer = connection.getErrorCode() === ErrorCode.NO_ERROR;
|
|
718
|
+
const status = connection.getStatus();
|
|
754
719
|
if (!hitServer ||
|
|
755
|
-
(isRetryStatusCode(status,
|
|
756
|
-
|
|
757
|
-
|
|
720
|
+
(isRetryStatusCode(status, this.additionalRetryCodes_) &&
|
|
721
|
+
this.retry)) {
|
|
722
|
+
const wasCanceled = connection.getErrorCode() === ErrorCode.ABORT;
|
|
758
723
|
backoffCallback(false, new RequestEndStatus(false, null, wasCanceled));
|
|
759
724
|
return;
|
|
760
725
|
}
|
|
761
|
-
|
|
726
|
+
const successCode = this.successCodes_.indexOf(status) !== -1;
|
|
762
727
|
backoffCallback(true, new RequestEndStatus(successCode, connection));
|
|
763
728
|
});
|
|
764
729
|
};
|
|
@@ -766,13 +731,13 @@ var NetworkRequest = /** @class */ (function () {
|
|
|
766
731
|
* @param requestWentThrough - True if the request eventually went
|
|
767
732
|
* through, false if it hit the retry limit or was canceled.
|
|
768
733
|
*/
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
734
|
+
const backoffDone = (requestWentThrough, status) => {
|
|
735
|
+
const resolve = this.resolve_;
|
|
736
|
+
const reject = this.reject_;
|
|
737
|
+
const connection = status.connection;
|
|
773
738
|
if (status.wasSuccessCode) {
|
|
774
739
|
try {
|
|
775
|
-
|
|
740
|
+
const result = this.callback_(connection, connection.getResponse());
|
|
776
741
|
if (isJustDef(result)) {
|
|
777
742
|
resolve(result);
|
|
778
743
|
}
|
|
@@ -786,10 +751,10 @@ var NetworkRequest = /** @class */ (function () {
|
|
|
786
751
|
}
|
|
787
752
|
else {
|
|
788
753
|
if (connection !== null) {
|
|
789
|
-
|
|
754
|
+
const err = unknown();
|
|
790
755
|
err.serverResponse = connection.getErrorText();
|
|
791
|
-
if (
|
|
792
|
-
reject(
|
|
756
|
+
if (this.errorCallback_) {
|
|
757
|
+
reject(this.errorCallback_(connection, err));
|
|
793
758
|
}
|
|
794
759
|
else {
|
|
795
760
|
reject(err);
|
|
@@ -797,11 +762,11 @@ var NetworkRequest = /** @class */ (function () {
|
|
|
797
762
|
}
|
|
798
763
|
else {
|
|
799
764
|
if (status.canceled) {
|
|
800
|
-
|
|
765
|
+
const err = this.appDelete_ ? appDeleted() : canceled();
|
|
801
766
|
reject(err);
|
|
802
767
|
}
|
|
803
768
|
else {
|
|
804
|
-
|
|
769
|
+
const err = retryLimitExceeded();
|
|
805
770
|
reject(err);
|
|
806
771
|
}
|
|
807
772
|
}
|
|
@@ -813,13 +778,13 @@ var NetworkRequest = /** @class */ (function () {
|
|
|
813
778
|
else {
|
|
814
779
|
this.backoffId_ = start(doTheRequest, backoffDone, this.timeout_);
|
|
815
780
|
}
|
|
816
|
-
}
|
|
781
|
+
}
|
|
817
782
|
/** @inheritDoc */
|
|
818
|
-
|
|
783
|
+
getPromise() {
|
|
819
784
|
return this.promise_;
|
|
820
|
-
}
|
|
785
|
+
}
|
|
821
786
|
/** @inheritDoc */
|
|
822
|
-
|
|
787
|
+
cancel(appDelete) {
|
|
823
788
|
this.canceled_ = true;
|
|
824
789
|
this.appDelete_ = appDelete || false;
|
|
825
790
|
if (this.backoffId_ !== null) {
|
|
@@ -828,21 +793,19 @@ var NetworkRequest = /** @class */ (function () {
|
|
|
828
793
|
if (this.pendingConnection_ !== null) {
|
|
829
794
|
this.pendingConnection_.abort();
|
|
830
795
|
}
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
}());
|
|
796
|
+
}
|
|
797
|
+
}
|
|
834
798
|
/**
|
|
835
799
|
* A collection of information about the result of a network request.
|
|
836
800
|
* @param opt_canceled - Defaults to false.
|
|
837
801
|
*/
|
|
838
|
-
|
|
839
|
-
|
|
802
|
+
class RequestEndStatus {
|
|
803
|
+
constructor(wasSuccessCode, connection, canceled) {
|
|
840
804
|
this.wasSuccessCode = wasSuccessCode;
|
|
841
805
|
this.connection = connection;
|
|
842
806
|
this.canceled = !!canceled;
|
|
843
807
|
}
|
|
844
|
-
|
|
845
|
-
}());
|
|
808
|
+
}
|
|
846
809
|
function addAuthHeader_(headers, authToken) {
|
|
847
810
|
if (authToken !== null && authToken.length > 0) {
|
|
848
811
|
headers['Authorization'] = 'Firebase ' + authToken;
|
|
@@ -862,11 +825,10 @@ function addAppCheckHeader_(headers, appCheckToken) {
|
|
|
862
825
|
headers['X-Firebase-AppCheck'] = appCheckToken;
|
|
863
826
|
}
|
|
864
827
|
}
|
|
865
|
-
function makeRequest(requestInfo, appId, authToken, appCheckToken, requestFactory, firebaseVersion, retry) {
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
var headers = Object.assign({}, requestInfo.headers);
|
|
828
|
+
function makeRequest(requestInfo, appId, authToken, appCheckToken, requestFactory, firebaseVersion, retry = true) {
|
|
829
|
+
const queryPart = makeQueryString(requestInfo.urlParams);
|
|
830
|
+
const url = requestInfo.url + queryPart;
|
|
831
|
+
const headers = Object.assign({}, requestInfo.headers);
|
|
870
832
|
addGmpidHeader_(headers, appId);
|
|
871
833
|
addAuthHeader_(headers, authToken);
|
|
872
834
|
addVersionHeader_(headers, firebaseVersion);
|
|
@@ -907,15 +869,11 @@ function getBlobBuilder() {
|
|
|
907
869
|
* @param args The values that will make up the resulting blob.
|
|
908
870
|
* @return The blob.
|
|
909
871
|
*/
|
|
910
|
-
function getBlob$1() {
|
|
911
|
-
|
|
912
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
913
|
-
args[_i] = arguments[_i];
|
|
914
|
-
}
|
|
915
|
-
var BlobBuilder = getBlobBuilder();
|
|
872
|
+
function getBlob$1(...args) {
|
|
873
|
+
const BlobBuilder = getBlobBuilder();
|
|
916
874
|
if (BlobBuilder !== undefined) {
|
|
917
|
-
|
|
918
|
-
for (
|
|
875
|
+
const bb = new BlobBuilder();
|
|
876
|
+
for (let i = 0; i < args.length; i++) {
|
|
919
877
|
bb.append(args[i]);
|
|
920
878
|
}
|
|
921
879
|
return bb.getBlob();
|
|
@@ -995,7 +953,7 @@ function decodeBase64(encoded) {
|
|
|
995
953
|
* An enumeration of the possible string formats for upload.
|
|
996
954
|
* @public
|
|
997
955
|
*/
|
|
998
|
-
|
|
956
|
+
const StringFormat = {
|
|
999
957
|
/**
|
|
1000
958
|
* Indicates the string should be interpreted "raw", that is, as normal text.
|
|
1001
959
|
* The string will be interpreted as UTF-16, then uploaded as a UTF-8 byte
|
|
@@ -1029,13 +987,12 @@ var StringFormat = {
|
|
|
1029
987
|
*/
|
|
1030
988
|
DATA_URL: 'data_url'
|
|
1031
989
|
};
|
|
1032
|
-
|
|
1033
|
-
|
|
990
|
+
class StringData {
|
|
991
|
+
constructor(data, contentType) {
|
|
1034
992
|
this.data = data;
|
|
1035
993
|
this.contentType = contentType || null;
|
|
1036
994
|
}
|
|
1037
|
-
|
|
1038
|
-
}());
|
|
995
|
+
}
|
|
1039
996
|
/**
|
|
1040
997
|
* @internal
|
|
1041
998
|
*/
|
|
@@ -1054,9 +1011,9 @@ function dataFromString(format, stringData) {
|
|
|
1054
1011
|
throw unknown();
|
|
1055
1012
|
}
|
|
1056
1013
|
function utf8Bytes_(value) {
|
|
1057
|
-
|
|
1058
|
-
for (
|
|
1059
|
-
|
|
1014
|
+
const b = [];
|
|
1015
|
+
for (let i = 0; i < value.length; i++) {
|
|
1016
|
+
let c = value.charCodeAt(i);
|
|
1060
1017
|
if (c <= 127) {
|
|
1061
1018
|
b.push(c);
|
|
1062
1019
|
}
|
|
@@ -1067,14 +1024,14 @@ function utf8Bytes_(value) {
|
|
|
1067
1024
|
else {
|
|
1068
1025
|
if ((c & 64512) === 55296) {
|
|
1069
1026
|
// The start of a surrogate pair.
|
|
1070
|
-
|
|
1027
|
+
const valid = i < value.length - 1 && (value.charCodeAt(i + 1) & 64512) === 56320;
|
|
1071
1028
|
if (!valid) {
|
|
1072
1029
|
// The second surrogate wasn't there.
|
|
1073
1030
|
b.push(239, 191, 189);
|
|
1074
1031
|
}
|
|
1075
1032
|
else {
|
|
1076
|
-
|
|
1077
|
-
|
|
1033
|
+
const hi = c;
|
|
1034
|
+
const lo = value.charCodeAt(++i);
|
|
1078
1035
|
c = 65536 | ((hi & 1023) << 10) | (lo & 1023);
|
|
1079
1036
|
b.push(240 | (c >> 18), 128 | ((c >> 12) & 63), 128 | ((c >> 6) & 63), 128 | (c & 63));
|
|
1080
1037
|
}
|
|
@@ -1094,7 +1051,7 @@ function utf8Bytes_(value) {
|
|
|
1094
1051
|
return new Uint8Array(b);
|
|
1095
1052
|
}
|
|
1096
1053
|
function percentEncodedBytes_(value) {
|
|
1097
|
-
|
|
1054
|
+
let decoded;
|
|
1098
1055
|
try {
|
|
1099
1056
|
decoded = decodeURIComponent(value);
|
|
1100
1057
|
}
|
|
@@ -1106,10 +1063,10 @@ function percentEncodedBytes_(value) {
|
|
|
1106
1063
|
function base64Bytes_(format, value) {
|
|
1107
1064
|
switch (format) {
|
|
1108
1065
|
case StringFormat.BASE64: {
|
|
1109
|
-
|
|
1110
|
-
|
|
1066
|
+
const hasMinus = value.indexOf('-') !== -1;
|
|
1067
|
+
const hasUnder = value.indexOf('_') !== -1;
|
|
1111
1068
|
if (hasMinus || hasUnder) {
|
|
1112
|
-
|
|
1069
|
+
const invalidChar = hasMinus ? '-' : '_';
|
|
1113
1070
|
throw invalidFormat(format, "Invalid character '" +
|
|
1114
1071
|
invalidChar +
|
|
1115
1072
|
"' found: is it base64url encoded?");
|
|
@@ -1117,10 +1074,10 @@ function base64Bytes_(format, value) {
|
|
|
1117
1074
|
break;
|
|
1118
1075
|
}
|
|
1119
1076
|
case StringFormat.BASE64URL: {
|
|
1120
|
-
|
|
1121
|
-
|
|
1077
|
+
const hasPlus = value.indexOf('+') !== -1;
|
|
1078
|
+
const hasSlash = value.indexOf('/') !== -1;
|
|
1122
1079
|
if (hasPlus || hasSlash) {
|
|
1123
|
-
|
|
1080
|
+
const invalidChar = hasPlus ? '+' : '/';
|
|
1124
1081
|
throw invalidFormat(format, "Invalid character '" + invalidChar + "' found: is it base64 encoded?");
|
|
1125
1082
|
}
|
|
1126
1083
|
value = value.replace(/-/g, '+').replace(/_/g, '/');
|
|
@@ -1128,7 +1085,7 @@ function base64Bytes_(format, value) {
|
|
|
1128
1085
|
}
|
|
1129
1086
|
// do nothing
|
|
1130
1087
|
}
|
|
1131
|
-
|
|
1088
|
+
let bytes;
|
|
1132
1089
|
try {
|
|
1133
1090
|
bytes = decodeBase64(value);
|
|
1134
1091
|
}
|
|
@@ -1138,21 +1095,21 @@ function base64Bytes_(format, value) {
|
|
|
1138
1095
|
}
|
|
1139
1096
|
throw invalidFormat(format, 'Invalid character found');
|
|
1140
1097
|
}
|
|
1141
|
-
|
|
1142
|
-
for (
|
|
1098
|
+
const array = new Uint8Array(bytes.length);
|
|
1099
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
1143
1100
|
array[i] = bytes.charCodeAt(i);
|
|
1144
1101
|
}
|
|
1145
1102
|
return array;
|
|
1146
1103
|
}
|
|
1147
|
-
|
|
1148
|
-
|
|
1104
|
+
class DataURLParts {
|
|
1105
|
+
constructor(dataURL) {
|
|
1149
1106
|
this.base64 = false;
|
|
1150
1107
|
this.contentType = null;
|
|
1151
|
-
|
|
1108
|
+
const matches = dataURL.match(/^data:([^,]+)?,/);
|
|
1152
1109
|
if (matches === null) {
|
|
1153
1110
|
throw invalidFormat(StringFormat.DATA_URL, "Must be formatted 'data:[<mediatype>][;base64],<data>");
|
|
1154
1111
|
}
|
|
1155
|
-
|
|
1112
|
+
const middle = matches[1] || null;
|
|
1156
1113
|
if (middle != null) {
|
|
1157
1114
|
this.base64 = endsWith(middle, ';base64');
|
|
1158
1115
|
this.contentType = this.base64
|
|
@@ -1161,10 +1118,9 @@ var DataURLParts = /** @class */ (function () {
|
|
|
1161
1118
|
}
|
|
1162
1119
|
this.rest = dataURL.substring(dataURL.indexOf(',') + 1);
|
|
1163
1120
|
}
|
|
1164
|
-
|
|
1165
|
-
}());
|
|
1121
|
+
}
|
|
1166
1122
|
function dataURLBytes_(dataUrl) {
|
|
1167
|
-
|
|
1123
|
+
const parts = new DataURLParts(dataUrl);
|
|
1168
1124
|
if (parts.base64) {
|
|
1169
1125
|
return base64Bytes_(StringFormat.BASE64, parts.rest);
|
|
1170
1126
|
}
|
|
@@ -1173,11 +1129,11 @@ function dataURLBytes_(dataUrl) {
|
|
|
1173
1129
|
}
|
|
1174
1130
|
}
|
|
1175
1131
|
function dataURLContentType_(dataUrl) {
|
|
1176
|
-
|
|
1132
|
+
const parts = new DataURLParts(dataUrl);
|
|
1177
1133
|
return parts.contentType;
|
|
1178
1134
|
}
|
|
1179
1135
|
function endsWith(s, end) {
|
|
1180
|
-
|
|
1136
|
+
const longEnough = s.length >= end.length;
|
|
1181
1137
|
if (!longEnough) {
|
|
1182
1138
|
return false;
|
|
1183
1139
|
}
|
|
@@ -1207,10 +1163,10 @@ function endsWith(s, end) {
|
|
|
1207
1163
|
*
|
|
1208
1164
|
* @internal
|
|
1209
1165
|
*/
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1166
|
+
class FbsBlob {
|
|
1167
|
+
constructor(data, elideCopy) {
|
|
1168
|
+
let size = 0;
|
|
1169
|
+
let blobType = '';
|
|
1214
1170
|
if (isNativeBlob(data)) {
|
|
1215
1171
|
this.data_ = data;
|
|
1216
1172
|
size = data.size;
|
|
@@ -1239,33 +1195,29 @@ var FbsBlob = /** @class */ (function () {
|
|
|
1239
1195
|
this.size_ = size;
|
|
1240
1196
|
this.type_ = blobType;
|
|
1241
1197
|
}
|
|
1242
|
-
|
|
1198
|
+
size() {
|
|
1243
1199
|
return this.size_;
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1200
|
+
}
|
|
1201
|
+
type() {
|
|
1246
1202
|
return this.type_;
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1203
|
+
}
|
|
1204
|
+
slice(startByte, endByte) {
|
|
1249
1205
|
if (isNativeBlob(this.data_)) {
|
|
1250
|
-
|
|
1251
|
-
|
|
1206
|
+
const realBlob = this.data_;
|
|
1207
|
+
const sliced = sliceBlob(realBlob, startByte, endByte);
|
|
1252
1208
|
if (sliced === null) {
|
|
1253
1209
|
return null;
|
|
1254
1210
|
}
|
|
1255
1211
|
return new FbsBlob(sliced);
|
|
1256
1212
|
}
|
|
1257
1213
|
else {
|
|
1258
|
-
|
|
1214
|
+
const slice = new Uint8Array(this.data_.buffer, startByte, endByte - startByte);
|
|
1259
1215
|
return new FbsBlob(slice, true);
|
|
1260
1216
|
}
|
|
1261
|
-
}
|
|
1262
|
-
|
|
1263
|
-
var args = [];
|
|
1264
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1265
|
-
args[_i] = arguments[_i];
|
|
1266
|
-
}
|
|
1217
|
+
}
|
|
1218
|
+
static getBlob(...args) {
|
|
1267
1219
|
if (isNativeBlobDefined()) {
|
|
1268
|
-
|
|
1220
|
+
const blobby = args.map((val) => {
|
|
1269
1221
|
if (val instanceof FbsBlob) {
|
|
1270
1222
|
return val.data_;
|
|
1271
1223
|
}
|
|
@@ -1276,7 +1228,7 @@ var FbsBlob = /** @class */ (function () {
|
|
|
1276
1228
|
return new FbsBlob(getBlob$1.apply(null, blobby));
|
|
1277
1229
|
}
|
|
1278
1230
|
else {
|
|
1279
|
-
|
|
1231
|
+
const uint8Arrays = args.map((val) => {
|
|
1280
1232
|
if (isString(val)) {
|
|
1281
1233
|
return dataFromString(StringFormat.RAW, val).data;
|
|
1282
1234
|
}
|
|
@@ -1285,25 +1237,24 @@ var FbsBlob = /** @class */ (function () {
|
|
|
1285
1237
|
return val.data_;
|
|
1286
1238
|
}
|
|
1287
1239
|
});
|
|
1288
|
-
|
|
1289
|
-
uint8Arrays.forEach(
|
|
1290
|
-
|
|
1240
|
+
let finalLength = 0;
|
|
1241
|
+
uint8Arrays.forEach((array) => {
|
|
1242
|
+
finalLength += array.byteLength;
|
|
1291
1243
|
});
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
uint8Arrays.forEach(
|
|
1295
|
-
for (
|
|
1296
|
-
|
|
1244
|
+
const merged = new Uint8Array(finalLength);
|
|
1245
|
+
let index = 0;
|
|
1246
|
+
uint8Arrays.forEach((array) => {
|
|
1247
|
+
for (let i = 0; i < array.length; i++) {
|
|
1248
|
+
merged[index++] = array[i];
|
|
1297
1249
|
}
|
|
1298
1250
|
});
|
|
1299
|
-
return new FbsBlob(
|
|
1251
|
+
return new FbsBlob(merged, true);
|
|
1300
1252
|
}
|
|
1301
|
-
}
|
|
1302
|
-
|
|
1253
|
+
}
|
|
1254
|
+
uploadData() {
|
|
1303
1255
|
return this.data_;
|
|
1304
|
-
}
|
|
1305
|
-
|
|
1306
|
-
}());
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1307
1258
|
|
|
1308
1259
|
/**
|
|
1309
1260
|
* @license
|
|
@@ -1326,7 +1277,7 @@ var FbsBlob = /** @class */ (function () {
|
|
|
1326
1277
|
* given string does not represent a JSON object.
|
|
1327
1278
|
*/
|
|
1328
1279
|
function jsonObjectOrNull(s) {
|
|
1329
|
-
|
|
1280
|
+
let obj;
|
|
1330
1281
|
try {
|
|
1331
1282
|
obj = JSON.parse(s);
|
|
1332
1283
|
}
|
|
@@ -1367,17 +1318,17 @@ function parent(path) {
|
|
|
1367
1318
|
if (path.length === 0) {
|
|
1368
1319
|
return null;
|
|
1369
1320
|
}
|
|
1370
|
-
|
|
1321
|
+
const index = path.lastIndexOf('/');
|
|
1371
1322
|
if (index === -1) {
|
|
1372
1323
|
return '';
|
|
1373
1324
|
}
|
|
1374
|
-
|
|
1325
|
+
const newPath = path.slice(0, index);
|
|
1375
1326
|
return newPath;
|
|
1376
1327
|
}
|
|
1377
1328
|
function child(path, childPath) {
|
|
1378
|
-
|
|
1329
|
+
const canonicalChildPath = childPath
|
|
1379
1330
|
.split('/')
|
|
1380
|
-
.filter(
|
|
1331
|
+
.filter(component => component.length > 0)
|
|
1381
1332
|
.join('/');
|
|
1382
1333
|
if (path.length === 0) {
|
|
1383
1334
|
return canonicalChildPath;
|
|
@@ -1393,7 +1344,7 @@ function child(path, childPath) {
|
|
|
1393
1344
|
* '/a' -> 'a'
|
|
1394
1345
|
*/
|
|
1395
1346
|
function lastComponent(path) {
|
|
1396
|
-
|
|
1347
|
+
const index = path.lastIndexOf('/', path.length - 2);
|
|
1397
1348
|
if (index === -1) {
|
|
1398
1349
|
return path;
|
|
1399
1350
|
}
|
|
@@ -1421,16 +1372,15 @@ function lastComponent(path) {
|
|
|
1421
1372
|
function noXform_(metadata, value) {
|
|
1422
1373
|
return value;
|
|
1423
1374
|
}
|
|
1424
|
-
|
|
1425
|
-
|
|
1375
|
+
class Mapping {
|
|
1376
|
+
constructor(server, local, writable, xform) {
|
|
1426
1377
|
this.server = server;
|
|
1427
1378
|
this.local = local || server;
|
|
1428
1379
|
this.writable = !!writable;
|
|
1429
1380
|
this.xform = xform || noXform_;
|
|
1430
1381
|
}
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
var mappings_ = null;
|
|
1382
|
+
}
|
|
1383
|
+
let mappings_ = null;
|
|
1434
1384
|
function xformPath(fullPath) {
|
|
1435
1385
|
if (!isString(fullPath) || fullPath.length < 2) {
|
|
1436
1386
|
return fullPath;
|
|
@@ -1443,7 +1393,7 @@ function getMappings() {
|
|
|
1443
1393
|
if (mappings_) {
|
|
1444
1394
|
return mappings_;
|
|
1445
1395
|
}
|
|
1446
|
-
|
|
1396
|
+
const mappings = [];
|
|
1447
1397
|
mappings.push(new Mapping('bucket'));
|
|
1448
1398
|
mappings.push(new Mapping('generation'));
|
|
1449
1399
|
mappings.push(new Mapping('metageneration'));
|
|
@@ -1451,7 +1401,7 @@ function getMappings() {
|
|
|
1451
1401
|
function mappingsXformPath(_metadata, fullPath) {
|
|
1452
1402
|
return xformPath(fullPath);
|
|
1453
1403
|
}
|
|
1454
|
-
|
|
1404
|
+
const nameMapping = new Mapping('name');
|
|
1455
1405
|
nameMapping.xform = mappingsXformPath;
|
|
1456
1406
|
mappings.push(nameMapping);
|
|
1457
1407
|
/**
|
|
@@ -1465,7 +1415,7 @@ function getMappings() {
|
|
|
1465
1415
|
return size;
|
|
1466
1416
|
}
|
|
1467
1417
|
}
|
|
1468
|
-
|
|
1418
|
+
const sizeMapping = new Mapping('size');
|
|
1469
1419
|
sizeMapping.xform = xformSize;
|
|
1470
1420
|
mappings.push(sizeMapping);
|
|
1471
1421
|
mappings.push(new Mapping('timeCreated'));
|
|
@@ -1482,34 +1432,34 @@ function getMappings() {
|
|
|
1482
1432
|
}
|
|
1483
1433
|
function addRef(metadata, service) {
|
|
1484
1434
|
function generateRef() {
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1435
|
+
const bucket = metadata['bucket'];
|
|
1436
|
+
const path = metadata['fullPath'];
|
|
1437
|
+
const loc = new Location(bucket, path);
|
|
1488
1438
|
return service._makeStorageReference(loc);
|
|
1489
1439
|
}
|
|
1490
1440
|
Object.defineProperty(metadata, 'ref', { get: generateRef });
|
|
1491
1441
|
}
|
|
1492
1442
|
function fromResource(service, resource, mappings) {
|
|
1493
|
-
|
|
1443
|
+
const metadata = {};
|
|
1494
1444
|
metadata['type'] = 'file';
|
|
1495
|
-
|
|
1496
|
-
for (
|
|
1497
|
-
|
|
1445
|
+
const len = mappings.length;
|
|
1446
|
+
for (let i = 0; i < len; i++) {
|
|
1447
|
+
const mapping = mappings[i];
|
|
1498
1448
|
metadata[mapping.local] = mapping.xform(metadata, resource[mapping.server]);
|
|
1499
1449
|
}
|
|
1500
1450
|
addRef(metadata, service);
|
|
1501
1451
|
return metadata;
|
|
1502
1452
|
}
|
|
1503
1453
|
function fromResourceString(service, resourceString, mappings) {
|
|
1504
|
-
|
|
1454
|
+
const obj = jsonObjectOrNull(resourceString);
|
|
1505
1455
|
if (obj === null) {
|
|
1506
1456
|
return null;
|
|
1507
1457
|
}
|
|
1508
|
-
|
|
1458
|
+
const resource = obj;
|
|
1509
1459
|
return fromResource(service, resource, mappings);
|
|
1510
1460
|
}
|
|
1511
1461
|
function downloadUrlFromResourceString(metadata, resourceString, host, protocol) {
|
|
1512
|
-
|
|
1462
|
+
const obj = jsonObjectOrNull(resourceString);
|
|
1513
1463
|
if (obj === null) {
|
|
1514
1464
|
return null;
|
|
1515
1465
|
}
|
|
@@ -1518,30 +1468,30 @@ function downloadUrlFromResourceString(metadata, resourceString, host, protocol)
|
|
|
1518
1468
|
// through list, so we don't want to throw an Error.
|
|
1519
1469
|
return null;
|
|
1520
1470
|
}
|
|
1521
|
-
|
|
1471
|
+
const tokens = obj['downloadTokens'];
|
|
1522
1472
|
if (tokens.length === 0) {
|
|
1523
1473
|
return null;
|
|
1524
1474
|
}
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1475
|
+
const encode = encodeURIComponent;
|
|
1476
|
+
const tokensList = tokens.split(',');
|
|
1477
|
+
const urls = tokensList.map((token) => {
|
|
1478
|
+
const bucket = metadata['bucket'];
|
|
1479
|
+
const path = metadata['fullPath'];
|
|
1480
|
+
const urlPart = '/b/' + encode(bucket) + '/o/' + encode(path);
|
|
1481
|
+
const base = makeUrl(urlPart, host, protocol);
|
|
1482
|
+
const queryString = makeQueryString({
|
|
1533
1483
|
alt: 'media',
|
|
1534
|
-
token
|
|
1484
|
+
token
|
|
1535
1485
|
});
|
|
1536
1486
|
return base + queryString;
|
|
1537
1487
|
});
|
|
1538
1488
|
return urls[0];
|
|
1539
1489
|
}
|
|
1540
1490
|
function toResourceString(metadata, mappings) {
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
for (
|
|
1544
|
-
|
|
1491
|
+
const resource = {};
|
|
1492
|
+
const len = mappings.length;
|
|
1493
|
+
for (let i = 0; i < len; i++) {
|
|
1494
|
+
const mapping = mappings[i];
|
|
1545
1495
|
if (mapping.writable) {
|
|
1546
1496
|
resource[mapping.server] = metadata[mapping.local];
|
|
1547
1497
|
}
|
|
@@ -1565,37 +1515,35 @@ function toResourceString(metadata, mappings) {
|
|
|
1565
1515
|
* See the License for the specific language governing permissions and
|
|
1566
1516
|
* limitations under the License.
|
|
1567
1517
|
*/
|
|
1568
|
-
|
|
1569
|
-
|
|
1518
|
+
const PREFIXES_KEY = 'prefixes';
|
|
1519
|
+
const ITEMS_KEY = 'items';
|
|
1570
1520
|
function fromBackendResponse(service, bucket, resource) {
|
|
1571
|
-
|
|
1521
|
+
const listResult = {
|
|
1572
1522
|
prefixes: [],
|
|
1573
1523
|
items: [],
|
|
1574
1524
|
nextPageToken: resource['nextPageToken']
|
|
1575
1525
|
};
|
|
1576
1526
|
if (resource[PREFIXES_KEY]) {
|
|
1577
|
-
for (
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
var reference = service._makeStorageReference(new Location(bucket, pathWithoutTrailingSlash));
|
|
1527
|
+
for (const path of resource[PREFIXES_KEY]) {
|
|
1528
|
+
const pathWithoutTrailingSlash = path.replace(/\/$/, '');
|
|
1529
|
+
const reference = service._makeStorageReference(new Location(bucket, pathWithoutTrailingSlash));
|
|
1581
1530
|
listResult.prefixes.push(reference);
|
|
1582
1531
|
}
|
|
1583
1532
|
}
|
|
1584
1533
|
if (resource[ITEMS_KEY]) {
|
|
1585
|
-
for (
|
|
1586
|
-
|
|
1587
|
-
var reference = service._makeStorageReference(new Location(bucket, item['name']));
|
|
1534
|
+
for (const item of resource[ITEMS_KEY]) {
|
|
1535
|
+
const reference = service._makeStorageReference(new Location(bucket, item['name']));
|
|
1588
1536
|
listResult.items.push(reference);
|
|
1589
1537
|
}
|
|
1590
1538
|
}
|
|
1591
1539
|
return listResult;
|
|
1592
1540
|
}
|
|
1593
1541
|
function fromResponseString(service, bucket, resourceString) {
|
|
1594
|
-
|
|
1542
|
+
const obj = jsonObjectOrNull(resourceString);
|
|
1595
1543
|
if (obj === null) {
|
|
1596
1544
|
return null;
|
|
1597
1545
|
}
|
|
1598
|
-
|
|
1546
|
+
const resource = obj;
|
|
1599
1547
|
return fromBackendResponse(service, bucket, resource);
|
|
1600
1548
|
}
|
|
1601
1549
|
|
|
@@ -1605,8 +1553,8 @@ function fromResponseString(service, bucket, resourceString) {
|
|
|
1605
1553
|
* @param I - the type of the backend's network response.
|
|
1606
1554
|
* @param O - the output response type used by the rest of the SDK.
|
|
1607
1555
|
*/
|
|
1608
|
-
|
|
1609
|
-
|
|
1556
|
+
class RequestInfo {
|
|
1557
|
+
constructor(url, method,
|
|
1610
1558
|
/**
|
|
1611
1559
|
* Returns the value with which to resolve the request's promise. Only called
|
|
1612
1560
|
* if the request is successful. Throw from this function to reject the
|
|
@@ -1631,8 +1579,7 @@ var RequestInfo = /** @class */ (function () {
|
|
|
1631
1579
|
this.successCodes = [200];
|
|
1632
1580
|
this.additionalRetryCodes = [];
|
|
1633
1581
|
}
|
|
1634
|
-
|
|
1635
|
-
}());
|
|
1582
|
+
}
|
|
1636
1583
|
|
|
1637
1584
|
/**
|
|
1638
1585
|
* @license
|
|
@@ -1660,7 +1607,7 @@ function handlerCheck(cndn) {
|
|
|
1660
1607
|
}
|
|
1661
1608
|
function metadataHandler(service, mappings) {
|
|
1662
1609
|
function handler(xhr, text) {
|
|
1663
|
-
|
|
1610
|
+
const metadata = fromResourceString(service, text, mappings);
|
|
1664
1611
|
handlerCheck(metadata !== null);
|
|
1665
1612
|
return metadata;
|
|
1666
1613
|
}
|
|
@@ -1668,7 +1615,7 @@ function metadataHandler(service, mappings) {
|
|
|
1668
1615
|
}
|
|
1669
1616
|
function listHandler(service, bucket) {
|
|
1670
1617
|
function handler(xhr, text) {
|
|
1671
|
-
|
|
1618
|
+
const listResult = fromResponseString(service, bucket, text);
|
|
1672
1619
|
handlerCheck(listResult !== null);
|
|
1673
1620
|
return listResult;
|
|
1674
1621
|
}
|
|
@@ -1676,7 +1623,7 @@ function listHandler(service, bucket) {
|
|
|
1676
1623
|
}
|
|
1677
1624
|
function downloadUrlHandler(service, mappings) {
|
|
1678
1625
|
function handler(xhr, text) {
|
|
1679
|
-
|
|
1626
|
+
const metadata = fromResourceString(service, text, mappings);
|
|
1680
1627
|
handlerCheck(metadata !== null);
|
|
1681
1628
|
return downloadUrlFromResourceString(metadata, text, service.host, service._protocol);
|
|
1682
1629
|
}
|
|
@@ -1684,7 +1631,7 @@ function downloadUrlHandler(service, mappings) {
|
|
|
1684
1631
|
}
|
|
1685
1632
|
function sharedErrorHandler(location) {
|
|
1686
1633
|
function errorHandler(xhr, err) {
|
|
1687
|
-
|
|
1634
|
+
let newErr;
|
|
1688
1635
|
if (xhr.getStatus() === 401) {
|
|
1689
1636
|
if (
|
|
1690
1637
|
// This exact message string is the only consistent part of the
|
|
@@ -1716,9 +1663,9 @@ function sharedErrorHandler(location) {
|
|
|
1716
1663
|
return errorHandler;
|
|
1717
1664
|
}
|
|
1718
1665
|
function objectErrorHandler(location) {
|
|
1719
|
-
|
|
1666
|
+
const shared = sharedErrorHandler(location);
|
|
1720
1667
|
function errorHandler(xhr, err) {
|
|
1721
|
-
|
|
1668
|
+
let newErr = shared(xhr, err);
|
|
1722
1669
|
if (xhr.getStatus() === 404) {
|
|
1723
1670
|
newErr = objectNotFound(location.path);
|
|
1724
1671
|
}
|
|
@@ -1728,16 +1675,16 @@ function objectErrorHandler(location) {
|
|
|
1728
1675
|
return errorHandler;
|
|
1729
1676
|
}
|
|
1730
1677
|
function getMetadata$2(service, location, mappings) {
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1678
|
+
const urlPart = location.fullServerUrl();
|
|
1679
|
+
const url = makeUrl(urlPart, service.host, service._protocol);
|
|
1680
|
+
const method = 'GET';
|
|
1681
|
+
const timeout = service.maxOperationRetryTime;
|
|
1682
|
+
const requestInfo = new RequestInfo(url, method, metadataHandler(service, mappings), timeout);
|
|
1736
1683
|
requestInfo.errorHandler = objectErrorHandler(location);
|
|
1737
1684
|
return requestInfo;
|
|
1738
1685
|
}
|
|
1739
1686
|
function list$2(service, location, delimiter, pageToken, maxResults) {
|
|
1740
|
-
|
|
1687
|
+
const urlParams = {};
|
|
1741
1688
|
if (location.isRoot) {
|
|
1742
1689
|
urlParams['prefix'] = '';
|
|
1743
1690
|
}
|
|
@@ -1753,57 +1700,57 @@ function list$2(service, location, delimiter, pageToken, maxResults) {
|
|
|
1753
1700
|
if (maxResults) {
|
|
1754
1701
|
urlParams['maxResults'] = maxResults;
|
|
1755
1702
|
}
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1703
|
+
const urlPart = location.bucketOnlyServerUrl();
|
|
1704
|
+
const url = makeUrl(urlPart, service.host, service._protocol);
|
|
1705
|
+
const method = 'GET';
|
|
1706
|
+
const timeout = service.maxOperationRetryTime;
|
|
1707
|
+
const requestInfo = new RequestInfo(url, method, listHandler(service, location.bucket), timeout);
|
|
1761
1708
|
requestInfo.urlParams = urlParams;
|
|
1762
1709
|
requestInfo.errorHandler = sharedErrorHandler(location);
|
|
1763
1710
|
return requestInfo;
|
|
1764
1711
|
}
|
|
1765
1712
|
function getBytes$1(service, location, maxDownloadSizeBytes) {
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1713
|
+
const urlPart = location.fullServerUrl();
|
|
1714
|
+
const url = makeUrl(urlPart, service.host, service._protocol) + '?alt=media';
|
|
1715
|
+
const method = 'GET';
|
|
1716
|
+
const timeout = service.maxOperationRetryTime;
|
|
1717
|
+
const requestInfo = new RequestInfo(url, method, (_, data) => data, timeout);
|
|
1771
1718
|
requestInfo.errorHandler = objectErrorHandler(location);
|
|
1772
1719
|
if (maxDownloadSizeBytes !== undefined) {
|
|
1773
|
-
requestInfo.headers['Range'] =
|
|
1720
|
+
requestInfo.headers['Range'] = `bytes=0-${maxDownloadSizeBytes}`;
|
|
1774
1721
|
requestInfo.successCodes = [200 /* OK */, 206 /* Partial Content */];
|
|
1775
1722
|
}
|
|
1776
1723
|
return requestInfo;
|
|
1777
1724
|
}
|
|
1778
1725
|
function getDownloadUrl(service, location, mappings) {
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1726
|
+
const urlPart = location.fullServerUrl();
|
|
1727
|
+
const url = makeUrl(urlPart, service.host, service._protocol);
|
|
1728
|
+
const method = 'GET';
|
|
1729
|
+
const timeout = service.maxOperationRetryTime;
|
|
1730
|
+
const requestInfo = new RequestInfo(url, method, downloadUrlHandler(service, mappings), timeout);
|
|
1784
1731
|
requestInfo.errorHandler = objectErrorHandler(location);
|
|
1785
1732
|
return requestInfo;
|
|
1786
1733
|
}
|
|
1787
1734
|
function updateMetadata$2(service, location, metadata, mappings) {
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1735
|
+
const urlPart = location.fullServerUrl();
|
|
1736
|
+
const url = makeUrl(urlPart, service.host, service._protocol);
|
|
1737
|
+
const method = 'PATCH';
|
|
1738
|
+
const body = toResourceString(metadata, mappings);
|
|
1739
|
+
const headers = { 'Content-Type': 'application/json; charset=utf-8' };
|
|
1740
|
+
const timeout = service.maxOperationRetryTime;
|
|
1741
|
+
const requestInfo = new RequestInfo(url, method, metadataHandler(service, mappings), timeout);
|
|
1795
1742
|
requestInfo.headers = headers;
|
|
1796
1743
|
requestInfo.body = body;
|
|
1797
1744
|
requestInfo.errorHandler = objectErrorHandler(location);
|
|
1798
1745
|
return requestInfo;
|
|
1799
1746
|
}
|
|
1800
1747
|
function deleteObject$2(service, location) {
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1748
|
+
const urlPart = location.fullServerUrl();
|
|
1749
|
+
const url = makeUrl(urlPart, service.host, service._protocol);
|
|
1750
|
+
const method = 'DELETE';
|
|
1751
|
+
const timeout = service.maxOperationRetryTime;
|
|
1805
1752
|
function handler(_xhr, _text) { }
|
|
1806
|
-
|
|
1753
|
+
const requestInfo = new RequestInfo(url, method, handler, timeout);
|
|
1807
1754
|
requestInfo.successCodes = [200, 204];
|
|
1808
1755
|
requestInfo.errorHandler = objectErrorHandler(location);
|
|
1809
1756
|
return requestInfo;
|
|
@@ -1814,7 +1761,7 @@ function determineContentType_(metadata, blob) {
|
|
|
1814
1761
|
'application/octet-stream');
|
|
1815
1762
|
}
|
|
1816
1763
|
function metadataForUpload_(location, blob, metadata) {
|
|
1817
|
-
|
|
1764
|
+
const metadataClone = Object.assign({}, metadata);
|
|
1818
1765
|
metadataClone['fullPath'] = location.path;
|
|
1819
1766
|
metadataClone['size'] = blob.size();
|
|
1820
1767
|
if (!metadataClone['contentType']) {
|
|
@@ -1826,22 +1773,22 @@ function metadataForUpload_(location, blob, metadata) {
|
|
|
1826
1773
|
* Prepare RequestInfo for uploads as Content-Type: multipart.
|
|
1827
1774
|
*/
|
|
1828
1775
|
function multipartUpload(service, location, mappings, blob, metadata) {
|
|
1829
|
-
|
|
1830
|
-
|
|
1776
|
+
const urlPart = location.bucketOnlyServerUrl();
|
|
1777
|
+
const headers = {
|
|
1831
1778
|
'X-Goog-Upload-Protocol': 'multipart'
|
|
1832
1779
|
};
|
|
1833
1780
|
function genBoundary() {
|
|
1834
|
-
|
|
1835
|
-
for (
|
|
1781
|
+
let str = '';
|
|
1782
|
+
for (let i = 0; i < 2; i++) {
|
|
1836
1783
|
str = str + Math.random().toString().slice(2);
|
|
1837
1784
|
}
|
|
1838
1785
|
return str;
|
|
1839
1786
|
}
|
|
1840
|
-
|
|
1787
|
+
const boundary = genBoundary();
|
|
1841
1788
|
headers['Content-Type'] = 'multipart/related; boundary=' + boundary;
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1789
|
+
const metadata_ = metadataForUpload_(location, blob, metadata);
|
|
1790
|
+
const metadataString = toResourceString(metadata_, mappings);
|
|
1791
|
+
const preBlobPart = '--' +
|
|
1845
1792
|
boundary +
|
|
1846
1793
|
'\r\n' +
|
|
1847
1794
|
'Content-Type: application/json; charset=utf-8\r\n\r\n' +
|
|
@@ -1852,16 +1799,16 @@ function multipartUpload(service, location, mappings, blob, metadata) {
|
|
|
1852
1799
|
'Content-Type: ' +
|
|
1853
1800
|
metadata_['contentType'] +
|
|
1854
1801
|
'\r\n\r\n';
|
|
1855
|
-
|
|
1856
|
-
|
|
1802
|
+
const postBlobPart = '\r\n--' + boundary + '--';
|
|
1803
|
+
const body = FbsBlob.getBlob(preBlobPart, blob, postBlobPart);
|
|
1857
1804
|
if (body === null) {
|
|
1858
1805
|
throw cannotSliceBlob();
|
|
1859
1806
|
}
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1807
|
+
const urlParams = { name: metadata_['fullPath'] };
|
|
1808
|
+
const url = makeUrl(urlPart, service.host, service._protocol);
|
|
1809
|
+
const method = 'POST';
|
|
1810
|
+
const timeout = service.maxUploadRetryTime;
|
|
1811
|
+
const requestInfo = new RequestInfo(url, method, metadataHandler(service, mappings), timeout);
|
|
1865
1812
|
requestInfo.urlParams = urlParams;
|
|
1866
1813
|
requestInfo.headers = headers;
|
|
1867
1814
|
requestInfo.body = body.uploadData();
|
|
@@ -1875,45 +1822,44 @@ function multipartUpload(service, location, mappings, blob, metadata) {
|
|
|
1875
1822
|
* @param opt_metadata The upload metadata, should
|
|
1876
1823
|
* only be passed if opt_finalized is true.
|
|
1877
1824
|
*/
|
|
1878
|
-
|
|
1879
|
-
|
|
1825
|
+
class ResumableUploadStatus {
|
|
1826
|
+
constructor(current, total, finalized, metadata) {
|
|
1880
1827
|
this.current = current;
|
|
1881
1828
|
this.total = total;
|
|
1882
1829
|
this.finalized = !!finalized;
|
|
1883
1830
|
this.metadata = metadata || null;
|
|
1884
1831
|
}
|
|
1885
|
-
|
|
1886
|
-
}());
|
|
1832
|
+
}
|
|
1887
1833
|
function checkResumeHeader_(xhr, allowed) {
|
|
1888
|
-
|
|
1834
|
+
let status = null;
|
|
1889
1835
|
try {
|
|
1890
1836
|
status = xhr.getResponseHeader('X-Goog-Upload-Status');
|
|
1891
1837
|
}
|
|
1892
1838
|
catch (e) {
|
|
1893
1839
|
handlerCheck(false);
|
|
1894
1840
|
}
|
|
1895
|
-
|
|
1841
|
+
const allowedStatus = allowed || ['active'];
|
|
1896
1842
|
handlerCheck(!!status && allowedStatus.indexOf(status) !== -1);
|
|
1897
1843
|
return status;
|
|
1898
1844
|
}
|
|
1899
1845
|
function createResumableUpload(service, location, mappings, blob, metadata) {
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1846
|
+
const urlPart = location.bucketOnlyServerUrl();
|
|
1847
|
+
const metadataForUpload = metadataForUpload_(location, blob, metadata);
|
|
1848
|
+
const urlParams = { name: metadataForUpload['fullPath'] };
|
|
1849
|
+
const url = makeUrl(urlPart, service.host, service._protocol);
|
|
1850
|
+
const method = 'POST';
|
|
1851
|
+
const headers = {
|
|
1906
1852
|
'X-Goog-Upload-Protocol': 'resumable',
|
|
1907
1853
|
'X-Goog-Upload-Command': 'start',
|
|
1908
|
-
'X-Goog-Upload-Header-Content-Length':
|
|
1854
|
+
'X-Goog-Upload-Header-Content-Length': `${blob.size()}`,
|
|
1909
1855
|
'X-Goog-Upload-Header-Content-Type': metadataForUpload['contentType'],
|
|
1910
1856
|
'Content-Type': 'application/json; charset=utf-8'
|
|
1911
1857
|
};
|
|
1912
|
-
|
|
1913
|
-
|
|
1858
|
+
const body = toResourceString(metadataForUpload, mappings);
|
|
1859
|
+
const timeout = service.maxUploadRetryTime;
|
|
1914
1860
|
function handler(xhr) {
|
|
1915
1861
|
checkResumeHeader_(xhr);
|
|
1916
|
-
|
|
1862
|
+
let url;
|
|
1917
1863
|
try {
|
|
1918
1864
|
url = xhr.getResponseHeader('X-Goog-Upload-URL');
|
|
1919
1865
|
}
|
|
@@ -1923,7 +1869,7 @@ function createResumableUpload(service, location, mappings, blob, metadata) {
|
|
|
1923
1869
|
handlerCheck(isString(url));
|
|
1924
1870
|
return url;
|
|
1925
1871
|
}
|
|
1926
|
-
|
|
1872
|
+
const requestInfo = new RequestInfo(url, method, handler, timeout);
|
|
1927
1873
|
requestInfo.urlParams = urlParams;
|
|
1928
1874
|
requestInfo.headers = headers;
|
|
1929
1875
|
requestInfo.body = body;
|
|
@@ -1934,10 +1880,10 @@ function createResumableUpload(service, location, mappings, blob, metadata) {
|
|
|
1934
1880
|
* @param url From a call to fbs.requests.createResumableUpload.
|
|
1935
1881
|
*/
|
|
1936
1882
|
function getResumableUploadStatus(service, location, url, blob) {
|
|
1937
|
-
|
|
1883
|
+
const headers = { 'X-Goog-Upload-Command': 'query' };
|
|
1938
1884
|
function handler(xhr) {
|
|
1939
|
-
|
|
1940
|
-
|
|
1885
|
+
const status = checkResumeHeader_(xhr, ['active', 'final']);
|
|
1886
|
+
let sizeString = null;
|
|
1941
1887
|
try {
|
|
1942
1888
|
sizeString = xhr.getResponseHeader('X-Goog-Upload-Size-Received');
|
|
1943
1889
|
}
|
|
@@ -1948,13 +1894,13 @@ function getResumableUploadStatus(service, location, url, blob) {
|
|
|
1948
1894
|
// null or empty string
|
|
1949
1895
|
handlerCheck(false);
|
|
1950
1896
|
}
|
|
1951
|
-
|
|
1897
|
+
const size = Number(sizeString);
|
|
1952
1898
|
handlerCheck(!isNaN(size));
|
|
1953
1899
|
return new ResumableUploadStatus(size, blob.size(), status === 'final');
|
|
1954
1900
|
}
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1901
|
+
const method = 'POST';
|
|
1902
|
+
const timeout = service.maxUploadRetryTime;
|
|
1903
|
+
const requestInfo = new RequestInfo(url, method, handler, timeout);
|
|
1958
1904
|
requestInfo.headers = headers;
|
|
1959
1905
|
requestInfo.errorHandler = sharedErrorHandler(location);
|
|
1960
1906
|
return requestInfo;
|
|
@@ -1963,7 +1909,7 @@ function getResumableUploadStatus(service, location, url, blob) {
|
|
|
1963
1909
|
* Any uploads via the resumable upload API must transfer a number of bytes
|
|
1964
1910
|
* that is a multiple of this number.
|
|
1965
1911
|
*/
|
|
1966
|
-
|
|
1912
|
+
const RESUMABLE_UPLOAD_CHUNK_SIZE = 256 * 1024;
|
|
1967
1913
|
/**
|
|
1968
1914
|
* @param url From a call to fbs.requests.createResumableUpload.
|
|
1969
1915
|
* @param chunkSize Number of bytes to upload.
|
|
@@ -1976,7 +1922,7 @@ var RESUMABLE_UPLOAD_CHUNK_SIZE = 256 * 1024;
|
|
|
1976
1922
|
function continueResumableUpload(location, service, url, blob, chunkSize, mappings, status, progressCallback) {
|
|
1977
1923
|
// TODO(andysoto): standardize on internal asserts
|
|
1978
1924
|
// assert(!(opt_status && opt_status.finalized));
|
|
1979
|
-
|
|
1925
|
+
const status_ = new ResumableUploadStatus(0, 0);
|
|
1980
1926
|
if (status) {
|
|
1981
1927
|
status_.current = status.current;
|
|
1982
1928
|
status_.total = status.total;
|
|
@@ -1988,14 +1934,14 @@ function continueResumableUpload(location, service, url, blob, chunkSize, mappin
|
|
|
1988
1934
|
if (blob.size() !== status_.total) {
|
|
1989
1935
|
throw serverFileWrongSize();
|
|
1990
1936
|
}
|
|
1991
|
-
|
|
1992
|
-
|
|
1937
|
+
const bytesLeft = status_.total - status_.current;
|
|
1938
|
+
let bytesToUpload = bytesLeft;
|
|
1993
1939
|
if (chunkSize > 0) {
|
|
1994
1940
|
bytesToUpload = Math.min(bytesToUpload, chunkSize);
|
|
1995
1941
|
}
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1942
|
+
const startByte = status_.current;
|
|
1943
|
+
const endByte = startByte + bytesToUpload;
|
|
1944
|
+
let uploadCommand = '';
|
|
1999
1945
|
if (bytesToUpload === 0) {
|
|
2000
1946
|
uploadCommand = 'finalize';
|
|
2001
1947
|
}
|
|
@@ -2005,11 +1951,11 @@ function continueResumableUpload(location, service, url, blob, chunkSize, mappin
|
|
|
2005
1951
|
else {
|
|
2006
1952
|
uploadCommand = 'upload';
|
|
2007
1953
|
}
|
|
2008
|
-
|
|
1954
|
+
const headers = {
|
|
2009
1955
|
'X-Goog-Upload-Command': uploadCommand,
|
|
2010
|
-
'X-Goog-Upload-Offset':
|
|
1956
|
+
'X-Goog-Upload-Offset': `${status_.current}`
|
|
2011
1957
|
};
|
|
2012
|
-
|
|
1958
|
+
const body = blob.slice(startByte, endByte);
|
|
2013
1959
|
if (body === null) {
|
|
2014
1960
|
throw cannotSliceBlob();
|
|
2015
1961
|
}
|
|
@@ -2018,10 +1964,10 @@ function continueResumableUpload(location, service, url, blob, chunkSize, mappin
|
|
|
2018
1964
|
// the 'x-range-md5' header comes back with status code 308 responses.
|
|
2019
1965
|
// We'll only be able to bail out though, because you can't re-upload a
|
|
2020
1966
|
// range that you previously uploaded.
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
1967
|
+
const uploadStatus = checkResumeHeader_(xhr, ['active', 'final']);
|
|
1968
|
+
const newCurrent = status_.current + bytesToUpload;
|
|
1969
|
+
const size = blob.size();
|
|
1970
|
+
let metadata;
|
|
2025
1971
|
if (uploadStatus === 'final') {
|
|
2026
1972
|
metadata = metadataHandler(service, mappings)(xhr, text);
|
|
2027
1973
|
}
|
|
@@ -2030,9 +1976,9 @@ function continueResumableUpload(location, service, url, blob, chunkSize, mappin
|
|
|
2030
1976
|
}
|
|
2031
1977
|
return new ResumableUploadStatus(newCurrent, size, uploadStatus === 'final', metadata);
|
|
2032
1978
|
}
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
1979
|
+
const method = 'POST';
|
|
1980
|
+
const timeout = service.maxUploadRetryTime;
|
|
1981
|
+
const requestInfo = new RequestInfo(url, method, handler, timeout);
|
|
2036
1982
|
requestInfo.headers = headers;
|
|
2037
1983
|
requestInfo.body = body.uploadData();
|
|
2038
1984
|
requestInfo.progressCallback = progressCallback || null;
|
|
@@ -2060,7 +2006,7 @@ function continueResumableUpload(location, service, url, blob, chunkSize, mappin
|
|
|
2060
2006
|
* An event that is triggered on a task.
|
|
2061
2007
|
* @internal
|
|
2062
2008
|
*/
|
|
2063
|
-
|
|
2009
|
+
const TaskEvent = {
|
|
2064
2010
|
/**
|
|
2065
2011
|
* For this event,
|
|
2066
2012
|
* <ul>
|
|
@@ -2080,7 +2026,7 @@ var TaskEvent = {
|
|
|
2080
2026
|
* Represents the current state of a running upload.
|
|
2081
2027
|
* @internal
|
|
2082
2028
|
*/
|
|
2083
|
-
|
|
2029
|
+
const TaskState = {
|
|
2084
2030
|
/** The task is currently transferring data. */
|
|
2085
2031
|
RUNNING: 'running',
|
|
2086
2032
|
/** The task was paused by the user. */
|
|
@@ -2128,23 +2074,22 @@ function taskStateFromInternalTaskState(state) {
|
|
|
2128
2074
|
* See the License for the specific language governing permissions and
|
|
2129
2075
|
* limitations under the License.
|
|
2130
2076
|
*/
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2077
|
+
class Observer {
|
|
2078
|
+
constructor(nextOrObserver, error, complete) {
|
|
2079
|
+
const asFunctions = isFunction(nextOrObserver) || error != null || complete != null;
|
|
2134
2080
|
if (asFunctions) {
|
|
2135
2081
|
this.next = nextOrObserver;
|
|
2136
2082
|
this.error = error !== null && error !== void 0 ? error : undefined;
|
|
2137
2083
|
this.complete = complete !== null && complete !== void 0 ? complete : undefined;
|
|
2138
2084
|
}
|
|
2139
2085
|
else {
|
|
2140
|
-
|
|
2086
|
+
const observer = nextOrObserver;
|
|
2141
2087
|
this.next = observer.next;
|
|
2142
2088
|
this.error = observer.error;
|
|
2143
2089
|
this.complete = observer.complete;
|
|
2144
2090
|
}
|
|
2145
2091
|
}
|
|
2146
|
-
|
|
2147
|
-
}());
|
|
2092
|
+
}
|
|
2148
2093
|
|
|
2149
2094
|
/**
|
|
2150
2095
|
* @license
|
|
@@ -2169,13 +2114,9 @@ var Observer = /** @class */ (function () {
|
|
|
2169
2114
|
*/
|
|
2170
2115
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
2171
2116
|
function async(f) {
|
|
2172
|
-
return
|
|
2173
|
-
var argsToForward = [];
|
|
2174
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2175
|
-
argsToForward[_i] = arguments[_i];
|
|
2176
|
-
}
|
|
2117
|
+
return (...argsToForward) => {
|
|
2177
2118
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
2178
|
-
Promise.resolve().then(
|
|
2119
|
+
Promise.resolve().then(() => f(...argsToForward));
|
|
2179
2120
|
};
|
|
2180
2121
|
}
|
|
2181
2122
|
|
|
@@ -2196,40 +2137,39 @@ function async(f) {
|
|
|
2196
2137
|
* limitations under the License.
|
|
2197
2138
|
*/
|
|
2198
2139
|
/** An override for the text-based Connection. Used in tests. */
|
|
2199
|
-
|
|
2140
|
+
let textFactoryOverride = null;
|
|
2200
2141
|
/**
|
|
2201
2142
|
* Network layer for browsers. We use this instead of goog.net.XhrIo because
|
|
2202
2143
|
* goog.net.XhrIo is hyuuuuge and doesn't work in React Native on Android.
|
|
2203
2144
|
*/
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
var _this = this;
|
|
2145
|
+
class XhrConnection {
|
|
2146
|
+
constructor() {
|
|
2207
2147
|
this.sent_ = false;
|
|
2208
2148
|
this.xhr_ = new XMLHttpRequest();
|
|
2209
2149
|
this.initXhr();
|
|
2210
2150
|
this.errorCode_ = ErrorCode.NO_ERROR;
|
|
2211
|
-
this.sendPromise_ = new Promise(
|
|
2212
|
-
|
|
2213
|
-
|
|
2151
|
+
this.sendPromise_ = new Promise(resolve => {
|
|
2152
|
+
this.xhr_.addEventListener('abort', () => {
|
|
2153
|
+
this.errorCode_ = ErrorCode.ABORT;
|
|
2214
2154
|
resolve();
|
|
2215
2155
|
});
|
|
2216
|
-
|
|
2217
|
-
|
|
2156
|
+
this.xhr_.addEventListener('error', () => {
|
|
2157
|
+
this.errorCode_ = ErrorCode.NETWORK_ERROR;
|
|
2218
2158
|
resolve();
|
|
2219
2159
|
});
|
|
2220
|
-
|
|
2160
|
+
this.xhr_.addEventListener('load', () => {
|
|
2221
2161
|
resolve();
|
|
2222
2162
|
});
|
|
2223
2163
|
});
|
|
2224
2164
|
}
|
|
2225
|
-
|
|
2165
|
+
send(url, method, body, headers) {
|
|
2226
2166
|
if (this.sent_) {
|
|
2227
2167
|
throw internalError('cannot .send() more than once');
|
|
2228
2168
|
}
|
|
2229
2169
|
this.sent_ = true;
|
|
2230
2170
|
this.xhr_.open(method, url, true);
|
|
2231
2171
|
if (headers !== undefined) {
|
|
2232
|
-
for (
|
|
2172
|
+
for (const key in headers) {
|
|
2233
2173
|
if (headers.hasOwnProperty(key)) {
|
|
2234
2174
|
this.xhr_.setRequestHeader(key, headers[key].toString());
|
|
2235
2175
|
}
|
|
@@ -2242,14 +2182,14 @@ var XhrConnection = /** @class */ (function () {
|
|
|
2242
2182
|
this.xhr_.send();
|
|
2243
2183
|
}
|
|
2244
2184
|
return this.sendPromise_;
|
|
2245
|
-
}
|
|
2246
|
-
|
|
2185
|
+
}
|
|
2186
|
+
getErrorCode() {
|
|
2247
2187
|
if (!this.sent_) {
|
|
2248
2188
|
throw internalError('cannot .getErrorCode() before sending');
|
|
2249
2189
|
}
|
|
2250
2190
|
return this.errorCode_;
|
|
2251
|
-
}
|
|
2252
|
-
|
|
2191
|
+
}
|
|
2192
|
+
getStatus() {
|
|
2253
2193
|
if (!this.sent_) {
|
|
2254
2194
|
throw internalError('cannot .getStatus() before sending');
|
|
2255
2195
|
}
|
|
@@ -2259,74 +2199,58 @@ var XhrConnection = /** @class */ (function () {
|
|
|
2259
2199
|
catch (e) {
|
|
2260
2200
|
return -1;
|
|
2261
2201
|
}
|
|
2262
|
-
}
|
|
2263
|
-
|
|
2202
|
+
}
|
|
2203
|
+
getResponse() {
|
|
2264
2204
|
if (!this.sent_) {
|
|
2265
2205
|
throw internalError('cannot .getResponse() before sending');
|
|
2266
2206
|
}
|
|
2267
2207
|
return this.xhr_.response;
|
|
2268
|
-
}
|
|
2269
|
-
|
|
2208
|
+
}
|
|
2209
|
+
getErrorText() {
|
|
2270
2210
|
if (!this.sent_) {
|
|
2271
2211
|
throw internalError('cannot .getErrorText() before sending');
|
|
2272
2212
|
}
|
|
2273
2213
|
return this.xhr_.statusText;
|
|
2274
|
-
}
|
|
2214
|
+
}
|
|
2275
2215
|
/** Aborts the request. */
|
|
2276
|
-
|
|
2216
|
+
abort() {
|
|
2277
2217
|
this.xhr_.abort();
|
|
2278
|
-
}
|
|
2279
|
-
|
|
2218
|
+
}
|
|
2219
|
+
getResponseHeader(header) {
|
|
2280
2220
|
return this.xhr_.getResponseHeader(header);
|
|
2281
|
-
}
|
|
2282
|
-
|
|
2221
|
+
}
|
|
2222
|
+
addUploadProgressListener(listener) {
|
|
2283
2223
|
if (this.xhr_.upload != null) {
|
|
2284
2224
|
this.xhr_.upload.addEventListener('progress', listener);
|
|
2285
2225
|
}
|
|
2286
|
-
}
|
|
2287
|
-
|
|
2226
|
+
}
|
|
2227
|
+
removeUploadProgressListener(listener) {
|
|
2288
2228
|
if (this.xhr_.upload != null) {
|
|
2289
2229
|
this.xhr_.upload.removeEventListener('progress', listener);
|
|
2290
2230
|
}
|
|
2291
|
-
}
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
tslib.__extends(XhrTextConnection, _super);
|
|
2296
|
-
function XhrTextConnection() {
|
|
2297
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2298
|
-
}
|
|
2299
|
-
XhrTextConnection.prototype.initXhr = function () {
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
class XhrTextConnection extends XhrConnection {
|
|
2234
|
+
initXhr() {
|
|
2300
2235
|
this.xhr_.responseType = 'text';
|
|
2301
|
-
}
|
|
2302
|
-
|
|
2303
|
-
}(XhrConnection));
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2304
2238
|
function newTextConnection() {
|
|
2305
2239
|
return textFactoryOverride ? textFactoryOverride() : new XhrTextConnection();
|
|
2306
2240
|
}
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
function XhrBytesConnection() {
|
|
2310
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2311
|
-
}
|
|
2312
|
-
XhrBytesConnection.prototype.initXhr = function () {
|
|
2241
|
+
class XhrBytesConnection extends XhrConnection {
|
|
2242
|
+
initXhr() {
|
|
2313
2243
|
this.xhr_.responseType = 'arraybuffer';
|
|
2314
|
-
}
|
|
2315
|
-
|
|
2316
|
-
}(XhrConnection));
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2317
2246
|
function newBytesConnection() {
|
|
2318
2247
|
return new XhrBytesConnection();
|
|
2319
2248
|
}
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
function XhrBlobConnection() {
|
|
2323
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2324
|
-
}
|
|
2325
|
-
XhrBlobConnection.prototype.initXhr = function () {
|
|
2249
|
+
class XhrBlobConnection extends XhrConnection {
|
|
2250
|
+
initXhr() {
|
|
2326
2251
|
this.xhr_.responseType = 'blob';
|
|
2327
|
-
}
|
|
2328
|
-
|
|
2329
|
-
}(XhrConnection));
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2330
2254
|
function newBlobConnection() {
|
|
2331
2255
|
return new XhrBlobConnection();
|
|
2332
2256
|
}
|
|
@@ -2352,15 +2276,13 @@ function newBlobConnection() {
|
|
|
2352
2276
|
* upload and manage callbacks for various events.
|
|
2353
2277
|
* @internal
|
|
2354
2278
|
*/
|
|
2355
|
-
|
|
2279
|
+
class UploadTask {
|
|
2356
2280
|
/**
|
|
2357
2281
|
* @param ref - The firebaseStorage.Reference object this task came
|
|
2358
2282
|
* from, untyped to avoid cyclic dependencies.
|
|
2359
2283
|
* @param blob - The blob to upload.
|
|
2360
2284
|
*/
|
|
2361
|
-
|
|
2362
|
-
if (metadata === void 0) { metadata = null; }
|
|
2363
|
-
var _this = this;
|
|
2285
|
+
constructor(ref, blob, metadata = null) {
|
|
2364
2286
|
/**
|
|
2365
2287
|
* Number of bytes transferred so far.
|
|
2366
2288
|
*/
|
|
@@ -2380,64 +2302,62 @@ var UploadTask = /** @class */ (function () {
|
|
|
2380
2302
|
this._mappings = getMappings();
|
|
2381
2303
|
this._resumable = this._shouldDoResumable(this._blob);
|
|
2382
2304
|
this._state = "running" /* InternalTaskState.RUNNING */;
|
|
2383
|
-
this._errorHandler =
|
|
2384
|
-
|
|
2385
|
-
|
|
2305
|
+
this._errorHandler = error => {
|
|
2306
|
+
this._request = undefined;
|
|
2307
|
+
this._chunkMultiplier = 1;
|
|
2386
2308
|
if (error._codeEquals(exports.StorageErrorCode.CANCELED)) {
|
|
2387
|
-
|
|
2388
|
-
|
|
2309
|
+
this._needToFetchStatus = true;
|
|
2310
|
+
this.completeTransitions_();
|
|
2389
2311
|
}
|
|
2390
2312
|
else {
|
|
2391
|
-
|
|
2313
|
+
const backoffExpired = this.isExponentialBackoffExpired();
|
|
2392
2314
|
if (isRetryStatusCode(error.status, [])) {
|
|
2393
2315
|
if (backoffExpired) {
|
|
2394
2316
|
error = retryLimitExceeded();
|
|
2395
2317
|
}
|
|
2396
2318
|
else {
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2319
|
+
this.sleepTime = Math.max(this.sleepTime * 2, DEFAULT_MIN_SLEEP_TIME_MILLIS);
|
|
2320
|
+
this._needToFetchStatus = true;
|
|
2321
|
+
this.completeTransitions_();
|
|
2400
2322
|
return;
|
|
2401
2323
|
}
|
|
2402
2324
|
}
|
|
2403
|
-
|
|
2404
|
-
|
|
2325
|
+
this._error = error;
|
|
2326
|
+
this._transition("error" /* InternalTaskState.ERROR */);
|
|
2405
2327
|
}
|
|
2406
2328
|
};
|
|
2407
|
-
this._metadataErrorHandler =
|
|
2408
|
-
|
|
2329
|
+
this._metadataErrorHandler = error => {
|
|
2330
|
+
this._request = undefined;
|
|
2409
2331
|
if (error._codeEquals(exports.StorageErrorCode.CANCELED)) {
|
|
2410
|
-
|
|
2332
|
+
this.completeTransitions_();
|
|
2411
2333
|
}
|
|
2412
2334
|
else {
|
|
2413
|
-
|
|
2414
|
-
|
|
2335
|
+
this._error = error;
|
|
2336
|
+
this._transition("error" /* InternalTaskState.ERROR */);
|
|
2415
2337
|
}
|
|
2416
2338
|
};
|
|
2417
2339
|
this.sleepTime = 0;
|
|
2418
2340
|
this.maxSleepTime = this._ref.storage.maxUploadRetryTime;
|
|
2419
|
-
this._promise = new Promise(
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2341
|
+
this._promise = new Promise((resolve, reject) => {
|
|
2342
|
+
this._resolve = resolve;
|
|
2343
|
+
this._reject = reject;
|
|
2344
|
+
this._start();
|
|
2423
2345
|
});
|
|
2424
2346
|
// Prevent uncaught rejections on the internal promise from bubbling out
|
|
2425
2347
|
// to the top level with a dummy handler.
|
|
2426
|
-
this._promise.then(null,
|
|
2348
|
+
this._promise.then(null, () => { });
|
|
2427
2349
|
}
|
|
2428
|
-
|
|
2350
|
+
isExponentialBackoffExpired() {
|
|
2429
2351
|
return this.sleepTime > this.maxSleepTime;
|
|
2430
|
-
}
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
UploadTask.prototype._shouldDoResumable = function (blob) {
|
|
2352
|
+
}
|
|
2353
|
+
_makeProgressCallback() {
|
|
2354
|
+
const sizeBefore = this._transferred;
|
|
2355
|
+
return loaded => this._updateProgress(sizeBefore + loaded);
|
|
2356
|
+
}
|
|
2357
|
+
_shouldDoResumable(blob) {
|
|
2437
2358
|
return blob.size() > 256 * 1024;
|
|
2438
|
-
}
|
|
2439
|
-
|
|
2440
|
-
var _this = this;
|
|
2359
|
+
}
|
|
2360
|
+
_start() {
|
|
2441
2361
|
if (this._state !== "running" /* InternalTaskState.RUNNING */) {
|
|
2442
2362
|
// This can happen if someone pauses us in a resume callback, for example.
|
|
2443
2363
|
return;
|
|
@@ -2459,9 +2379,9 @@ var UploadTask = /** @class */ (function () {
|
|
|
2459
2379
|
this._fetchMetadata();
|
|
2460
2380
|
}
|
|
2461
2381
|
else {
|
|
2462
|
-
this.pendingTimeout = setTimeout(
|
|
2463
|
-
|
|
2464
|
-
|
|
2382
|
+
this.pendingTimeout = setTimeout(() => {
|
|
2383
|
+
this.pendingTimeout = undefined;
|
|
2384
|
+
this._continueUpload();
|
|
2465
2385
|
}, this.sleepTime);
|
|
2466
2386
|
}
|
|
2467
2387
|
}
|
|
@@ -2470,133 +2390,126 @@ var UploadTask = /** @class */ (function () {
|
|
|
2470
2390
|
else {
|
|
2471
2391
|
this._oneShotUpload();
|
|
2472
2392
|
}
|
|
2473
|
-
}
|
|
2474
|
-
|
|
2475
|
-
var _this = this;
|
|
2393
|
+
}
|
|
2394
|
+
_resolveToken(callback) {
|
|
2476
2395
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
2477
2396
|
Promise.all([
|
|
2478
2397
|
this._ref.storage._getAuthToken(),
|
|
2479
2398
|
this._ref.storage._getAppCheckToken()
|
|
2480
|
-
]).then(
|
|
2481
|
-
|
|
2482
|
-
switch (_this._state) {
|
|
2399
|
+
]).then(([authToken, appCheckToken]) => {
|
|
2400
|
+
switch (this._state) {
|
|
2483
2401
|
case "running" /* InternalTaskState.RUNNING */:
|
|
2484
2402
|
callback(authToken, appCheckToken);
|
|
2485
2403
|
break;
|
|
2486
2404
|
case "canceling" /* InternalTaskState.CANCELING */:
|
|
2487
|
-
|
|
2405
|
+
this._transition("canceled" /* InternalTaskState.CANCELED */);
|
|
2488
2406
|
break;
|
|
2489
2407
|
case "pausing" /* InternalTaskState.PAUSING */:
|
|
2490
|
-
|
|
2408
|
+
this._transition("paused" /* InternalTaskState.PAUSED */);
|
|
2491
2409
|
break;
|
|
2492
2410
|
}
|
|
2493
2411
|
});
|
|
2494
|
-
}
|
|
2412
|
+
}
|
|
2495
2413
|
// TODO(andysoto): assert false
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
}, _this._errorHandler);
|
|
2414
|
+
_createResumable() {
|
|
2415
|
+
this._resolveToken((authToken, appCheckToken) => {
|
|
2416
|
+
const requestInfo = createResumableUpload(this._ref.storage, this._ref._location, this._mappings, this._blob, this._metadata);
|
|
2417
|
+
const createRequest = this._ref.storage._makeRequest(requestInfo, newTextConnection, authToken, appCheckToken);
|
|
2418
|
+
this._request = createRequest;
|
|
2419
|
+
createRequest.getPromise().then((url) => {
|
|
2420
|
+
this._request = undefined;
|
|
2421
|
+
this._uploadUrl = url;
|
|
2422
|
+
this._needToFetchStatus = false;
|
|
2423
|
+
this.completeTransitions_();
|
|
2424
|
+
}, this._errorHandler);
|
|
2508
2425
|
});
|
|
2509
|
-
}
|
|
2510
|
-
|
|
2511
|
-
var _this = this;
|
|
2426
|
+
}
|
|
2427
|
+
_fetchStatus() {
|
|
2512
2428
|
// TODO(andysoto): assert(this.uploadUrl_ !== null);
|
|
2513
|
-
|
|
2514
|
-
this._resolveToken(
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
statusRequest.getPromise().then(
|
|
2429
|
+
const url = this._uploadUrl;
|
|
2430
|
+
this._resolveToken((authToken, appCheckToken) => {
|
|
2431
|
+
const requestInfo = getResumableUploadStatus(this._ref.storage, this._ref._location, url, this._blob);
|
|
2432
|
+
const statusRequest = this._ref.storage._makeRequest(requestInfo, newTextConnection, authToken, appCheckToken);
|
|
2433
|
+
this._request = statusRequest;
|
|
2434
|
+
statusRequest.getPromise().then(status => {
|
|
2519
2435
|
status = status;
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2436
|
+
this._request = undefined;
|
|
2437
|
+
this._updateProgress(status.current);
|
|
2438
|
+
this._needToFetchStatus = false;
|
|
2523
2439
|
if (status.finalized) {
|
|
2524
|
-
|
|
2440
|
+
this._needToFetchMetadata = true;
|
|
2525
2441
|
}
|
|
2526
|
-
|
|
2527
|
-
},
|
|
2442
|
+
this.completeTransitions_();
|
|
2443
|
+
}, this._errorHandler);
|
|
2528
2444
|
});
|
|
2529
|
-
}
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
var status = new ResumableUploadStatus(this._transferred, this._blob.size());
|
|
2445
|
+
}
|
|
2446
|
+
_continueUpload() {
|
|
2447
|
+
const chunkSize = RESUMABLE_UPLOAD_CHUNK_SIZE * this._chunkMultiplier;
|
|
2448
|
+
const status = new ResumableUploadStatus(this._transferred, this._blob.size());
|
|
2534
2449
|
// TODO(andysoto): assert(this.uploadUrl_ !== null);
|
|
2535
|
-
|
|
2536
|
-
this._resolveToken(
|
|
2537
|
-
|
|
2450
|
+
const url = this._uploadUrl;
|
|
2451
|
+
this._resolveToken((authToken, appCheckToken) => {
|
|
2452
|
+
let requestInfo;
|
|
2538
2453
|
try {
|
|
2539
|
-
requestInfo = continueResumableUpload(
|
|
2454
|
+
requestInfo = continueResumableUpload(this._ref._location, this._ref.storage, url, this._blob, chunkSize, this._mappings, status, this._makeProgressCallback());
|
|
2540
2455
|
}
|
|
2541
2456
|
catch (e) {
|
|
2542
|
-
|
|
2543
|
-
|
|
2457
|
+
this._error = e;
|
|
2458
|
+
this._transition("error" /* InternalTaskState.ERROR */);
|
|
2544
2459
|
return;
|
|
2545
2460
|
}
|
|
2546
|
-
|
|
2461
|
+
const uploadRequest = this._ref.storage._makeRequest(requestInfo, newTextConnection, authToken, appCheckToken,
|
|
2547
2462
|
/*retry=*/ false // Upload requests should not be retried as each retry should be preceded by another query request. Which is handled in this file.
|
|
2548
2463
|
);
|
|
2549
|
-
|
|
2550
|
-
uploadRequest.getPromise().then(
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2464
|
+
this._request = uploadRequest;
|
|
2465
|
+
uploadRequest.getPromise().then((newStatus) => {
|
|
2466
|
+
this._increaseMultiplier();
|
|
2467
|
+
this._request = undefined;
|
|
2468
|
+
this._updateProgress(newStatus.current);
|
|
2554
2469
|
if (newStatus.finalized) {
|
|
2555
|
-
|
|
2556
|
-
|
|
2470
|
+
this._metadata = newStatus.metadata;
|
|
2471
|
+
this._transition("success" /* InternalTaskState.SUCCESS */);
|
|
2557
2472
|
}
|
|
2558
2473
|
else {
|
|
2559
|
-
|
|
2474
|
+
this.completeTransitions_();
|
|
2560
2475
|
}
|
|
2561
|
-
},
|
|
2476
|
+
}, this._errorHandler);
|
|
2562
2477
|
});
|
|
2563
|
-
}
|
|
2564
|
-
|
|
2565
|
-
|
|
2478
|
+
}
|
|
2479
|
+
_increaseMultiplier() {
|
|
2480
|
+
const currentSize = RESUMABLE_UPLOAD_CHUNK_SIZE * this._chunkMultiplier;
|
|
2566
2481
|
// Max chunk size is 32M.
|
|
2567
2482
|
if (currentSize * 2 < 32 * 1024 * 1024) {
|
|
2568
2483
|
this._chunkMultiplier *= 2;
|
|
2569
2484
|
}
|
|
2570
|
-
}
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
}, _this._metadataErrorHandler);
|
|
2485
|
+
}
|
|
2486
|
+
_fetchMetadata() {
|
|
2487
|
+
this._resolveToken((authToken, appCheckToken) => {
|
|
2488
|
+
const requestInfo = getMetadata$2(this._ref.storage, this._ref._location, this._mappings);
|
|
2489
|
+
const metadataRequest = this._ref.storage._makeRequest(requestInfo, newTextConnection, authToken, appCheckToken);
|
|
2490
|
+
this._request = metadataRequest;
|
|
2491
|
+
metadataRequest.getPromise().then(metadata => {
|
|
2492
|
+
this._request = undefined;
|
|
2493
|
+
this._metadata = metadata;
|
|
2494
|
+
this._transition("success" /* InternalTaskState.SUCCESS */);
|
|
2495
|
+
}, this._metadataErrorHandler);
|
|
2582
2496
|
});
|
|
2583
|
-
}
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
}, _this._errorHandler);
|
|
2497
|
+
}
|
|
2498
|
+
_oneShotUpload() {
|
|
2499
|
+
this._resolveToken((authToken, appCheckToken) => {
|
|
2500
|
+
const requestInfo = multipartUpload(this._ref.storage, this._ref._location, this._mappings, this._blob, this._metadata);
|
|
2501
|
+
const multipartRequest = this._ref.storage._makeRequest(requestInfo, newTextConnection, authToken, appCheckToken);
|
|
2502
|
+
this._request = multipartRequest;
|
|
2503
|
+
multipartRequest.getPromise().then(metadata => {
|
|
2504
|
+
this._request = undefined;
|
|
2505
|
+
this._metadata = metadata;
|
|
2506
|
+
this._updateProgress(this._blob.size());
|
|
2507
|
+
this._transition("success" /* InternalTaskState.SUCCESS */);
|
|
2508
|
+
}, this._errorHandler);
|
|
2596
2509
|
});
|
|
2597
|
-
}
|
|
2598
|
-
|
|
2599
|
-
|
|
2510
|
+
}
|
|
2511
|
+
_updateProgress(transferred) {
|
|
2512
|
+
const old = this._transferred;
|
|
2600
2513
|
this._transferred = transferred;
|
|
2601
2514
|
// A progress update can make the "transferred" value smaller (e.g. a
|
|
2602
2515
|
// partial upload not completed by server, after which the "transferred"
|
|
@@ -2604,8 +2517,8 @@ var UploadTask = /** @class */ (function () {
|
|
|
2604
2517
|
if (this._transferred !== old) {
|
|
2605
2518
|
this._notifyObservers();
|
|
2606
2519
|
}
|
|
2607
|
-
}
|
|
2608
|
-
|
|
2520
|
+
}
|
|
2521
|
+
_transition(state) {
|
|
2609
2522
|
if (this._state === state) {
|
|
2610
2523
|
return;
|
|
2611
2524
|
}
|
|
@@ -2629,7 +2542,7 @@ var UploadTask = /** @class */ (function () {
|
|
|
2629
2542
|
// TODO(andysoto):
|
|
2630
2543
|
// assert(this.state_ === InternalTaskState.PAUSED ||
|
|
2631
2544
|
// this.state_ === InternalTaskState.PAUSING);
|
|
2632
|
-
|
|
2545
|
+
const wasPaused = this._state === "paused" /* InternalTaskState.PAUSED */;
|
|
2633
2546
|
this._state = state;
|
|
2634
2547
|
if (wasPaused) {
|
|
2635
2548
|
this._notifyObservers();
|
|
@@ -2667,8 +2580,8 @@ var UploadTask = /** @class */ (function () {
|
|
|
2667
2580
|
this._notifyObservers();
|
|
2668
2581
|
break;
|
|
2669
2582
|
}
|
|
2670
|
-
}
|
|
2671
|
-
|
|
2583
|
+
}
|
|
2584
|
+
completeTransitions_() {
|
|
2672
2585
|
switch (this._state) {
|
|
2673
2586
|
case "pausing" /* InternalTaskState.PAUSING */:
|
|
2674
2587
|
this._transition("paused" /* InternalTaskState.PAUSED */);
|
|
@@ -2680,25 +2593,21 @@ var UploadTask = /** @class */ (function () {
|
|
|
2680
2593
|
this._start();
|
|
2681
2594
|
break;
|
|
2682
2595
|
}
|
|
2683
|
-
}
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
},
|
|
2699
|
-
enumerable: false,
|
|
2700
|
-
configurable: true
|
|
2701
|
-
});
|
|
2596
|
+
}
|
|
2597
|
+
/**
|
|
2598
|
+
* A snapshot of the current task state.
|
|
2599
|
+
*/
|
|
2600
|
+
get snapshot() {
|
|
2601
|
+
const externalState = taskStateFromInternalTaskState(this._state);
|
|
2602
|
+
return {
|
|
2603
|
+
bytesTransferred: this._transferred,
|
|
2604
|
+
totalBytes: this._blob.size(),
|
|
2605
|
+
state: externalState,
|
|
2606
|
+
metadata: this._metadata,
|
|
2607
|
+
task: this,
|
|
2608
|
+
ref: this._ref
|
|
2609
|
+
};
|
|
2610
|
+
}
|
|
2702
2611
|
/**
|
|
2703
2612
|
* Adds a callback for an event.
|
|
2704
2613
|
* @param type - The type of event to listen for.
|
|
@@ -2716,66 +2625,64 @@ var UploadTask = /** @class */ (function () {
|
|
|
2716
2625
|
* argument is passed, returns a function you can call to unregister the
|
|
2717
2626
|
* callbacks.
|
|
2718
2627
|
*/
|
|
2719
|
-
|
|
2720
|
-
var _this = this;
|
|
2628
|
+
on(type, nextOrObserver, error, completed) {
|
|
2721
2629
|
// Note: `type` isn't being used. Its type is also incorrect. TaskEvent should not be a string.
|
|
2722
|
-
|
|
2630
|
+
const observer = new Observer(nextOrObserver || undefined, error || undefined, completed || undefined);
|
|
2723
2631
|
this._addObserver(observer);
|
|
2724
|
-
return
|
|
2725
|
-
|
|
2632
|
+
return () => {
|
|
2633
|
+
this._removeObserver(observer);
|
|
2726
2634
|
};
|
|
2727
|
-
}
|
|
2635
|
+
}
|
|
2728
2636
|
/**
|
|
2729
2637
|
* This object behaves like a Promise, and resolves with its snapshot data
|
|
2730
2638
|
* when the upload completes.
|
|
2731
2639
|
* @param onFulfilled - The fulfillment callback. Promise chaining works as normal.
|
|
2732
2640
|
* @param onRejected - The rejection callback.
|
|
2733
2641
|
*/
|
|
2734
|
-
|
|
2642
|
+
then(onFulfilled, onRejected) {
|
|
2735
2643
|
// These casts are needed so that TypeScript can infer the types of the
|
|
2736
2644
|
// resulting Promise.
|
|
2737
2645
|
return this._promise.then(onFulfilled, onRejected);
|
|
2738
|
-
}
|
|
2646
|
+
}
|
|
2739
2647
|
/**
|
|
2740
2648
|
* Equivalent to calling `then(null, onRejected)`.
|
|
2741
2649
|
*/
|
|
2742
|
-
|
|
2650
|
+
catch(onRejected) {
|
|
2743
2651
|
return this.then(null, onRejected);
|
|
2744
|
-
}
|
|
2652
|
+
}
|
|
2745
2653
|
/**
|
|
2746
2654
|
* Adds the given observer.
|
|
2747
2655
|
*/
|
|
2748
|
-
|
|
2656
|
+
_addObserver(observer) {
|
|
2749
2657
|
this._observers.push(observer);
|
|
2750
2658
|
this._notifyObserver(observer);
|
|
2751
|
-
}
|
|
2659
|
+
}
|
|
2752
2660
|
/**
|
|
2753
2661
|
* Removes the given observer.
|
|
2754
2662
|
*/
|
|
2755
|
-
|
|
2756
|
-
|
|
2663
|
+
_removeObserver(observer) {
|
|
2664
|
+
const i = this._observers.indexOf(observer);
|
|
2757
2665
|
if (i !== -1) {
|
|
2758
2666
|
this._observers.splice(i, 1);
|
|
2759
2667
|
}
|
|
2760
|
-
}
|
|
2761
|
-
|
|
2762
|
-
var _this = this;
|
|
2668
|
+
}
|
|
2669
|
+
_notifyObservers() {
|
|
2763
2670
|
this._finishPromise();
|
|
2764
|
-
|
|
2765
|
-
observers.forEach(
|
|
2766
|
-
|
|
2671
|
+
const observers = this._observers.slice();
|
|
2672
|
+
observers.forEach(observer => {
|
|
2673
|
+
this._notifyObserver(observer);
|
|
2767
2674
|
});
|
|
2768
|
-
}
|
|
2769
|
-
|
|
2675
|
+
}
|
|
2676
|
+
_finishPromise() {
|
|
2770
2677
|
if (this._resolve !== undefined) {
|
|
2771
|
-
|
|
2678
|
+
let triggered = true;
|
|
2772
2679
|
switch (taskStateFromInternalTaskState(this._state)) {
|
|
2773
2680
|
case TaskState.SUCCESS:
|
|
2774
2681
|
async(this._resolve.bind(null, this.snapshot))();
|
|
2775
2682
|
break;
|
|
2776
2683
|
case TaskState.CANCELED:
|
|
2777
2684
|
case TaskState.ERROR:
|
|
2778
|
-
|
|
2685
|
+
const toCall = this._reject;
|
|
2779
2686
|
async(toCall.bind(null, this._error))();
|
|
2780
2687
|
break;
|
|
2781
2688
|
default:
|
|
@@ -2787,9 +2694,9 @@ var UploadTask = /** @class */ (function () {
|
|
|
2787
2694
|
this._reject = undefined;
|
|
2788
2695
|
}
|
|
2789
2696
|
}
|
|
2790
|
-
}
|
|
2791
|
-
|
|
2792
|
-
|
|
2697
|
+
}
|
|
2698
|
+
_notifyObserver(observer) {
|
|
2699
|
+
const externalState = taskStateFromInternalTaskState(this._state);
|
|
2793
2700
|
switch (externalState) {
|
|
2794
2701
|
case TaskState.RUNNING:
|
|
2795
2702
|
case TaskState.PAUSED:
|
|
@@ -2814,45 +2721,44 @@ var UploadTask = /** @class */ (function () {
|
|
|
2814
2721
|
async(observer.error.bind(observer, this._error))();
|
|
2815
2722
|
}
|
|
2816
2723
|
}
|
|
2817
|
-
}
|
|
2724
|
+
}
|
|
2818
2725
|
/**
|
|
2819
2726
|
* Resumes a paused task. Has no effect on a currently running or failed task.
|
|
2820
2727
|
* @returns True if the operation took effect, false if ignored.
|
|
2821
2728
|
*/
|
|
2822
|
-
|
|
2823
|
-
|
|
2729
|
+
resume() {
|
|
2730
|
+
const valid = this._state === "paused" /* InternalTaskState.PAUSED */ ||
|
|
2824
2731
|
this._state === "pausing" /* InternalTaskState.PAUSING */;
|
|
2825
2732
|
if (valid) {
|
|
2826
2733
|
this._transition("running" /* InternalTaskState.RUNNING */);
|
|
2827
2734
|
}
|
|
2828
2735
|
return valid;
|
|
2829
|
-
}
|
|
2736
|
+
}
|
|
2830
2737
|
/**
|
|
2831
2738
|
* Pauses a currently running task. Has no effect on a paused or failed task.
|
|
2832
2739
|
* @returns True if the operation took effect, false if ignored.
|
|
2833
2740
|
*/
|
|
2834
|
-
|
|
2835
|
-
|
|
2741
|
+
pause() {
|
|
2742
|
+
const valid = this._state === "running" /* InternalTaskState.RUNNING */;
|
|
2836
2743
|
if (valid) {
|
|
2837
2744
|
this._transition("pausing" /* InternalTaskState.PAUSING */);
|
|
2838
2745
|
}
|
|
2839
2746
|
return valid;
|
|
2840
|
-
}
|
|
2747
|
+
}
|
|
2841
2748
|
/**
|
|
2842
2749
|
* Cancels a currently running or paused task. Has no effect on a complete or
|
|
2843
2750
|
* failed task.
|
|
2844
2751
|
* @returns True if the operation took effect, false if ignored.
|
|
2845
2752
|
*/
|
|
2846
|
-
|
|
2847
|
-
|
|
2753
|
+
cancel() {
|
|
2754
|
+
const valid = this._state === "running" /* InternalTaskState.RUNNING */ ||
|
|
2848
2755
|
this._state === "pausing" /* InternalTaskState.PAUSING */;
|
|
2849
2756
|
if (valid) {
|
|
2850
2757
|
this._transition("canceling" /* InternalTaskState.CANCELING */);
|
|
2851
2758
|
}
|
|
2852
2759
|
return valid;
|
|
2853
|
-
}
|
|
2854
|
-
|
|
2855
|
-
}());
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2856
2762
|
|
|
2857
2763
|
/**
|
|
2858
2764
|
* @license
|
|
@@ -2882,8 +2788,8 @@ var UploadTask = /** @class */ (function () {
|
|
|
2882
2788
|
* format. If no value is passed, the storage object will use a URL based on
|
|
2883
2789
|
* the project ID of the base firebase.App instance.
|
|
2884
2790
|
*/
|
|
2885
|
-
|
|
2886
|
-
|
|
2791
|
+
class Reference {
|
|
2792
|
+
constructor(_service, location) {
|
|
2887
2793
|
this._service = _service;
|
|
2888
2794
|
if (location instanceof Location) {
|
|
2889
2795
|
this._location = location;
|
|
@@ -2897,105 +2803,78 @@ var Reference = /** @class */ (function () {
|
|
|
2897
2803
|
* in the form gs://<bucket>/<object-path>
|
|
2898
2804
|
* @override
|
|
2899
2805
|
*/
|
|
2900
|
-
|
|
2806
|
+
toString() {
|
|
2901
2807
|
return 'gs://' + this._location.bucket + '/' + this._location.path;
|
|
2902
|
-
}
|
|
2903
|
-
|
|
2808
|
+
}
|
|
2809
|
+
_newRef(service, location) {
|
|
2904
2810
|
return new Reference(service, location);
|
|
2905
|
-
}
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
* The `StorageService` instance this `StorageReference` is associated with.
|
|
2951
|
-
*/
|
|
2952
|
-
get: function () {
|
|
2953
|
-
return this._service;
|
|
2954
|
-
},
|
|
2955
|
-
enumerable: false,
|
|
2956
|
-
configurable: true
|
|
2957
|
-
});
|
|
2958
|
-
Object.defineProperty(Reference.prototype, "parent", {
|
|
2959
|
-
/**
|
|
2960
|
-
* A `StorageReference` pointing to the parent location of this `StorageReference`, or null if
|
|
2961
|
-
* this reference is the root.
|
|
2962
|
-
*/
|
|
2963
|
-
get: function () {
|
|
2964
|
-
var newPath = parent(this._location.path);
|
|
2965
|
-
if (newPath === null) {
|
|
2966
|
-
return null;
|
|
2967
|
-
}
|
|
2968
|
-
var location = new Location(this._location.bucket, newPath);
|
|
2969
|
-
return new Reference(this._service, location);
|
|
2970
|
-
},
|
|
2971
|
-
enumerable: false,
|
|
2972
|
-
configurable: true
|
|
2973
|
-
});
|
|
2811
|
+
}
|
|
2812
|
+
/**
|
|
2813
|
+
* A reference to the root of this object's bucket.
|
|
2814
|
+
*/
|
|
2815
|
+
get root() {
|
|
2816
|
+
const location = new Location(this._location.bucket, '');
|
|
2817
|
+
return this._newRef(this._service, location);
|
|
2818
|
+
}
|
|
2819
|
+
/**
|
|
2820
|
+
* The name of the bucket containing this reference's object.
|
|
2821
|
+
*/
|
|
2822
|
+
get bucket() {
|
|
2823
|
+
return this._location.bucket;
|
|
2824
|
+
}
|
|
2825
|
+
/**
|
|
2826
|
+
* The full path of this object.
|
|
2827
|
+
*/
|
|
2828
|
+
get fullPath() {
|
|
2829
|
+
return this._location.path;
|
|
2830
|
+
}
|
|
2831
|
+
/**
|
|
2832
|
+
* The short name of this object, which is the last component of the full path.
|
|
2833
|
+
* For example, if fullPath is 'full/path/image.png', name is 'image.png'.
|
|
2834
|
+
*/
|
|
2835
|
+
get name() {
|
|
2836
|
+
return lastComponent(this._location.path);
|
|
2837
|
+
}
|
|
2838
|
+
/**
|
|
2839
|
+
* The `StorageService` instance this `StorageReference` is associated with.
|
|
2840
|
+
*/
|
|
2841
|
+
get storage() {
|
|
2842
|
+
return this._service;
|
|
2843
|
+
}
|
|
2844
|
+
/**
|
|
2845
|
+
* A `StorageReference` pointing to the parent location of this `StorageReference`, or null if
|
|
2846
|
+
* this reference is the root.
|
|
2847
|
+
*/
|
|
2848
|
+
get parent() {
|
|
2849
|
+
const newPath = parent(this._location.path);
|
|
2850
|
+
if (newPath === null) {
|
|
2851
|
+
return null;
|
|
2852
|
+
}
|
|
2853
|
+
const location = new Location(this._location.bucket, newPath);
|
|
2854
|
+
return new Reference(this._service, location);
|
|
2855
|
+
}
|
|
2974
2856
|
/**
|
|
2975
2857
|
* Utility function to throw an error in methods that do not accept a root reference.
|
|
2976
2858
|
*/
|
|
2977
|
-
|
|
2859
|
+
_throwIfRoot(name) {
|
|
2978
2860
|
if (this._location.path === '') {
|
|
2979
2861
|
throw invalidRootOperation(name);
|
|
2980
2862
|
}
|
|
2981
|
-
}
|
|
2982
|
-
|
|
2983
|
-
}());
|
|
2863
|
+
}
|
|
2864
|
+
}
|
|
2984
2865
|
/**
|
|
2985
2866
|
* Download the bytes at the object's location.
|
|
2986
2867
|
* @returns A Promise containing the downloaded bytes.
|
|
2987
2868
|
*/
|
|
2988
2869
|
function getBytesInternal(ref, maxDownloadSizeBytes) {
|
|
2989
2870
|
ref._throwIfRoot('getBytes');
|
|
2990
|
-
|
|
2871
|
+
const requestInfo = getBytes$1(ref.storage, ref._location, maxDownloadSizeBytes);
|
|
2991
2872
|
return ref.storage
|
|
2992
2873
|
.makeRequestWithTokens(requestInfo, newBytesConnection)
|
|
2993
|
-
.then(
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
: bytes;
|
|
2998
|
-
});
|
|
2874
|
+
.then(bytes => maxDownloadSizeBytes !== undefined
|
|
2875
|
+
? // GCS may not honor the Range header for small files
|
|
2876
|
+
bytes.slice(0, maxDownloadSizeBytes)
|
|
2877
|
+
: bytes);
|
|
2999
2878
|
}
|
|
3000
2879
|
/**
|
|
3001
2880
|
* Download the bytes at the object's location.
|
|
@@ -3003,15 +2882,13 @@ function getBytesInternal(ref, maxDownloadSizeBytes) {
|
|
|
3003
2882
|
*/
|
|
3004
2883
|
function getBlobInternal(ref, maxDownloadSizeBytes) {
|
|
3005
2884
|
ref._throwIfRoot('getBlob');
|
|
3006
|
-
|
|
2885
|
+
const requestInfo = getBytes$1(ref.storage, ref._location, maxDownloadSizeBytes);
|
|
3007
2886
|
return ref.storage
|
|
3008
2887
|
.makeRequestWithTokens(requestInfo, newBlobConnection)
|
|
3009
|
-
.then(
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
: blob;
|
|
3014
|
-
});
|
|
2888
|
+
.then(blob => maxDownloadSizeBytes !== undefined
|
|
2889
|
+
? // GCS may not honor the Range header for small files
|
|
2890
|
+
blob.slice(0, maxDownloadSizeBytes)
|
|
2891
|
+
: blob);
|
|
3015
2892
|
}
|
|
3016
2893
|
/**
|
|
3017
2894
|
* Uploads data to this object's location.
|
|
@@ -3024,13 +2901,13 @@ function getBlobInternal(ref, maxDownloadSizeBytes) {
|
|
|
3024
2901
|
*/
|
|
3025
2902
|
function uploadBytes$1(ref, data, metadata) {
|
|
3026
2903
|
ref._throwIfRoot('uploadBytes');
|
|
3027
|
-
|
|
2904
|
+
const requestInfo = multipartUpload(ref.storage, ref._location, getMappings(), new FbsBlob(data, true), metadata);
|
|
3028
2905
|
return ref.storage
|
|
3029
2906
|
.makeRequestWithTokens(requestInfo, newTextConnection)
|
|
3030
|
-
.then(
|
|
2907
|
+
.then(finalMetadata => {
|
|
3031
2908
|
return {
|
|
3032
2909
|
metadata: finalMetadata,
|
|
3033
|
-
ref
|
|
2910
|
+
ref
|
|
3034
2911
|
};
|
|
3035
2912
|
});
|
|
3036
2913
|
}
|
|
@@ -3057,11 +2934,10 @@ function uploadBytesResumable$1(ref, data, metadata) {
|
|
|
3057
2934
|
* @param metadata - Metadata for the newly uploaded string.
|
|
3058
2935
|
* @returns A Promise containing an UploadResult
|
|
3059
2936
|
*/
|
|
3060
|
-
function uploadString$1(ref, value, format, metadata) {
|
|
3061
|
-
if (format === void 0) { format = StringFormat.RAW; }
|
|
2937
|
+
function uploadString$1(ref, value, format = StringFormat.RAW, metadata) {
|
|
3062
2938
|
ref._throwIfRoot('uploadString');
|
|
3063
|
-
|
|
3064
|
-
|
|
2939
|
+
const data = dataFromString(format, value);
|
|
2940
|
+
const metadataClone = Object.assign({}, metadata);
|
|
3065
2941
|
if (metadataClone['contentType'] == null && data.contentType != null) {
|
|
3066
2942
|
metadataClone['contentType'] = data.contentType;
|
|
3067
2943
|
}
|
|
@@ -3087,11 +2963,11 @@ function uploadString$1(ref, value, format, metadata) {
|
|
|
3087
2963
|
* folder. `nextPageToken` is never returned.
|
|
3088
2964
|
*/
|
|
3089
2965
|
function listAll$1(ref) {
|
|
3090
|
-
|
|
2966
|
+
const accumulator = {
|
|
3091
2967
|
prefixes: [],
|
|
3092
2968
|
items: []
|
|
3093
2969
|
};
|
|
3094
|
-
return listAllHelper(ref, accumulator).then(
|
|
2970
|
+
return listAllHelper(ref, accumulator).then(() => accumulator);
|
|
3095
2971
|
}
|
|
3096
2972
|
/**
|
|
3097
2973
|
* Separated from listAll because async functions can't use "arguments".
|
|
@@ -3099,31 +2975,17 @@ function listAll$1(ref) {
|
|
|
3099
2975
|
* @param accumulator
|
|
3100
2976
|
* @param pageToken
|
|
3101
2977
|
*/
|
|
3102
|
-
function listAllHelper(ref, accumulator, pageToken) {
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
return [4 /*yield*/, list$1(ref, opt)];
|
|
3114
|
-
case 1:
|
|
3115
|
-
nextPage = _c.sent();
|
|
3116
|
-
(_a = accumulator.prefixes).push.apply(_a, nextPage.prefixes);
|
|
3117
|
-
(_b = accumulator.items).push.apply(_b, nextPage.items);
|
|
3118
|
-
if (!(nextPage.nextPageToken != null)) return [3 /*break*/, 3];
|
|
3119
|
-
return [4 /*yield*/, listAllHelper(ref, accumulator, nextPage.nextPageToken)];
|
|
3120
|
-
case 2:
|
|
3121
|
-
_c.sent();
|
|
3122
|
-
_c.label = 3;
|
|
3123
|
-
case 3: return [2 /*return*/];
|
|
3124
|
-
}
|
|
3125
|
-
});
|
|
3126
|
-
});
|
|
2978
|
+
async function listAllHelper(ref, accumulator, pageToken) {
|
|
2979
|
+
const opt = {
|
|
2980
|
+
// maxResults is 1000 by default.
|
|
2981
|
+
pageToken
|
|
2982
|
+
};
|
|
2983
|
+
const nextPage = await list$1(ref, opt);
|
|
2984
|
+
accumulator.prefixes.push(...nextPage.prefixes);
|
|
2985
|
+
accumulator.items.push(...nextPage.items);
|
|
2986
|
+
if (nextPage.nextPageToken != null) {
|
|
2987
|
+
await listAllHelper(ref, accumulator, nextPage.nextPageToken);
|
|
2988
|
+
}
|
|
3127
2989
|
}
|
|
3128
2990
|
/**
|
|
3129
2991
|
* List items (files) and prefixes (folders) under this storage reference.
|
|
@@ -3155,8 +3017,8 @@ function list$1(ref, options) {
|
|
|
3155
3017
|
/* maxValue= */ 1000, options.maxResults);
|
|
3156
3018
|
}
|
|
3157
3019
|
}
|
|
3158
|
-
|
|
3159
|
-
|
|
3020
|
+
const op = options || {};
|
|
3021
|
+
const requestInfo = list$2(ref.storage, ref._location,
|
|
3160
3022
|
/*delimiter= */ '/', op.pageToken, op.maxResults);
|
|
3161
3023
|
return ref.storage.makeRequestWithTokens(requestInfo, newTextConnection);
|
|
3162
3024
|
}
|
|
@@ -3169,7 +3031,7 @@ function list$1(ref, options) {
|
|
|
3169
3031
|
*/
|
|
3170
3032
|
function getMetadata$1(ref) {
|
|
3171
3033
|
ref._throwIfRoot('getMetadata');
|
|
3172
|
-
|
|
3034
|
+
const requestInfo = getMetadata$2(ref.storage, ref._location, getMappings());
|
|
3173
3035
|
return ref.storage.makeRequestWithTokens(requestInfo, newTextConnection);
|
|
3174
3036
|
}
|
|
3175
3037
|
/**
|
|
@@ -3185,7 +3047,7 @@ function getMetadata$1(ref) {
|
|
|
3185
3047
|
*/
|
|
3186
3048
|
function updateMetadata$1(ref, metadata) {
|
|
3187
3049
|
ref._throwIfRoot('updateMetadata');
|
|
3188
|
-
|
|
3050
|
+
const requestInfo = updateMetadata$2(ref.storage, ref._location, metadata, getMappings());
|
|
3189
3051
|
return ref.storage.makeRequestWithTokens(requestInfo, newTextConnection);
|
|
3190
3052
|
}
|
|
3191
3053
|
/**
|
|
@@ -3196,10 +3058,10 @@ function updateMetadata$1(ref, metadata) {
|
|
|
3196
3058
|
*/
|
|
3197
3059
|
function getDownloadURL$1(ref) {
|
|
3198
3060
|
ref._throwIfRoot('getDownloadURL');
|
|
3199
|
-
|
|
3061
|
+
const requestInfo = getDownloadUrl(ref.storage, ref._location, getMappings());
|
|
3200
3062
|
return ref.storage
|
|
3201
3063
|
.makeRequestWithTokens(requestInfo, newTextConnection)
|
|
3202
|
-
.then(
|
|
3064
|
+
.then(url => {
|
|
3203
3065
|
if (url === null) {
|
|
3204
3066
|
throw noDownloadURL();
|
|
3205
3067
|
}
|
|
@@ -3214,7 +3076,7 @@ function getDownloadURL$1(ref) {
|
|
|
3214
3076
|
*/
|
|
3215
3077
|
function deleteObject$1(ref) {
|
|
3216
3078
|
ref._throwIfRoot('deleteObject');
|
|
3217
|
-
|
|
3079
|
+
const requestInfo = deleteObject$2(ref.storage, ref._location);
|
|
3218
3080
|
return ref.storage.makeRequestWithTokens(requestInfo, newTextConnection);
|
|
3219
3081
|
}
|
|
3220
3082
|
/**
|
|
@@ -3228,8 +3090,8 @@ function deleteObject$1(ref) {
|
|
|
3228
3090
|
*
|
|
3229
3091
|
*/
|
|
3230
3092
|
function _getChild$1(ref, childPath) {
|
|
3231
|
-
|
|
3232
|
-
|
|
3093
|
+
const newPath = child(ref._location.path, childPath);
|
|
3094
|
+
const location = new Location(ref._location.bucket, newPath);
|
|
3233
3095
|
return new Reference(ref.storage, location);
|
|
3234
3096
|
}
|
|
3235
3097
|
|
|
@@ -3264,11 +3126,11 @@ function refFromURL(service, url) {
|
|
|
3264
3126
|
*/
|
|
3265
3127
|
function refFromPath(ref, path) {
|
|
3266
3128
|
if (ref instanceof FirebaseStorageImpl) {
|
|
3267
|
-
|
|
3129
|
+
const service = ref;
|
|
3268
3130
|
if (service._bucket == null) {
|
|
3269
3131
|
throw noDefaultBucket();
|
|
3270
3132
|
}
|
|
3271
|
-
|
|
3133
|
+
const reference = new Reference(service, service._bucket);
|
|
3272
3134
|
if (path != null) {
|
|
3273
3135
|
return refFromPath(reference, path);
|
|
3274
3136
|
}
|
|
@@ -3300,17 +3162,16 @@ function ref$1(serviceOrRef, pathOrUrl) {
|
|
|
3300
3162
|
}
|
|
3301
3163
|
}
|
|
3302
3164
|
function extractBucket(host, config) {
|
|
3303
|
-
|
|
3165
|
+
const bucketString = config === null || config === void 0 ? void 0 : config[CONFIG_STORAGE_BUCKET_KEY];
|
|
3304
3166
|
if (bucketString == null) {
|
|
3305
3167
|
return null;
|
|
3306
3168
|
}
|
|
3307
3169
|
return Location.makeFromBucketSpec(bucketString, host);
|
|
3308
3170
|
}
|
|
3309
|
-
function connectStorageEmulator$1(storage, host, port, options) {
|
|
3310
|
-
|
|
3311
|
-
storage.host = "".concat(host, ":").concat(port);
|
|
3171
|
+
function connectStorageEmulator$1(storage, host, port, options = {}) {
|
|
3172
|
+
storage.host = `${host}:${port}`;
|
|
3312
3173
|
storage._protocol = 'http';
|
|
3313
|
-
|
|
3174
|
+
const { mockUserToken } = options;
|
|
3314
3175
|
if (mockUserToken) {
|
|
3315
3176
|
storage._overrideAuthToken =
|
|
3316
3177
|
typeof mockUserToken === 'string'
|
|
@@ -3324,8 +3185,8 @@ function connectStorageEmulator$1(storage, host, port, options) {
|
|
|
3324
3185
|
*
|
|
3325
3186
|
* @internal
|
|
3326
3187
|
*/
|
|
3327
|
-
|
|
3328
|
-
|
|
3188
|
+
class FirebaseStorageImpl {
|
|
3189
|
+
constructor(
|
|
3329
3190
|
/**
|
|
3330
3191
|
* FirebaseApp associated with this StorageService instance.
|
|
3331
3192
|
*/
|
|
@@ -3363,160 +3224,117 @@ var FirebaseStorageImpl = /** @class */ (function () {
|
|
|
3363
3224
|
this._bucket = extractBucket(this._host, this.app.options);
|
|
3364
3225
|
}
|
|
3365
3226
|
}
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3227
|
+
/**
|
|
3228
|
+
* The host string for this service, in the form of `host` or
|
|
3229
|
+
* `host:port`.
|
|
3230
|
+
*/
|
|
3231
|
+
get host() {
|
|
3232
|
+
return this._host;
|
|
3233
|
+
}
|
|
3234
|
+
set host(host) {
|
|
3235
|
+
this._host = host;
|
|
3236
|
+
if (this._url != null) {
|
|
3237
|
+
this._bucket = Location.makeFromBucketSpec(this._url, host);
|
|
3238
|
+
}
|
|
3239
|
+
else {
|
|
3240
|
+
this._bucket = extractBucket(host, this.app.options);
|
|
3241
|
+
}
|
|
3242
|
+
}
|
|
3243
|
+
/**
|
|
3244
|
+
* The maximum time to retry uploads in milliseconds.
|
|
3245
|
+
*/
|
|
3246
|
+
get maxUploadRetryTime() {
|
|
3247
|
+
return this._maxUploadRetryTime;
|
|
3248
|
+
}
|
|
3249
|
+
set maxUploadRetryTime(time) {
|
|
3250
|
+
validateNumber('time',
|
|
3251
|
+
/* minValue=*/ 0,
|
|
3252
|
+
/* maxValue= */ Number.POSITIVE_INFINITY, time);
|
|
3253
|
+
this._maxUploadRetryTime = time;
|
|
3254
|
+
}
|
|
3255
|
+
/**
|
|
3256
|
+
* The maximum time to retry operations other than uploads or downloads in
|
|
3257
|
+
* milliseconds.
|
|
3258
|
+
*/
|
|
3259
|
+
get maxOperationRetryTime() {
|
|
3260
|
+
return this._maxOperationRetryTime;
|
|
3261
|
+
}
|
|
3262
|
+
set maxOperationRetryTime(time) {
|
|
3263
|
+
validateNumber('time',
|
|
3264
|
+
/* minValue=*/ 0,
|
|
3265
|
+
/* maxValue= */ Number.POSITIVE_INFINITY, time);
|
|
3266
|
+
this._maxOperationRetryTime = time;
|
|
3267
|
+
}
|
|
3268
|
+
async _getAuthToken() {
|
|
3269
|
+
if (this._overrideAuthToken) {
|
|
3270
|
+
return this._overrideAuthToken;
|
|
3271
|
+
}
|
|
3272
|
+
const auth = this._authProvider.getImmediate({ optional: true });
|
|
3273
|
+
if (auth) {
|
|
3274
|
+
const tokenData = await auth.getToken();
|
|
3275
|
+
if (tokenData !== null) {
|
|
3276
|
+
return tokenData.accessToken;
|
|
3381
3277
|
}
|
|
3382
|
-
}
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
this._maxUploadRetryTime = time;
|
|
3398
|
-
},
|
|
3399
|
-
enumerable: false,
|
|
3400
|
-
configurable: true
|
|
3401
|
-
});
|
|
3402
|
-
Object.defineProperty(FirebaseStorageImpl.prototype, "maxOperationRetryTime", {
|
|
3403
|
-
/**
|
|
3404
|
-
* The maximum time to retry operations other than uploads or downloads in
|
|
3405
|
-
* milliseconds.
|
|
3406
|
-
*/
|
|
3407
|
-
get: function () {
|
|
3408
|
-
return this._maxOperationRetryTime;
|
|
3409
|
-
},
|
|
3410
|
-
set: function (time) {
|
|
3411
|
-
validateNumber('time',
|
|
3412
|
-
/* minValue=*/ 0,
|
|
3413
|
-
/* maxValue= */ Number.POSITIVE_INFINITY, time);
|
|
3414
|
-
this._maxOperationRetryTime = time;
|
|
3415
|
-
},
|
|
3416
|
-
enumerable: false,
|
|
3417
|
-
configurable: true
|
|
3418
|
-
});
|
|
3419
|
-
FirebaseStorageImpl.prototype._getAuthToken = function () {
|
|
3420
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
3421
|
-
var auth, tokenData;
|
|
3422
|
-
return tslib.__generator(this, function (_a) {
|
|
3423
|
-
switch (_a.label) {
|
|
3424
|
-
case 0:
|
|
3425
|
-
if (this._overrideAuthToken) {
|
|
3426
|
-
return [2 /*return*/, this._overrideAuthToken];
|
|
3427
|
-
}
|
|
3428
|
-
auth = this._authProvider.getImmediate({ optional: true });
|
|
3429
|
-
if (!auth) return [3 /*break*/, 2];
|
|
3430
|
-
return [4 /*yield*/, auth.getToken()];
|
|
3431
|
-
case 1:
|
|
3432
|
-
tokenData = _a.sent();
|
|
3433
|
-
if (tokenData !== null) {
|
|
3434
|
-
return [2 /*return*/, tokenData.accessToken];
|
|
3435
|
-
}
|
|
3436
|
-
_a.label = 2;
|
|
3437
|
-
case 2: return [2 /*return*/, null];
|
|
3438
|
-
}
|
|
3439
|
-
});
|
|
3440
|
-
});
|
|
3441
|
-
};
|
|
3442
|
-
FirebaseStorageImpl.prototype._getAppCheckToken = function () {
|
|
3443
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
3444
|
-
var appCheck, result;
|
|
3445
|
-
return tslib.__generator(this, function (_a) {
|
|
3446
|
-
switch (_a.label) {
|
|
3447
|
-
case 0:
|
|
3448
|
-
appCheck = this._appCheckProvider.getImmediate({ optional: true });
|
|
3449
|
-
if (!appCheck) return [3 /*break*/, 2];
|
|
3450
|
-
return [4 /*yield*/, appCheck.getToken()];
|
|
3451
|
-
case 1:
|
|
3452
|
-
result = _a.sent();
|
|
3453
|
-
// TODO: What do we want to do if there is an error getting the token?
|
|
3454
|
-
// Context: appCheck.getToken() will never throw even if an error happened. In the error case, a dummy token will be
|
|
3455
|
-
// returned along with an error field describing the error. In general, we shouldn't care about the error condition and just use
|
|
3456
|
-
// the token (actual or dummy) to send requests.
|
|
3457
|
-
return [2 /*return*/, result.token];
|
|
3458
|
-
case 2: return [2 /*return*/, null];
|
|
3459
|
-
}
|
|
3460
|
-
});
|
|
3461
|
-
});
|
|
3462
|
-
};
|
|
3278
|
+
}
|
|
3279
|
+
return null;
|
|
3280
|
+
}
|
|
3281
|
+
async _getAppCheckToken() {
|
|
3282
|
+
const appCheck = this._appCheckProvider.getImmediate({ optional: true });
|
|
3283
|
+
if (appCheck) {
|
|
3284
|
+
const result = await appCheck.getToken();
|
|
3285
|
+
// TODO: What do we want to do if there is an error getting the token?
|
|
3286
|
+
// Context: appCheck.getToken() will never throw even if an error happened. In the error case, a dummy token will be
|
|
3287
|
+
// returned along with an error field describing the error. In general, we shouldn't care about the error condition and just use
|
|
3288
|
+
// the token (actual or dummy) to send requests.
|
|
3289
|
+
return result.token;
|
|
3290
|
+
}
|
|
3291
|
+
return null;
|
|
3292
|
+
}
|
|
3463
3293
|
/**
|
|
3464
3294
|
* Stop running requests and prevent more from being created.
|
|
3465
3295
|
*/
|
|
3466
|
-
|
|
3296
|
+
_delete() {
|
|
3467
3297
|
if (!this._deleted) {
|
|
3468
3298
|
this._deleted = true;
|
|
3469
|
-
this._requests.forEach(
|
|
3299
|
+
this._requests.forEach(request => request.cancel());
|
|
3470
3300
|
this._requests.clear();
|
|
3471
3301
|
}
|
|
3472
3302
|
return Promise.resolve();
|
|
3473
|
-
}
|
|
3303
|
+
}
|
|
3474
3304
|
/**
|
|
3475
3305
|
* Returns a new firebaseStorage.Reference object referencing this StorageService
|
|
3476
3306
|
* at the given Location.
|
|
3477
3307
|
*/
|
|
3478
|
-
|
|
3308
|
+
_makeStorageReference(loc) {
|
|
3479
3309
|
return new Reference(this, loc);
|
|
3480
|
-
}
|
|
3310
|
+
}
|
|
3481
3311
|
/**
|
|
3482
3312
|
* @param requestInfo - HTTP RequestInfo object
|
|
3483
3313
|
* @param authToken - Firebase auth token
|
|
3484
3314
|
*/
|
|
3485
|
-
|
|
3486
|
-
var _this = this;
|
|
3487
|
-
if (retry === void 0) { retry = true; }
|
|
3315
|
+
_makeRequest(requestInfo, requestFactory, authToken, appCheckToken, retry = true) {
|
|
3488
3316
|
if (!this._deleted) {
|
|
3489
|
-
|
|
3490
|
-
this._requests.add(
|
|
3317
|
+
const request = makeRequest(requestInfo, this._appId, authToken, appCheckToken, requestFactory, this._firebaseVersion, retry);
|
|
3318
|
+
this._requests.add(request);
|
|
3491
3319
|
// Request removes itself from set when complete.
|
|
3492
|
-
|
|
3493
|
-
return
|
|
3320
|
+
request.getPromise().then(() => this._requests.delete(request), () => this._requests.delete(request));
|
|
3321
|
+
return request;
|
|
3494
3322
|
}
|
|
3495
3323
|
else {
|
|
3496
3324
|
return new FailRequest(appDeleted());
|
|
3497
3325
|
}
|
|
3498
|
-
}
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
])];
|
|
3508
|
-
case 1:
|
|
3509
|
-
_a = _b.sent(), authToken = _a[0], appCheckToken = _a[1];
|
|
3510
|
-
return [2 /*return*/, this._makeRequest(requestInfo, requestFactory, authToken, appCheckToken).getPromise()];
|
|
3511
|
-
}
|
|
3512
|
-
});
|
|
3513
|
-
});
|
|
3514
|
-
};
|
|
3515
|
-
return FirebaseStorageImpl;
|
|
3516
|
-
}());
|
|
3326
|
+
}
|
|
3327
|
+
async makeRequestWithTokens(requestInfo, requestFactory) {
|
|
3328
|
+
const [authToken, appCheckToken] = await Promise.all([
|
|
3329
|
+
this._getAuthToken(),
|
|
3330
|
+
this._getAppCheckToken()
|
|
3331
|
+
]);
|
|
3332
|
+
return this._makeRequest(requestInfo, requestFactory, authToken, appCheckToken).getPromise();
|
|
3333
|
+
}
|
|
3334
|
+
}
|
|
3517
3335
|
|
|
3518
|
-
|
|
3519
|
-
|
|
3336
|
+
const name = "@firebase/storage";
|
|
3337
|
+
const version = "0.13.3";
|
|
3520
3338
|
|
|
3521
3339
|
/**
|
|
3522
3340
|
* @license
|
|
@@ -3537,8 +3355,24 @@ var version = "0.13.2";
|
|
|
3537
3355
|
/**
|
|
3538
3356
|
* Type constant for Firebase Storage.
|
|
3539
3357
|
*/
|
|
3540
|
-
|
|
3358
|
+
const STORAGE_TYPE = 'storage';
|
|
3541
3359
|
|
|
3360
|
+
/**
|
|
3361
|
+
* @license
|
|
3362
|
+
* Copyright 2020 Google LLC
|
|
3363
|
+
*
|
|
3364
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3365
|
+
* you may not use this file except in compliance with the License.
|
|
3366
|
+
* You may obtain a copy of the License at
|
|
3367
|
+
*
|
|
3368
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3369
|
+
*
|
|
3370
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
3371
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3372
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3373
|
+
* See the License for the specific language governing permissions and
|
|
3374
|
+
* limitations under the License.
|
|
3375
|
+
*/
|
|
3542
3376
|
/**
|
|
3543
3377
|
* Downloads the data at the object's location. Returns an error if the object
|
|
3544
3378
|
* is not found.
|
|
@@ -3709,16 +3543,15 @@ function _getChild(ref, childPath) {
|
|
|
3709
3543
|
* If not passed, uses the app's default Storage Bucket.
|
|
3710
3544
|
* @returns A {@link FirebaseStorage} instance.
|
|
3711
3545
|
*/
|
|
3712
|
-
function getStorage(app$1, bucketUrl) {
|
|
3713
|
-
if (app$1 === void 0) { app$1 = app.getApp(); }
|
|
3546
|
+
function getStorage(app$1 = app.getApp(), bucketUrl) {
|
|
3714
3547
|
app$1 = util.getModularInstance(app$1);
|
|
3715
|
-
|
|
3716
|
-
|
|
3548
|
+
const storageProvider = app._getProvider(app$1, STORAGE_TYPE);
|
|
3549
|
+
const storageInstance = storageProvider.getImmediate({
|
|
3717
3550
|
identifier: bucketUrl
|
|
3718
3551
|
});
|
|
3719
|
-
|
|
3552
|
+
const emulator = util.getDefaultEmulatorHostnameAndPort('storage');
|
|
3720
3553
|
if (emulator) {
|
|
3721
|
-
connectStorageEmulator
|
|
3554
|
+
connectStorageEmulator(storageInstance, ...emulator);
|
|
3722
3555
|
}
|
|
3723
3556
|
return storageInstance;
|
|
3724
3557
|
}
|
|
@@ -3732,8 +3565,7 @@ function getStorage(app$1, bucketUrl) {
|
|
|
3732
3565
|
* token to use for unit testing Security Rules.
|
|
3733
3566
|
* @public
|
|
3734
3567
|
*/
|
|
3735
|
-
function connectStorageEmulator(storage, host, port, options) {
|
|
3736
|
-
if (options === void 0) { options = {}; }
|
|
3568
|
+
function connectStorageEmulator(storage, host, port, options = {}) {
|
|
3737
3569
|
connectStorageEmulator$1(storage, host, port, options);
|
|
3738
3570
|
}
|
|
3739
3571
|
|
|
@@ -3794,19 +3626,18 @@ function getStream(ref, maxDownloadSizeBytes) {
|
|
|
3794
3626
|
*
|
|
3795
3627
|
* @packageDocumentation
|
|
3796
3628
|
*/
|
|
3797
|
-
function factory(container,
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
var appCheckProvider = container.getProvider('app-check-internal');
|
|
3629
|
+
function factory(container, { instanceIdentifier: url }) {
|
|
3630
|
+
const app$1 = container.getProvider('app').getImmediate();
|
|
3631
|
+
const authProvider = container.getProvider('auth-internal');
|
|
3632
|
+
const appCheckProvider = container.getProvider('app-check-internal');
|
|
3802
3633
|
return new FirebaseStorageImpl(app$1, authProvider, appCheckProvider, url, app.SDK_VERSION);
|
|
3803
3634
|
}
|
|
3804
3635
|
function registerStorage() {
|
|
3805
3636
|
app._registerComponent(new component.Component(STORAGE_TYPE, factory, "PUBLIC" /* ComponentType.PUBLIC */).setMultipleInstances(true));
|
|
3806
3637
|
//RUNTIME_ENV will be replaced during the compilation to "node" for nodejs and an empty string for browser
|
|
3807
3638
|
app.registerVersion(name, version, '');
|
|
3808
|
-
// BUILD_TARGET will be replaced by values like
|
|
3809
|
-
app.registerVersion(name, version, '
|
|
3639
|
+
// BUILD_TARGET will be replaced by values like esm2017, cjs2017, etc during the compilation
|
|
3640
|
+
app.registerVersion(name, version, 'cjs2017');
|
|
3810
3641
|
}
|
|
3811
3642
|
registerStorage();
|
|
3812
3643
|
|