-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtus.min.js
2836 lines (2308 loc) · 131 KB
/
tus.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function(f) { if (typeof exports === "object" && typeof module !== "undefined") { module.exports = f() } else if (typeof define === "function" && define.amd) { define([], f) } else { var g; if (typeof window !== "undefined") { g = window } else if (typeof global !== "undefined") { g = global } else if (typeof self !== "undefined") { g = self } else { g = this }
g.tus = f() } })(function() {
var define, module, exports;
return (function e(t, n, r) {
function s(o, u) { if (!n[o]) { if (!t[o]) { var a = typeof require == "function" && require; if (!u && a) return a(o, !0); if (i) return i(o, !0); var f = new Error("Cannot find module '" + o + "'"); throw f.code = "MODULE_NOT_FOUND", f } var l = n[o] = { exports: {} };
t[o][0].call(l.exports, function(e) { var n = t[o][1][e]; return s(n ? n : e) }, l, l.exports, e, t, n, r) } return n[o].exports } var i = typeof require == "function" && require; for (var o = 0; o < r.length; o++) s(r[o]); return s })({
1: [function(require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _isReactNative = _interopRequireDefault(require("./isReactNative"));
var _uriToBlob = _interopRequireDefault(require("./uriToBlob"));
var _isCordova = _interopRequireDefault(require("./isCordova"));
var _readAsByteArray = _interopRequireDefault(require("./readAsByteArray"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var FileSource = /*#__PURE__*/ function() {
// Make this.size a method
function FileSource(file) {
_classCallCheck(this, FileSource);
this._file = file;
this.size = file.size;
}
_createClass(FileSource, [{
key: "slice",
value: function slice(start, end) {
// In Apache Cordova applications, a File must be resolved using
// FileReader instances, see
// https://cordova.apache.org/docs/en/8.x/reference/cordova-plugin-file/index.html#read-a-file
if ((0, _isCordova["default"])()) {
return (0, _readAsByteArray["default"])(this._file.slice(start, end));
}
var value = this._file.slice(start, end);
return Promise.resolve({
value: value
});
}
}, {
key: "close",
value: function close() { // Nothing to do here since we don't need to release any resources.
}
}]);
return FileSource;
}();
var StreamSource = /*#__PURE__*/ function() {
function StreamSource(reader, chunkSize) {
_classCallCheck(this, StreamSource);
this._chunkSize = chunkSize;
this._buffer = undefined;
this._bufferOffset = 0;
this._reader = reader;
this._done = false;
}
_createClass(StreamSource, [{
key: "slice",
value: function slice(start, end) {
if (start < this._bufferOffset) {
return Promise.reject(new Error("Requested data is before the reader's current offset"));
}
return this._readUntilEnoughDataOrDone(start, end);
}
}, {
key: "_readUntilEnoughDataOrDone",
value: function _readUntilEnoughDataOrDone(start, end) {
var _this = this;
var hasEnoughData = end <= this._bufferOffset + len(this._buffer);
if (this._done || hasEnoughData) {
var value = this._getDataFromBuffer(start, end);
var done = value == null ? this._done : false;
return Promise.resolve({
value: value,
done: done
});
}
return this._reader.read().then(function(_ref) {
var value = _ref.value,
done = _ref.done;
if (done) {
_this._done = true;
} else if (_this._buffer === undefined) {
_this._buffer = value;
} else {
_this._buffer = concat(_this._buffer, value);
}
return _this._readUntilEnoughDataOrDone(start, end);
});
}
}, {
key: "_getDataFromBuffer",
value: function _getDataFromBuffer(start, end) {
// Remove data from buffer before `start`.
// Data might be reread from the buffer if an upload fails, so we can only
// safely delete data when it comes *before* what is currently being read.
if (start > this._bufferOffset) {
this._buffer = this._buffer.slice(start - this._bufferOffset);
this._bufferOffset = start;
} // If the buffer is empty after removing old data, all data has been read.
var hasAllDataBeenRead = len(this._buffer) === 0;
if (this._done && hasAllDataBeenRead) {
return null;
} // We already removed data before `start`, so we just return the first
// chunk from the buffer.
return this._buffer.slice(0, end - start);
}
}, {
key: "close",
value: function close() {
if (this._reader.cancel) {
this._reader.cancel();
}
}
}]);
return StreamSource;
}();
function len(blobOrArray) {
if (blobOrArray === undefined) return 0;
if (blobOrArray.size !== undefined) return blobOrArray.size;
return blobOrArray.length;
}
/*
Typed arrays and blobs don't have a concat method.
This function helps StreamSource accumulate data to reach chunkSize.
*/
function concat(a, b) {
if (a.concat) {
// Is `a` an Array?
return a.concat(b);
}
if (a instanceof Blob) {
return new Blob([a, b], {
type: a.type
});
}
if (a.set) {
// Is `a` a typed array?
var c = new a.constructor(a.length + b.length);
c.set(a);
c.set(b, a.length);
return c;
}
throw new Error("Unknown data type");
}
var FileReader = /*#__PURE__*/ function() {
function FileReader() {
_classCallCheck(this, FileReader);
}
_createClass(FileReader, [{
key: "openFile",
value: function openFile(input, chunkSize) {
// In React Native, when user selects a file, instead of a File or Blob,
// you usually get a file object {} with a uri property that contains
// a local path to the file. We use XMLHttpRequest to fetch
// the file blob, before uploading with tus.
if ((0, _isReactNative["default"])() && input && typeof input.uri !== "undefined") {
return (0, _uriToBlob["default"])(input.uri).then(function(blob) {
return new FileSource(blob);
})["catch"](function(err) {
throw new Error("tus: cannot fetch `file.uri` as Blob, make sure the uri is correct and accessible. " + err);
});
} // Since we emulate the Blob type in our tests (not all target browsers
// support it), we cannot use `instanceof` for testing whether the input value
// can be handled. Instead, we simply check is the slice() function and the
// size property are available.
if (typeof input.slice === "function" && typeof input.size !== "undefined") {
return Promise.resolve(new FileSource(input));
}
if (typeof input.read === "function") {
chunkSize = +chunkSize;
if (!isFinite(chunkSize)) {
return Promise.reject(new Error("cannot create source for stream without a finite value for the `chunkSize` option"));
}
return Promise.resolve(new StreamSource(input, chunkSize));
}
return Promise.reject(new Error("source object may only be an instance of File, Blob, or Reader in this environment"));
}
}]);
return FileReader;
}();
exports["default"] = FileReader;
}, { "./isCordova": 5, "./isReactNative": 6, "./readAsByteArray": 7, "./uriToBlob": 8 }],
2: [function(require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = fingerprint;
var _isReactNative = _interopRequireDefault(require("./isReactNative"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
// TODO: Differenciate between input types
/**
* Generate a fingerprint for a file which will be used the store the endpoint
*
* @param {File} file
* @param {Object} options
* @param {Function} callback
*/
function fingerprint(file, options) {
if ((0, _isReactNative["default"])()) {
return Promise.resolve(reactNativeFingerprint(file, options));
}
return Promise.resolve(["tus-br", file.name, file.type, file.size, file.lastModified, options.endpoint].join("-"));
}
function reactNativeFingerprint(file, options) {
var exifHash = file.exif ? hashCode(JSON.stringify(file.exif)) : "noexif";
return ["tus-rn", file.name || "noname", file.size || "nosize", exifHash, options.endpoint].join("/");
}
function hashCode(str) {
// from https://stackoverflow.com/a/8831937/151666
var hash = 0;
if (str.length === 0) {
return hash;
}
for (var i = 0; i < str.length; i++) {
var _char = str.charCodeAt(i);
hash = (hash << 5) - hash + _char;
hash = hash & hash; // Convert to 32bit integer
}
return hash;
}
}, { "./isReactNative": 6 }],
3: [function(require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/* global window */
var XHRHttpStack = /*#__PURE__*/ function() {
function XHRHttpStack() {
_classCallCheck(this, XHRHttpStack);
}
_createClass(XHRHttpStack, [{
key: "createRequest",
value: function createRequest(method, url) {
return new Request(method, url);
}
}, {
key: "getName",
value: function getName() {
return "XHRHttpStack";
}
}]);
return XHRHttpStack;
}();
exports["default"] = XHRHttpStack;
var Request = /*#__PURE__*/ function() {
function Request(method, url) {
_classCallCheck(this, Request);
this._xhr = new XMLHttpRequest();
this._xhr.open(method, url, true);
this._method = method;
this._url = url;
this._headers = {};
}
_createClass(Request, [{
key: "getMethod",
value: function getMethod() {
return this._method;
}
}, {
key: "getURL",
value: function getURL() {
return this._url;
}
}, {
key: "setHeader",
value: function setHeader(header, value) {
this._xhr.setRequestHeader(header, value);
this._headers[header] = value;
}
}, {
key: "getHeader",
value: function getHeader(header) {
return this._headers[header];
}
}, {
key: "setProgressHandler",
value: function setProgressHandler(progressHandler) {
// Test support for progress events before attaching an event listener
if (!("upload" in this._xhr)) {
return;
}
this._xhr.upload.onprogress = function(e) {
if (!e.lengthComputable) {
return;
}
progressHandler(e.loaded);
};
}
}, {
key: "send",
value: function send() {
var _this = this;
var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
return new Promise(function(resolve, reject) {
_this._xhr.onload = function() {
resolve(new Response(_this._xhr));
};
_this._xhr.onerror = function(err) {
reject(err);
};
_this._xhr.send(body);
});
}
}, {
key: "abort",
value: function abort() {
this._xhr.abort();
return Promise.resolve();
}
}, {
key: "getUnderlyingObject",
value: function getUnderlyingObject() {
return this._xhr;
}
}]);
return Request;
}();
var Response = /*#__PURE__*/ function() {
function Response(xhr) {
_classCallCheck(this, Response);
this._xhr = xhr;
}
_createClass(Response, [{
key: "getStatus",
value: function getStatus() {
return this._xhr.status;
}
}, {
key: "getHeader",
value: function getHeader(header) {
return this._xhr.getResponseHeader(header);
}
}, {
key: "getBody",
value: function getBody() {
return this._xhr.responseText;
}
}, {
key: "getUnderlyingObject",
value: function getUnderlyingObject() {
return this._xhr;
}
}]);
return Response;
}();
}, {}],
4: [function(require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "enableDebugLog", {
enumerable: true,
get: function get() {
return _logger.enableDebugLog;
}
});
Object.defineProperty(exports, "canStoreURLs", {
enumerable: true,
get: function get() {
return _urlStorage.canStoreURLs;
}
});
exports.isSupported = exports.defaultOptions = exports.Upload = void 0;
var _upload = _interopRequireDefault(require("../upload"));
var _noopUrlStorage = _interopRequireDefault(require("../noopUrlStorage"));
var _logger = require("../logger");
var _urlStorage = require("./urlStorage");
var _httpStack = _interopRequireDefault(require("./httpStack"));
var _fileReader = _interopRequireDefault(require("./fileReader"));
var _fingerprint = _interopRequireDefault(require("./fingerprint"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); }
subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { return function() { var Super = _getPrototypeOf(Derived),
result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function() {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function(sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; });
keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function(key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function(key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var defaultOptions = _objectSpread({}, _upload["default"].defaultOptions, {
httpStack: new _httpStack["default"](),
fileReader: new _fileReader["default"](),
urlStorage: _urlStorage.canStoreURLs ? new _urlStorage.WebStorageUrlStorage() : new _noopUrlStorage["default"](),
fingerprint: _fingerprint["default"]
});
exports.defaultOptions = defaultOptions;
var Upload = /*#__PURE__*/ function(_BaseUpload) {
_inherits(Upload, _BaseUpload);
var _super = _createSuper(Upload);
function Upload() {
var file = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
_classCallCheck(this, Upload);
options = _objectSpread({}, defaultOptions, {}, options);
return _super.call(this, file, options);
}
_createClass(Upload, null, [{
key: "terminate",
value: function terminate(url, options, cb) {
options = _objectSpread({}, defaultOptions, {}, options);
return _upload["default"].terminate(url, options, cb);
}
}]);
return Upload;
}(_upload["default"]);
exports.Upload = Upload;
var _window = window,
XMLHttpRequest = _window.XMLHttpRequest,
Blob = _window.Blob;
var isSupported = XMLHttpRequest && Blob && typeof Blob.prototype.slice === "function";
exports.isSupported = isSupported;
}, { "../logger": 11, "../noopUrlStorage": 12, "../upload": 13, "./fileReader": 1, "./fingerprint": 2, "./httpStack": 3, "./urlStorage": 9 }],
5: [function(require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var isCordova = function isCordova() {
return typeof window != "undefined" && (typeof window.PhoneGap != "undefined" || typeof window.Cordova != "undefined" || typeof window.cordova != "undefined");
};
var _default = isCordova;
exports["default"] = _default;
}, {}],
6: [function(require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var isReactNative = function isReactNative() {
return typeof navigator !== "undefined" && typeof navigator.product === "string" && navigator.product.toLowerCase() === "reactnative";
};
var _default = isReactNative;
exports["default"] = _default;
}, {}],
7: [function(require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = readAsByteArray;
/**
* readAsByteArray converts a File object to a Uint8Array.
* This function is only used on the Apache Cordova platform.
* See https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/index.html#read-a-file
*/
function readAsByteArray(chunk) {
return new Promise(function(resolve, reject) {
var reader = new FileReader();
reader.onload = function() {
var value = new Uint8Array(reader.result);
resolve({
value: value
});
};
reader.onerror = function(err) {
reject(err);
};
reader.readAsArrayBuffer(chunk);
});
}
}, {}],
8: [function(require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = uriToBlob;
/**
* uriToBlob resolves a URI to a Blob object. This is used for
* React Native to retrieve a file (identified by a file://
* URI) as a blob.
*/
function uriToBlob(uri) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.responseType = "blob";
xhr.onload = function() {
var blob = xhr.response;
resolve(blob);
};
xhr.onerror = function(err) {
reject(err);
};
xhr.open("GET", uri);
xhr.send();
});
}
}, {}],
9: [function(require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.WebStorageUrlStorage = exports.canStoreURLs = void 0;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/* global window, localStorage */
var hasStorage = false;
try {
hasStorage = "localStorage" in window; // Attempt to store and read entries from the local storage to detect Private
// Mode on Safari on iOS (see #49)
var key = "tusSupport";
localStorage.setItem(key, localStorage.getItem(key));
} catch (e) {
// If we try to access localStorage inside a sandboxed iframe, a SecurityError
// is thrown. When in private mode on iOS Safari, a QuotaExceededError is
// thrown (see #49)
if (e.code === e.SECURITY_ERR || e.code === e.QUOTA_EXCEEDED_ERR) {
hasStorage = false;
} else {
throw e;
}
}
var canStoreURLs = hasStorage;
exports.canStoreURLs = canStoreURLs;
var WebStorageUrlStorage = /*#__PURE__*/ function() {
function WebStorageUrlStorage() {
_classCallCheck(this, WebStorageUrlStorage);
}
_createClass(WebStorageUrlStorage, [{
key: "findAllUploads",
value: function findAllUploads() {
var results = this._findEntries("tus::");
return Promise.resolve(results);
}
}, {
key: "findUploadsByFingerprint",
value: function findUploadsByFingerprint(fingerprint) {
var results = this._findEntries("tus::".concat(fingerprint, "::"));
return Promise.resolve(results);
}
}, {
key: "removeUpload",
value: function removeUpload(urlStorageKey) {
localStorage.removeItem(urlStorageKey);
return Promise.resolve();
}
}, {
key: "addUpload",
value: function addUpload(fingerprint, upload) {
var id = Math.round(Math.random() * 1e12);
var key = "tus::".concat(fingerprint, "::").concat(id);
localStorage.setItem(key, JSON.stringify(upload));
return Promise.resolve(key);
}
}, {
key: "_findEntries",
value: function _findEntries(prefix) {
var results = [];
for (var i = 0; i < localStorage.length; i++) {
var _key = localStorage.key(i);
if (_key.indexOf(prefix) !== 0) continue;
try {
var upload = JSON.parse(localStorage.getItem(_key));
upload.urlStorageKey = _key;
results.push(upload);
} catch (e) { // The JSON parse error is intentionally ignored here, so a malformed
// entry in the storage cannot prevent an upload.
}
}
return results;
}
}]);
return WebStorageUrlStorage;
}();
exports.WebStorageUrlStorage = WebStorageUrlStorage;
}, {}],
10: [function(require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); }
subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _createSuper(Derived) { return function() { var Super = _getPrototypeOf(Derived),
result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined;
_wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class);
_cache.set(Class, Wrapper); }
function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); }
Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null];
a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function() {})); return true; } catch (e) { return false; } }
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
var DetailedError = /*#__PURE__*/ function(_Error) {
_inherits(DetailedError, _Error);
var _super = _createSuper(DetailedError);
function DetailedError(message) {
var _this;
var causingErr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var req = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var res = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
_classCallCheck(this, DetailedError);
_this = _super.call(this, message);
_this.originalRequest = req;
_this.originalResponse = res;
_this.causingError = causingErr;
if (causingErr != null) {
message += ", caused by ".concat(causingErr.toString());
}
if (req != null) {
var requestId = req.getHeader("X-Request-ID") || "n/a";
var method = req.getMethod();
var url = req.getURL();
var status = res ? res.getStatus() : "n/a";
var body = res ? res.getBody() || "" : "n/a";
message += ", originated from request (method: ".concat(method, ", url: ").concat(url, ", response code: ").concat(status, ", response text: ").concat(body, ", request id: ").concat(requestId, ")");
}
_this.message = message;
return _this;
}
return DetailedError;
}( /*#__PURE__*/ _wrapNativeSuper(Error));
var _default = DetailedError;
exports["default"] = _default;
}, {}],
11: [function(require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.enableDebugLog = enableDebugLog;
exports.log = log;
/* eslint no-console: "off" */
var isEnabled = false;
function enableDebugLog() {
isEnabled = true;
}
function log(msg) {
if (!isEnabled) return;
console.log(msg);
}
}, {}],
12: [function(require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/* eslint no-unused-vars: "off" */
var NoopUrlStorage = /*#__PURE__*/ function() {
function NoopUrlStorage() {
_classCallCheck(this, NoopUrlStorage);
}
_createClass(NoopUrlStorage, [{
key: "listAllUploads",
value: function listAllUploads() {
return Promise.resolve([]);
}
}, {
key: "findUploadsByFingerprint",
value: function findUploadsByFingerprint(fingerprint) {
return Promise.resolve([]);
}
}, {
key: "removeUpload",
value: function removeUpload(urlStorageKey) {
return Promise.resolve();
}
}, {
key: "addUpload",
value: function addUpload(fingerprint, upload) {
return Promise.resolve(null);
}
}]);
return NoopUrlStorage;
}();
exports["default"] = NoopUrlStorage;
}, {}],
13: [function(require, module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _error = _interopRequireDefault(require("./error"));
var _uuid = _interopRequireDefault(require("./uuid"));
var _jsBase = require("js-base64");
var _urlParse = _interopRequireDefault(require("url-parse"));
var _logger = require("./logger");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function(sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; });
keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function(key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function(key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var defaultOptions = {
endpoint: null,
uploadUrl: null,
metadata: {},
fingerprint: null,
uploadSize: null,
onProgress: null,
onChunkComplete: null,
onSuccess: null,
onError: null,
_onUploadUrlAvailable: null,
overridePatchMethod: false,
headers: {},
addRequestId: false,
onBeforeRequest: null,
onAfterResponse: null,
chunkSize: Infinity,
retryDelays: [0, 1000, 3000, 5000],
parallelUploads: 1,
storeFingerprintForResuming: true,
removeFingerprintOnSuccess: false,
uploadLengthDeferred: false,
uploadDataDuringCreation: false,
urlStorage: null,
fileReader: null,
httpStack: null
};
var BaseUpload = /*#__PURE__*/ function() {
function BaseUpload(file, options) {
_classCallCheck(this, BaseUpload);
// Warn about removed options from previous versions
if ("resume" in options) {
console.log("tus: The `resume` option has been removed in tus-js-client v2. Please use the URL storage API instead."); // eslint-disable-line no-console
} // The default options will already be added from the wrapper classes.
this.options = options; // The storage module used to store URLs
this._urlStorage = this.options.urlStorage; // The underlying File/Blob object
this.file = file; // The URL against which the file will be uploaded
this.url = null; // The underlying request object for the current PATCH request