You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
10 lines
22 KiB
10 lines
22 KiB
3 years ago
|
/*!
|
||
|
* Uploader - Uploader library implements html5 file upload and provides multiple simultaneous, stable, fault tolerant and resumable uploads
|
||
|
* @version v0.5.6
|
||
|
* @author dolymood <dolymood@gmail.com>
|
||
|
* @link https://github.com/simple-uploader/Uploader
|
||
|
* @license MIT
|
||
|
*/
|
||
|
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.Uploader=e()}}(function(){return function r(n,o,a){function h(i,e){if(!o[i]){if(!n[i]){var t="function"==typeof require&&require;if(!e&&t)return t(i,!0);if(u)return u(i,!0);throw new Error("Cannot find module '"+i+"'")}var s=o[i]={exports:{}};n[i][0].call(s.exports,function(e){var t=n[i][1][e];return h(t||e)},s,s.exports,r,n,o,a)}return o[i].exports}for(var u="function"==typeof require&&require,e=0;e<a.length;e++)h(a[e]);return h}({1:[function(e,t,i){var h=e("./utils");function s(e,t,i){h.defineNonEnumerable(this,"uploader",e),h.defineNonEnumerable(this,"file",t),h.defineNonEnumerable(this,"bytes",null),this.offset=i,this.tested=!1,this.retries=0,this.pendingRetry=!1,this.preprocessState=0,this.readState=0,this.loaded=0,this.total=0,this.chunkSize=this.uploader.opts.chunkSize,this.startByte=this.offset*this.chunkSize,this.endByte=this.computeEndByte(),this.xhr=null}var o=s.STATUS={PENDING:"pending",UPLOADING:"uploading",READING:"reading",SUCCESS:"success",ERROR:"error",COMPLETE:"complete",PROGRESS:"progress",RETRY:"retry"};h.extend(s.prototype,{_event:function(e,t){(t=h.toArray(arguments)).unshift(this),this.file._chunkEvent.apply(this.file,t)},computeEndByte:function(){var e=Math.min(this.file.size,(this.offset+1)*this.chunkSize);return this.file.size-e<this.chunkSize&&!this.uploader.opts.forceChunkSize&&(e=this.file.size),e},getParams:function(){return{chunkNumber:this.offset+1,chunkSize:this.uploader.opts.chunkSize,currentChunkSize:this.endByte-this.startByte,totalSize:this.file.size,identifier:this.file.uniqueIdentifier,filename:this.file.name,relativePath:this.file.relativePath,totalChunks:this.file.chunks.length}},getTarget:function(e,t){return t.length?(e.indexOf("?")<0?e+="?":e+="&",e+t.join("&")):e},test:function(){this.xhr=new XMLHttpRequest,this.xhr.addEventListener("load",s,!1),this.xhr.addEventListener("error",s,!1);var e=h.evalOpts(this.uploader.opts.testMethod,this.file,this),t=this.prepareXhrRequest(e,!0);this.xhr.send(t);var i=this;function s(e){var t=i.status(!0);t===o.ERROR?(i._event(t,i.message()),i.uploader.uploadNextChunk()):t===o.SUCCESS?(i._event(t,i.message()),i.tested=!0):i.file.paused||(i.tested=!0,i.send())}},preprocessFinished:function(){this.endByte=this.computeEndByte(),this.preprocessState=2,this.send()},readFinished:function(e){this.readState=2,this.bytes=e,this.send()},send:function(){var e=this.uploader.opts.preprocess,t=this.uploader.opts.readFileFn;if(h.isFunction(e))switch(this.preprocessState){case 0:return this.preprocessState=1,void e(this);case 1:return}switch(this.readState){case 0:return this.readState=1,void t(this.file,this.file.fileType,this.startByte,this.endByte,this);case 1:return}if(!this.uploader.opts.testChunks||this.tested){this.loaded=0,this.total=0,this.pendingRetry=!1,this.xhr=new XMLHttpRequest,this.xhr.upload.addEventListener("progress",function(e){e.lengthComputable&&(r.loaded=e.loaded,r.total=e.total);r._event(o.PROGRESS,e)},!1),this.xhr.addEventListener("load",n,!1),this.xhr.addEventListener("error",n,!1);var i=h.evalOpts(this.uploader.opts.uploadMethod,this.file,this),s=this.prepareXhrRequest(i,!1,this.uploader.opts.method,this.bytes);this.xhr.send(s);var r=this}else this.test();function n(e){var t=r.message();r.processingResponse=!0,r.uploader.opts.processResponse(t,function(e,t){if(r.processingResponse=!1,r.xhr){r.processedState={err:e,res:t};var i=r.status();if(i===o.SUCCESS||i===o.ERROR)r._event(i,t),i===o.ERROR&&r.uploader.uploadNextChunk();else{r._event(o.RETRY,t),r.pendingRetry=!0,r.abort(),r.retries++;var s=r.uploader.opts.chunkRetryInterval;null!==s?setTimeout(function(){r.send()},s):r.send()}}},r.file,r)}},abort:function(){var e=this.xhr;this.xhr=null,this.processingResponse=!1,this.processedState=null,e&&e.abort()},status:function(e){if(1===this.readState)return o.READING;if(this.pendingRetry||1===this.preprocessSta
|
||
|
//# sourceMappingURL=uploader.min.js.map
|