tus-js-client
Version:
A pure JavaScript client for the tus resumable upload protocol
1 lines • 86.8 kB
JavaScript
!function(t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).tus=t()}(function(){return function n(o,i,u){function a(e,t){if(!i[e]){if(!o[e]){var r="function"==typeof require&&require;if(!t&&r)return r(e,!0);if(s)return s(e,!0);throw(t=new Error("Cannot find module '"+e+"'")).code="MODULE_NOT_FOUND",t}r=i[e]={exports:{}},o[e][0].call(r.exports,function(t){return a(o[e][1][t]||t)},r,r.exports,n,o,i,u)}return i[e].exports}for(var s="function"==typeof require&&require,t=0;t<u.length;t++)a(u[t]);return a}({1:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;var i=n(t("./isReactNative.js")),u=n(t("./uriToBlob.js")),s=n(t("./sources/FileSource.js")),l=n(t("./sources/StreamSource.js"));function n(t){return t&&t.__esModule?t:{default:t}}function P(t){return(P="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function A(){A=function(){return u};var s,u={},t=Object.prototype,l=t.hasOwnProperty,f=Object.defineProperty||function(t,e,r){t[e]=r.value},e="function"==typeof Symbol?Symbol:{},n=e.iterator||"@@iterator",r=e.asyncIterator||"@@asyncIterator",o=e.toStringTag||"@@toStringTag";function i(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{i({},"")}catch(s){i=function(t,e,r){return t[e]=r}}function a(t,e,r,n){var o,i,u,a,e=e&&e.prototype instanceof v?e:v,e=Object.create(e.prototype),n=new O(n||[]);return f(e,"_invoke",{value:(o=t,i=r,u=n,a=p,function(t,e){if(a===d)throw Error("Generator is already running");if(a===y){if("throw"===t)throw e;return{value:s,done:!0}}for(u.method=t,u.arg=e;;){var r=u.delegate;if(r){r=function t(e,r){var n=r.method,o=e.iterator[n];if(o===s)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=s,t(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),g;n=c(o,e.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,g;o=n.arg;return o?o.done?(r[e.resultName]=o.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=s),r.delegate=null,g):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,g)}(r,u);if(r){if(r===g)continue;return r}}if("next"===u.method)u.sent=u._sent=u.arg;else if("throw"===u.method){if(a===p)throw a=y,u.arg;u.dispatchException(u.arg)}else"return"===u.method&&u.abrupt("return",u.arg);a=d;r=c(o,i,u);if("normal"===r.type){if(a=u.done?y:h,r.arg===g)continue;return{value:r.arg,done:u.done}}"throw"===r.type&&(a=y,u.method="throw",u.arg=r.arg)}})}),e}function c(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}u.wrap=a;var p="suspendedStart",h="suspendedYield",d="executing",y="completed",g={};function v(){}function m(){}function b(){}var e={},w=(i(e,n,function(){return this}),Object.getPrototypeOf),w=w&&w(w(x([]))),_=(w&&w!==t&&l.call(w,n)&&(e=w),b.prototype=v.prototype=Object.create(e));function S(t){["next","throw","return"].forEach(function(e){i(t,e,function(t){return this._invoke(e,t)})})}function E(u,a){var e;f(this,"_invoke",{value:function(r,n){function t(){return new a(function(t,e){!function e(t,r,n,o){var i,t=c(u[t],u,r);if("throw"!==t.type)return(r=(i=t.arg).value)&&"object"==P(r)&&l.call(r,"__await")?a.resolve(r.__await).then(function(t){e("next",t,n,o)},function(t){e("throw",t,n,o)}):a.resolve(r).then(function(t){i.value=t,n(i)},function(t){return e("throw",t,n,o)});o(t.arg)}(r,n,t,e)})}return e=e?e.then(t,t):t()}})}function U(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(U,this),this.reset(!0)}function x(e){if(e||""===e){var r,t=e[n];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length))return r=-1,(t=function t(){for(;++r<e.length;)if(l.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=s,t.done=!0,t}).next=t}throw new TypeError(P(e)+" is not iterable")}return f(_,"constructor",{value:m.prototype=b,configurable:!0}),f(b,"constructor",{value:m,configurable:!0}),m.displayName=i(b,o,"GeneratorFunction"),u.isGeneratorFunction=function(t){t="function"==typeof t&&t.constructor;return!!t&&(t===m||"GeneratorFunction"===(t.displayName||t.name))},u.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,i(t,o,"GeneratorFunction")),t.prototype=Object.create(_),t},u.awrap=function(t){return{__await:t}},S(E.prototype),i(E.prototype,r,function(){return this}),u.AsyncIterator=E,u.async=function(t,e,r,n,o){void 0===o&&(o=Promise);var i=new E(a(t,e,r,n),o);return u.isGeneratorFunction(e)?i:i.next().then(function(t){return t.done?t.value:i.next()})},S(_),i(_,o,"Generator"),i(_,n,function(){return this}),i(_,"toString",function(){return"[object Generator]"}),u.keys=function(t){var e,r=Object(t),n=[];for(e in r)n.push(e);return n.reverse(),function t(){for(;n.length;){var e=n.pop();if(e in r)return t.value=e,t.done=!1,t}return t.done=!0,t}},u.values=x,O.prototype={constructor:O,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=s,this.done=!1,this.delegate=null,this.method="next",this.arg=s,this.tryEntries.forEach(j),!t)for(var e in this)"t"===e.charAt(0)&&l.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=s)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var n=this;function t(t,e){return i.type="throw",i.arg=r,n.next=t,e&&(n.method="next",n.arg=s),!!e}for(var e=this.tryEntries.length-1;0<=e;--e){var o=this.tryEntries[e],i=o.completion;if("root"===o.tryLoc)return t("end");if(o.tryLoc<=this.prev){var u=l.call(o,"catchLoc"),a=l.call(o,"finallyLoc");if(u&&a){if(this.prev<o.catchLoc)return t(o.catchLoc,!0);if(this.prev<o.finallyLoc)return t(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return t(o.catchLoc,!0)}else{if(!a)throw Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return t(o.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;0<=r;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&l.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}var i=(o=o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc?null:o)?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,g):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),g},finish:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),j(r),g}},catch:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var r,n,o=this.tryEntries[e];if(o.tryLoc===t)return"throw"===(r=o.completion).type&&(n=r.arg,j(o)),n}throw Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:x(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=s),g}},u}function f(t,e,r,n,o,i,u){try{var a=t[i](u),s=a.value}catch(t){return void r(t)}a.done?e(s):Promise.resolve(s).then(n,o)}function c(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,function(t){t=function(t,e){if("object"!=P(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0===r)return("string"===e?String:Number)(t);r=r.call(t,e||"default");if("object"!=P(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}(t,"string");return"symbol"==P(t)?t:t+""}(n.key),n)}}r.default=function(){function t(){if(!(this instanceof t))throw new TypeError("Cannot call a class as a function")}return e=t,(r=[{key:"openFile",value:(a=A().mark(function t(e,r){var n;return A().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if((0,i.default)()&&e&&void 0!==e.uri)return t.prev=1,t.next=4,(0,u.default)(e.uri);t.next=11;break;case 4:return n=t.sent,t.abrupt("return",new s.default(n));case 8:throw t.prev=8,t.t0=t.catch(1),new Error("tus: cannot fetch `file.uri` as Blob, make sure the uri is correct and accessible. ".concat(t.t0));case 11:if("function"==typeof e.slice&&void 0!==e.size)return t.abrupt("return",Promise.resolve(new s.default(e)));t.next=13;break;case 13:if("function"!=typeof e.read){t.next=18;break}if(r=Number(r),Number.isFinite(r)){t.next=17;break}return t.abrupt("return",Promise.reject(new Error("cannot create source for stream without a finite value for the `chunkSize` option")));case 17:return t.abrupt("return",Promise.resolve(new l.default(e,r)));case 18:return t.abrupt("return",Promise.reject(new Error("source object may only be an instance of File, Blob, or Reader in this environment")));case 19:case"end":return t.stop()}},t,null,[[1,8]])}),o=function(){var t=this,u=arguments;return new Promise(function(e,r){var n=a.apply(t,u);function o(t){f(n,e,r,o,i,"next",t)}function i(t){f(n,e,r,o,i,"throw",t)}o(void 0)})},function(t,e){return o.apply(this,arguments)})}])&&c(e.prototype,r),n&&c(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,n,a,o}()},{"./isReactNative.js":5,"./sources/FileSource.js":6,"./sources/StreamSource.js":7,"./uriToBlob.js":10}],2:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.default=function(t,e){if((0,n.default)())return Promise.resolve(function(t,e){var r=t.exif?function(t){var e=0;if(0!==t.length)for(var r=0;r<t.length;r++){var n=t.charCodeAt(r);e=(e<<5)-e+n,e&=e}return e}(JSON.stringify(t.exif)):"noexif";return["tus-rn",t.name||"noname",t.size||"nosize",r,e.endpoint].join("/")}(t,e));return Promise.resolve(["tus-br",t.name,t.type,t.size,t.lastModified,e.endpoint].join("-"))};var n=(r=t("./isReactNative.js"))&&r.__esModule?r:{default:r}},{"./isReactNative.js":5}],3:[function(t,e,r){"use strict";function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,function(t){t=function(t,e){if("object"!=o(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0===r)return("string"===e?String:Number)(t);r=r.call(t,e||"default");if("object"!=o(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}(t,"string");return"symbol"==o(t)?t:t+""}(n.key),n)}}function u(t,e,r){return e&&i(t.prototype,e),r&&i(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;r.default=function(){return u(function t(){n(this,t)},[{key:"createRequest",value:function(t,e){return new a(t,e)}},{key:"getName",value:function(){return"XHRHttpStack"}}])}();var a=function(){return u(function t(e,r){n(this,t),this._xhr=new XMLHttpRequest,this._xhr.open(e,r,!0),this._method=e,this._url=r,this._headers={}},[{key:"getMethod",value:function(){return this._method}},{key:"getURL",value:function(){return this._url}},{key:"setHeader",value:function(t,e){this._xhr.setRequestHeader(t,e),this._headers[t]=e}},{key:"getHeader",value:function(t){return this._headers[t]}},{key:"setProgressHandler",value:function(e){"upload"in this._xhr&&(this._xhr.upload.onprogress=function(t){t.lengthComputable&&e(t.loaded)})}},{key:"send",value:function(){var r=this,n=0<arguments.length&&void 0!==arguments[0]?arguments[0]:null;return new Promise(function(t,e){r._xhr.onload=function(){t(new s(r._xhr))},r._xhr.onerror=function(t){e(t)},r._xhr.send(n)})}},{key:"abort",value:function(){return this._xhr.abort(),Promise.resolve()}},{key:"getUnderlyingObject",value:function(){return this._xhr}}])}(),s=function(){return u(function t(e){n(this,t),this._xhr=e},[{key:"getStatus",value:function(){return this._xhr.status}},{key:"getHeader",value:function(t){return this._xhr.getResponseHeader(t)}},{key:"getBody",value:function(){return this._xhr.responseText}},{key:"getUnderlyingObject",value:function(){return this._xhr}}])}()},{}],4:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),Object.defineProperty(r,"DefaultHttpStack",{enumerable:!0,get:function(){return l.default}}),Object.defineProperty(r,"DetailedError",{enumerable:!0,get:function(){return n.default}}),r.Upload=void 0,Object.defineProperty(r,"canStoreURLs",{enumerable:!0,get:function(){return f.canStoreURLs}}),r.defaultOptions=void 0,Object.defineProperty(r,"enableDebugLog",{enumerable:!0,get:function(){return o.enableDebugLog}}),r.isSupported=void 0;var n=c(t("../error.js")),o=t("../logger.js"),i=c(t("../noopUrlStorage.js")),u=c(t("../upload.js")),a=c(t("./fileReader.js")),s=c(t("./fileSignature.js")),l=c(t("./httpStack.js")),f=t("./urlStorage.js");function c(t){return t&&t.__esModule?t:{default:t}}function p(t){return(p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function h(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,w(n.key),n)}}function d(t,e,r){e=g(e);var n=t,e=y()?Reflect.construct(e,r||[],g(t).constructor):e.apply(t,r);if(e&&("object"===p(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");t=n;if(void 0!==t)return t;throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}function y(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(y=function(){return!!t})()}function g(t){return(g=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function v(t,e){return(v=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}function m(e,t){var r,n=Object.keys(e);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(e),t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)),n}function b(n){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?m(Object(o),!0).forEach(function(t){var e,r;e=n,r=o[t=t],(t=w(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(o)):m(Object(o)).forEach(function(t){Object.defineProperty(n,t,Object.getOwnPropertyDescriptor(o,t))})}return n}function w(t){t=function(t,e){if("object"!=p(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0===r)return("string"===e?String:Number)(t);r=r.call(t,e||"default");if("object"!=p(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}(t,"string");return"symbol"==p(t)?t:t+""}var _=r.defaultOptions=b(b({},u.default.defaultOptions),{},{httpStack:new l.default,fileReader:new a.default,urlStorage:new(f.canStoreURLs?f.WebStorageUrlStorage:i.default),fingerprint:s.default});r.Upload=function(t){function o(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:null,e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},r=this,n=o;if(r instanceof n)return d(this,o,[t,b(b({},_),e)]);throw new TypeError("Cannot call a class as a function")}var e,r=o;if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");return r.prototype=Object.create(t&&t.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),Object.defineProperty(r,"prototype",{writable:!1}),t&&v(r,t),r=o,t=[{key:"terminate",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},e=b(b({},_),e);return u.default.terminate(t,e)}}],(e=null)&&h(r.prototype,e),t&&h(r,t),Object.defineProperty(r,"prototype",{writable:!1}),r}(u.default),r.isSupported="function"==typeof XMLHttpRequest&&"function"==typeof Blob&&"function"==typeof Blob.prototype.slice},{"../error.js":12,"../logger.js":13,"../noopUrlStorage.js":14,"../upload.js":15,"./fileReader.js":1,"./fileSignature.js":2,"./httpStack.js":3,"./urlStorage.js":11}],5:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;r.default=function(){return"undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase()}},{}],6:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;var o=n(t("./isCordova.js")),i=n(t("./readAsByteArray.js"));function n(t){return t&&t.__esModule?t:{default:t}}function u(t){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function a(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,function(t){t=function(t,e){if("object"!=u(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0===r)return("string"===e?String:Number)(t);r=r.call(t,e||"default");if("object"!=u(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}(t,"string");return"symbol"==u(t)?t:t+""}(n.key),n)}}r.default=function(){function e(t){if(!(this instanceof e))throw new TypeError("Cannot call a class as a function");this._file=t,this.size=t.size}return t=e,(r=[{key:"slice",value:function(t,e){return(0,o.default)()?(0,i.default)(this._file.slice(t,e)):(t=this._file.slice(t,e),e=e>=this.size,Promise.resolve({value:t,done:e}))}},{key:"close",value:function(){}}])&&a(t.prototype,r),n&&a(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,n}()},{"./isCordova.js":8,"./readAsByteArray.js":9}],7:[function(t,e,r){"use strict";function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,function(t){t=function(t,e){if("object"!=o(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0===r)return("string"===e?String:Number)(t);r=r.call(t,e||"default");if("object"!=o(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}(t,"string");return"symbol"==o(t)?t:t+""}(n.key),n)}}function u(t){return void 0===t?0:void 0!==t.size?t.size:t.length}Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;r.default=function(){function e(t){if(!(this instanceof e))throw new TypeError("Cannot call a class as a function");this._buffer=void 0,this._bufferOffset=0,this._reader=t,this._done=!1}return t=e,(r=[{key:"slice",value:function(t,e){return t<this._bufferOffset?Promise.reject(new Error("Requested data is before the reader's current offset")):this._readUntilEnoughDataOrDone(t,e)}},{key:"_readUntilEnoughDataOrDone",value:function(r,n){var t,o=this,e=n<=this._bufferOffset+u(this._buffer);return this._done||e?(t=null==(e=this._getDataFromBuffer(r,n))&&this._done,Promise.resolve({value:e,done:t})):this._reader.read().then(function(t){var e=t.value;return t.done?o._done=!0:void 0===o._buffer?o._buffer=e:o._buffer=function(t,e){if(t.concat)return t.concat(e);if(t instanceof Blob)return new Blob([t,e],{type:t.type});var r;if(t.set)return(r=new t.constructor(t.length+e.length)).set(t),r.set(e,t.length),r;throw new Error("Unknown data type")}(o._buffer,e),o._readUntilEnoughDataOrDone(r,n)})}},{key:"_getDataFromBuffer",value:function(t,e){t>this._bufferOffset&&(this._buffer=this._buffer.slice(t-this._bufferOffset),this._bufferOffset=t);var r=0===u(this._buffer);return this._done&&r?null:this._buffer.slice(0,e-t)}},{key:"close",value:function(){this._reader.cancel&&this._reader.cancel()}}])&&i(t.prototype,r),n&&i(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,n}()},{}],8:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;r.default=function(){return"undefined"!=typeof window&&(void 0!==window.PhoneGap||void 0!==window.Cordova||void 0!==window.cordova)}},{}],9:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.default=function(t){return new Promise(function(e,r){var n=new FileReader;n.onload=function(){var t=new Uint8Array(n.result);e({value:t})},n.onerror=function(t){r(t)},n.readAsArrayBuffer(t)})}},{}],10:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.default=function(t){return new Promise(function(e,r){var n=new XMLHttpRequest;n.responseType="blob",n.onload=function(){var t=n.response;e(t)},n.onerror=function(t){r(t)},n.open("GET",t),n.send()})}},{}],11:[function(t,e,r){"use strict";function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,function(t){t=function(t,e){if("object"!=o(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0===r)return("string"===e?String:Number)(t);r=r.call(t,e||"default");if("object"!=o(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}(t,"string");return"symbol"==o(t)?t:t+""}(n.key),n)}}Object.defineProperty(r,"__esModule",{value:!0}),r.canStoreURLs=r.WebStorageUrlStorage=void 0;var n=!1;try{var n="localStorage"in window,u="tusSupport",a=localStorage.getItem(u);localStorage.setItem(u,a),null===a&&localStorage.removeItem(u)}catch(t){if(t.code!==t.SECURITY_ERR&&t.code!==t.QUOTA_EXCEEDED_ERR)throw t;n=!1}r.canStoreURLs=n,r.WebStorageUrlStorage=function(){function t(){if(!(this instanceof t))throw new TypeError("Cannot call a class as a function")}return e=t,(r=[{key:"findAllUploads",value:function(){var t=this._findEntries("tus::");return Promise.resolve(t)}},{key:"findUploadsByFingerprint",value:function(t){t=this._findEntries("tus::".concat(t,"::"));return Promise.resolve(t)}},{key:"removeUpload",value:function(t){return localStorage.removeItem(t),Promise.resolve()}},{key:"addUpload",value:function(t,e){var r=Math.round(1e12*Math.random()),t="tus::".concat(t,"::").concat(r);return localStorage.setItem(t,JSON.stringify(e)),Promise.resolve(t)}},{key:"_findEntries",value:function(t){for(var e=[],r=0;r<localStorage.length;r++){var n=localStorage.key(r);if(0===n.indexOf(t))try{var o=JSON.parse(localStorage.getItem(n));o.urlStorageKey=n,e.push(o)}catch(t){}}return e}}])&&i(e.prototype,r),n&&i(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,n}()},{}],12:[function(t,e,r){"use strict";function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,function(t){t=function(t,e){if("object"!=o(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0===r)return("string"===e?String:Number)(t);r=r.call(t,e||"default");if("object"!=o(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}(t,"string");return"symbol"==o(t)?t:t+""}(n.key),n)}}function s(t,e,r){e=a(e);var n=t,e=u()?Reflect.construct(e,r||[],a(t).constructor):e.apply(t,r);if(e&&("object"===o(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");t=n;if(void 0!==t)return t;throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}function n(t){var r="function"==typeof Map?new Map:void 0;return function(t){if(null===t||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,e)}function e(){return function(t,e,r){var n;return u()?Reflect.construct.apply(null,arguments):((n=[null]).push.apply(n,e),e=new(t.bind.apply(t,n)),r&&l(e,r.prototype),e)}(t,arguments,a(this).constructor)}return e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),l(e,t)}(t)}function u(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(u=function(){return!!t})()}function l(t,e){return(l=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}function a(t){return(a=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;var f=function(t){function a(t){var e,r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:null,o=3<arguments.length&&void 0!==arguments[3]?arguments[3]:null,i=this,u=a;if(i instanceof u)return(i=s(this,a,[t])).originalRequest=n,i.originalResponse=o,null!=(i.causingError=r)&&(t+=", caused by ".concat(r.toString())),null!=n&&(u=n.getHeader("X-Request-ID")||"n/a",r=n.getMethod(),n=n.getURL(),e=o?o.getStatus():"n/a",o=o?o.getBody()||"":"n/a",t+=", originated from request (method: ".concat(r,", url: ").concat(n,", response code: ").concat(e,", response text: ").concat(o,", request id: ").concat(u,")")),i.message=t,i;throw new TypeError("Cannot call a class as a function")}var e,r,n=a;if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");return n.prototype=Object.create(t&&t.prototype,{constructor:{value:n,writable:!0,configurable:!0}}),Object.defineProperty(n,"prototype",{writable:!1}),t&&l(n,t),n=a,e&&i(n.prototype,e),r&&i(n,r),Object.defineProperty(n,"prototype",{writable:!1}),n}(n(Error));r.default=f},{}],13:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.enableDebugLog=function(){n=!0};var n=!(r.log=function(t){n&&console.log(t)})},{}],14:[function(t,e,r){"use strict";function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,function(t){t=function(t,e){if("object"!=o(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0===r)return("string"===e?String:Number)(t);r=r.call(t,e||"default");if("object"!=o(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}(t,"string");return"symbol"==o(t)?t:t+""}(n.key),n)}}Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;r.default=function(){function t(){if(!(this instanceof t))throw new TypeError("Cannot call a class as a function")}return e=t,(r=[{key:"listAllUploads",value:function(){return Promise.resolve([])}},{key:"findUploadsByFingerprint",value:function(t){return Promise.resolve([])}},{key:"removeUpload",value:function(t){return Promise.resolve()}},{key:"addUpload",value:function(t,e){return Promise.resolve(null)}}])&&i(e.prototype,r),n&&i(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,n}()},{}],15:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;var n=t("js-base64"),o=i(t("url-parse")),a=i(t("./error.js")),u=t("./logger.js"),s=i(t("./uuid.js"));function i(t){return t&&t.__esModule?t:{default:t}}function P(){P=function(){return u};var s,u={},t=Object.prototype,l=t.hasOwnProperty,f=Object.defineProperty||function(t,e,r){t[e]=r.value},e="function"==typeof Symbol?Symbol:{},n=e.iterator||"@@iterator",r=e.asyncIterator||"@@asyncIterator",o=e.toStringTag||"@@toStringTag";function i(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{i({},"")}catch(s){i=function(t,e,r){return t[e]=r}}function a(t,e,r,n){var o,i,u,a,e=e&&e.prototype instanceof v?e:v,e=Object.create(e.prototype),n=new O(n||[]);return f(e,"_invoke",{value:(o=t,i=r,u=n,a=p,function(t,e){if(a===d)throw Error("Generator is already running");if(a===y){if("throw"===t)throw e;return{value:s,done:!0}}for(u.method=t,u.arg=e;;){var r=u.delegate;if(r){r=function t(e,r){var n=r.method,o=e.iterator[n];if(o===s)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=s,t(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),g;n=c(o,e.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,g;o=n.arg;return o?o.done?(r[e.resultName]=o.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=s),r.delegate=null,g):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,g)}(r,u);if(r){if(r===g)continue;return r}}if("next"===u.method)u.sent=u._sent=u.arg;else if("throw"===u.method){if(a===p)throw a=y,u.arg;u.dispatchException(u.arg)}else"return"===u.method&&u.abrupt("return",u.arg);a=d;r=c(o,i,u);if("normal"===r.type){if(a=u.done?y:h,r.arg===g)continue;return{value:r.arg,done:u.done}}"throw"===r.type&&(a=y,u.method="throw",u.arg=r.arg)}})}),e}function c(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}u.wrap=a;var p="suspendedStart",h="suspendedYield",d="executing",y="completed",g={};function v(){}function m(){}function b(){}var e={},w=(i(e,n,function(){return this}),Object.getPrototypeOf),w=w&&w(w(x([]))),_=(w&&w!==t&&l.call(w,n)&&(e=w),b.prototype=v.prototype=Object.create(e));function S(t){["next","throw","return"].forEach(function(e){i(t,e,function(t){return this._invoke(e,t)})})}function E(u,a){var e;f(this,"_invoke",{value:function(r,n){function t(){return new a(function(t,e){!function e(t,r,n,o){var i,t=c(u[t],u,r);if("throw"!==t.type)return(r=(i=t.arg).value)&&"object"==A(r)&&l.call(r,"__await")?a.resolve(r.__await).then(function(t){e("next",t,n,o)},function(t){e("throw",t,n,o)}):a.resolve(r).then(function(t){i.value=t,n(i)},function(t){return e("throw",t,n,o)});o(t.arg)}(r,n,t,e)})}return e=e?e.then(t,t):t()}})}function U(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(U,this),this.reset(!0)}function x(e){if(e||""===e){var r,t=e[n];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length))return r=-1,(t=function t(){for(;++r<e.length;)if(l.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=s,t.done=!0,t}).next=t}throw new TypeError(A(e)+" is not iterable")}return f(_,"constructor",{value:m.prototype=b,configurable:!0}),f(b,"constructor",{value:m,configurable:!0}),m.displayName=i(b,o,"GeneratorFunction"),u.isGeneratorFunction=function(t){t="function"==typeof t&&t.constructor;return!!t&&(t===m||"GeneratorFunction"===(t.displayName||t.name))},u.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,i(t,o,"GeneratorFunction")),t.prototype=Object.create(_),t},u.awrap=function(t){return{__await:t}},S(E.prototype),i(E.prototype,r,function(){return this}),u.AsyncIterator=E,u.async=function(t,e,r,n,o){void 0===o&&(o=Promise);var i=new E(a(t,e,r,n),o);return u.isGeneratorFunction(e)?i:i.next().then(function(t){return t.done?t.value:i.next()})},S(_),i(_,o,"Generator"),i(_,n,function(){return this}),i(_,"toString",function(){return"[object Generator]"}),u.keys=function(t){var e,r=Object(t),n=[];for(e in r)n.push(e);return n.reverse(),function t(){for(;n.length;){var e=n.pop();if(e in r)return t.value=e,t.done=!1,t}return t.done=!0,t}},u.values=x,O.prototype={constructor:O,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=s,this.done=!1,this.delegate=null,this.method="next",this.arg=s,this.tryEntries.forEach(j),!t)for(var e in this)"t"===e.charAt(0)&&l.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=s)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var n=this;function t(t,e){return i.type="throw",i.arg=r,n.next=t,e&&(n.method="next",n.arg=s),!!e}for(var e=this.tryEntries.length-1;0<=e;--e){var o=this.tryEntries[e],i=o.completion;if("root"===o.tryLoc)return t("end");if(o.tryLoc<=this.prev){var u=l.call(o,"catchLoc"),a=l.call(o,"finallyLoc");if(u&&a){if(this.prev<o.catchLoc)return t(o.catchLoc,!0);if(this.prev<o.finallyLoc)return t(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return t(o.catchLoc,!0)}else{if(!a)throw Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return t(o.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;0<=r;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&l.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}var i=(o=o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc?null:o)?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,g):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),g},finish:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),j(r),g}},catch:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var r,n,o=this.tryEntries[e];if(o.tryLoc===t)return"throw"===(r=o.completion).type&&(n=r.arg,j(o)),n}throw Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:x(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=s),g}},u}function l(t,e,r,n,o,i,u){try{var a=t[i](u),s=a.value}catch(t){return void r(t)}a.done?e(s):Promise.resolve(s).then(n,o)}function f(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,u,a=[],s=!0,l=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=i.call(r)).done)&&(a.push(n.value),a.length!==e);s=!0);}catch(t){l=!0,o=t}finally{try{if(!s&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(l)throw o}}return a}}(t,e)||p(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function A(t){return(A="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function p(t,e){var r;if(t)return"string"==typeof t?c(t,e):"Map"===(r="Object"===(r=Object.prototype.toString.call(t).slice(8,-1))&&t.constructor?t.constructor.name:r)||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?c(t,e):void 0}function c(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function h(e,t){var r,n=Object.keys(e);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(e),t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)),n}function d(n){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?h(Object(o),!0).forEach(function(t){var e,r;e=n,r=o[t=t],(t=g(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(o)):h(Object(o)).forEach(function(t){Object.defineProperty(n,t,Object.getOwnPropertyDescriptor(o,t))})}return n}function y(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,g(n.key),n)}}function g(t){t=function(t,e){if("object"!=A(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0===r)return("string"===e?String:Number)(t);r=r.call(t,e||"default");if("object"!=A(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}(t,"string");return"symbol"==A(t)?t:t+""}var v="tus-v1",m="ietf-draft-03",b="ietf-draft-05",t={endpoint:null,uploadUrl:null,metadata:{},metadataForPartialUploads:{},fingerprint:null,uploadSize:null,onProgress:null,onChunkComplete:null,onSuccess:null,onError:null,onUploadUrlAvailable:null,overridePatchMethod:!1,headers:{},addRequestId:!1,onBeforeRequest:null,onAfterResponse:null,onShouldRetry:x,chunkSize:Number.POSITIVE_INFINITY,retryDelays:[0,1e3,3e3,5e3],parallelUploads:1,parallelUploadBoundaries:null,storeFingerprintForResuming:!0,removeFingerprintOnSuccess:!1,uploadLengthDeferred:!1,uploadDataDuringCreation:!1,urlStorage:null,fileReader:null,httpStack:null,protocol:v},w=function(){function c(t,e){if(!(this instanceof c))throw new TypeError("Cannot call a class as a function");"resume"in e&&console.log("tus: The `resume` option has been removed in tus-js-client v2. Please use the URL storage API instead."),this.options=e,this.options.chunkSize=Number(this.options.chunkSize),this._urlStorage=this.options.urlStorage,this.file=t,this.url=null,this._req=null,this._fingerprint=null,this._urlStorageKey=null,this._offset=null,this._aborted=!1,this._size=null,this._source=null,this._retryAttempt=0,this._retryTimeout=null,this._offsetBeforeRetry=0,this._parallelUploads=null,this._parallelUploadUrls=null}return t=c,r=[{key:"terminate",value:function(o){var i=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},u=E("DELETE",o,i);return U(u,null,i).then(function(t){if(204!==t.getStatus())throw new a.default("tus: unexpected response while terminating upload",null,u,t)}).catch(function(t){var e,r,n;if(O(t=t instanceof a.default?t:new a.default("tus: failed to terminate upload",t,u,null),0,i))return e=i.retryDelays[0],r=i.retryDelays.slice(1),n=d(d({},i),{},{retryDelays:r}),new Promise(function(t){return setTimeout(t,e)}).then(function(){return c.terminate(o,n)});throw t})}}],(e=[{key:"findPreviousUploads",value:function(){var e=this;return this.options.fingerprint(this.file,this.options).then(function(t){return e._urlStorage.findUploadsByFingerprint(t)})}},{key:"resumeFromPreviousUpload",value:function(t){this.url=t.uploadUrl||null,this._parallelUploadUrls=t.parallelUploadUrls||null,this._urlStorageKey=t.urlStorageKey}},{key:"start",value:function(){var e=this,r=this.file;if(r)if([v,m,b].includes(this.options.protocol))if(this.options.endpoint||this.options.uploadUrl||this.url){var t=this.options.retryDelays;if(null!=t&&"[object Array]"!==Object.prototype.toString.call(t))this._emitError(new Error("tus: the `retryDelays` option must either be an array or null"));else{if(1<this.options.parallelUploads)for(var n=0,o=["uploadUrl","uploadSize","uploadLengthDeferred"];n<o.length;n++){var i=o[n];if(this.options[i])return void this._emitError(new Error("tus: cannot use the ".concat(i," option when parallelUploads is enabled")))}if(this.options.parallelUploadBoundaries){if(this.options.parallelUploads<=1)return void this._emitError(new Error("tus: cannot use the `parallelUploadBoundaries` option when `parallelUploads` is disabled"));if(this.options.parallelUploads!==this.options.parallelUploadBoundaries.length)return void this._emitError(new Error("tus: the `parallelUploadBoundaries` must have the same length as the value of `parallelUploads`"))}this.options.fingerprint(r,this.options).then(function(t){return null==t?(0,u.log)("No fingerprint was calculated meaning that the upload cannot be stored in the URL storage."):(0,u.log)("Calculated fingerprint: ".concat(t)),e._fingerprint=t,e._source||e.options.fileReader.openFile(r,e.options.chunkSize)}).then(function(t){if(e._source=t,e.options.uploadLengthDeferred)e._size=null;else if(null!=e.options.uploadSize){if(e._size=Number(e.options.uploadSize),Number.isNaN(e._size))return void e._emitError(new Error("tus: cannot convert `uploadSize` option into a number"))}else if(e._size=e._source.size,null==e._size)return void e._emitError(new Error("tus: cannot automatically derive upload's size from input. Specify it manually using the `uploadSize` option or use the `uploadLengthDeferred` option"));1<e.options.parallelUploads||null!=e._parallelUploadUrls?e._startParallelUpload():e._startSingleUpload()}).catch(function(t){e._emitError(t)})}}else this._emitError(new Error("tus: neither an endpoint or an upload URL is provided"));else this._emitError(new Error("tus: unsupported protocol ".concat(this.options.protocol)));else this._emitError(new Error("tus: no file or stream to upload provided"))}},{key:"_startParallelUpload",value:function(){var r,a=this,s=this._size,l=0,t=(this._parallelUploads=[],null!=this._parallelUploadUrls?this._parallelUploadUrls.length:this.options.parallelUploads),f=null!=(e=this.options.parallelUploadBoundaries)?e:function(t,e){for(var r=Math.floor(t/e),n=[],o=0;o<e;o++)n.push({start:r*o,end:r*(o+1)});return n[e-1].end=t,n}(this._source.size,t),e=(this._parallelUploadUrls&&f.forEach(function(t,e){t.uploadUrl=a._parallelUploadUrls[e]||null}),this._parallelUploadUrls=new Array(f.length),f.map(function(o,i){var u=0;return a._source.slice(o.start,o.end).then(function(t){var n=t.value;return new Promise(function(t,e){var t=d(d({},a.options),{},{uploadUrl:o.uploadUrl||null,storeFingerprintForResuming:!1,removeFingerprintOnSuccess:!1,parallelUploads:1,parallelUploadBoundaries:null,metadata:a.options.metadataForPartialUploads,headers:d(d({},a.options.headers),{},{"Upload-Concat":"partial"}),onSuccess:t,onError:e,onProgress:function(t){l=l-u+t,u=t,a._emitProgress(l,s)},onUploadUrlAvailable:function(){a._parallelUploadUrls[i]=r.url,a._parallelUploadUrls.filter(function(t){return Boolean(t)}).length===f.length&&a._saveUploadInUrlStorage()}}),r=new c(n,t);r.start(),a._parallelUploads.push(r)})})}));Promise.all(e).then(function(){(r=a._openRequest("POST",a.options.endpoint)).setHeader("Upload-Concat","final;".concat(a._parallelUploadUrls.join(" ")));var t=_(a.options.metadata);return""!==t&&r.setHeader("Upload-Metadata",t),a._sendRequest(r,null)}).then(function(t){var e;S(t.getStatus(),200)?null==(e=t.getHeader("Location"))?a._emitHttpError(r,t,"tus: invalid or missing Location header"):(a.url=R(a.options.endpoint,e),(0,u.log)("Created upload at ".concat(a.url)),a._emitSuccess(t)):a._emitHttpError(r,t,"tus: unexpected response while creating upload")}).catch(function(t){a._emitError(t)})}},{key:"_startSingleUpload",value:function(){this._aborted=!1,null!=this.url?((0,u.log)("Resuming upload from previous URL: ".concat(this.url)),this._resumeUpload()):null!=this.options.uploadUrl?((0,u.log)("Resuming upload from provided URL: ".concat(this.options.uploadUrl)),this.url=this.options.uploadUrl,this._resumeUpload()):((0,u.log)("Creating a new upload"),this._createUpload())}},{key:"abort",value:function(t){var e=this;if(null!=this._parallelUploads){var r,n=function(t,e){var r,n,o,i,u="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(u)return n=!(r=!0),{s:function(){u=u.call(t)},n:function(){var t=u.next();return r=t.done,t},e:function(t){n=!0,o=t},f:function(){try{r||null==u.return||u.return()}finally{if(n)throw o}}};if(Array.isArray(t)||(u=p(t))||e&&t&&"number"==typeof t.length)return u&&(t=u),i=0,{s:e=function(){},n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:e};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(this._parallelUploads);try{for(n.s();!(r=n.n()).done;)r.value.abort(t)}catch(t){n.e(t)}finally{n.f()}}return null!==this._req&&this._req.abort(),this._aborted=!0,null!=this._retryTimeout&&(clearTimeout(this._retryTimeout),this._retryTimeout=null),t&&null!=this.url?c.terminate(this.url,this.options).then(function(){return e._removeFromUrlStorage()}):Promise.resolve()}},{key:"_emitHttpError",value:function(t,e,r,n){this._emitError(new a.default(r,n,t,e))}},{key:"_emitError",value:function(t){var e,r=this;if(!this._aborted){if(null!=this.options.retryDelays)if(null!=this._offset&&this._offset>this._offsetBeforeRetry&&(this._retryAttempt=0),O(t,this._retryAttempt,this.options))return e=this.options.retryDelays[this._retryAttempt++],this._offsetBeforeRetry=this._offset,void(this._retryTimeout=setTimeout(function(){r.start()},e));if("function"!=typeof this.options.onError)throw t;this.options.onError(t)}}},{key:"_emitSuccess",value:function(t){this.options.removeFingerprintOnSuccess&&this._removeFromUrlStorage(),"function"==typeof this.options.onSuccess&&this.options.onSuccess({lastResponse:t})}},{key:"_emitProgress",value:function(t,e){"function"==typeof this.options.onProgress&&this.options.onProgress(t,e)}},{key:"_emitChunkComplete",value:function(t,e,r){"function"==typeof this.options.onChunkComplete&&this.options.onChunkComplete(t,e,r)}},{key:"_createUpload",value:function(){var r,t,n=this;this.options.endpoint?(r=this._openRequest("POST",this.options.endpoint),this.options.uploadLengthDeferred?r.setHeader("Upload-Defer-Length","1"):r.setHeader("Upload-Length","".concat(this._size)),""!==(t=_(this.options.metadata))&&r.setHeader("Upload-Metadata",t),(this.options.uploadDataDuringCreation&&!this.options.uploadLengthDeferred?(this._offset=0,this._addChunkToRequest(r)):(this.options.protocol!==m&&this.options.protocol!==b||r.setHeader("Upload-Complete","?0"),this._sendRequest(r,null))).then(function(t){var e;S(t.getStatus(),200)?null==(e=t.getHeader("Location"))?n._emitHttpError(r,t,"tus: invalid or missing Location header"):(n.url=R(n.options.endpoint,e),(0,u.log)("Created upload at ".concat(n.url)),"function"==typeof n.options.onUploadUrlAvailable&&n.options.onUploadUrlAvailable(),0===n._size?(n._emitSuccess(t),n._source.close()):n._saveUploadInUrlStorage().then(function(){n.options.uploadDataDuringCreation?n._handleUploadResponse(r,t):(n._offset=0,n._performUpload())})):n._emitHttpError(r,t,"tus: unexpected response while creating upload")}).catch(function(t){n._emitHttpError(r,null,"tus: failed to create upload",t)})):this._emitError(new Error("tus: unable to create upload because no endpoint is provided"))}},{key:"_resumeUpload",value:function(){var o=this,i=this._openRequest("HEAD",this.url);this._sendRequest(i,null).then(function(t){var e=t.getStatus();if(!S(e,200))return 423===e?void o._emitHttpError(i,t,"tus: upload is currently locked; retry later"):(S(e,400)&&o._removeFromUrlStorage(),o.options.endpoint?(o.url=null,void o._createUpload()):void o._emitHttpError(i,t,"tus: unable to resume upload (new upload cannot be created without an endpoint)"));var r,n=Number.parseInt(t.getHeader("Upload-Offset"),10);Number.isNaN(n)?o._emitHttpError(i,t,"tus: invalid or missing offset value"):(r=Number.parseInt(t.getHeader("Upload-Length"),10),Number.isNaN(r)&&!o.options.uploadLengthDeferred&&o.options.protocol===v?o._emitHttpError(i,t,"tus: invalid or missing length value"):("function"==typeof o.options.onUploadUrlAvailable&&o.options.onUploadUrlAvailable(),o._saveUploadInUrlStorage().then(function(){n===r?(o._emitProgress(r,r),o._emitSuccess(t)):(o._offset=n,o._performUpload())})))}).catch(function(t){o._emitHttpError(i,null,"tus: failed to resume upload",t)})}},{key:"_performUpload",value:function(){var e,r=this;this._aborted||(this.options.overridePatchMethod?(e=this._openRequest("POST",this.url)).setHeader("X-HTTP-Method-Override","PATCH"):e=this._openRequest("PATCH",this.url),e.setHeader("Upload-Offset","".concat(this._offset)),this._addChunkToRequest(e).then(function(t){S(t.getStatus(),200)?r._handleUploadResponse(e,t):r._emitHttpError(e,t,"tus: unexpected response while uploading chunk")}).catch(function(t){r._aborted||r._emitHttpError(e,null,"tus: failed to upload chunk at offset ".concat(r._offset),t)}))}},{key:"_addChunkToRequest",value:function(n){var o=this,e=this._offset,t=this._offset+this.options.chunkSize;return n.setProgressHandler(function(t){o._emitProgress(e+t,o._size)}),this.options.protocol===v?n.setHeader("Content-Type","application/offset+octet-stream"):this.options.protocol===b&&n.setHeader("Content-Type","application/partial-upload"),(t===Number.POSITIVE_INFINITY||t>this._size)&&!this.options.uploadLengthDeferred&&(t=this._size),this._source.slice(e