-
Notifications
You must be signed in to change notification settings - Fork 84
/
client.min.js
21 lines (21 loc) · 7.7 KB
/
client.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* Socket IO File Upload Client-Side Library
* Copyright (C) 2015 Shane Carr and others
* Released under the X11 License
* For more information, visit: https://github.com/sffc/socketio-file-upload
*/
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.owns=function(c,f){return Object.prototype.hasOwnProperty.call(c,f)};$jscomp.assign="function"==typeof Object.assign?Object.assign:function(c,f){for(var b=1;b<arguments.length;b++){var d=arguments[b];if(d)for(var e in d)$jscomp.owns(d,e)&&(c[e]=d[e])}return c};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;
$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(c,f,b){c!=Array.prototype&&c!=Object.prototype&&(c[f]=b.value)};$jscomp.getGlobal=function(c){return"undefined"!=typeof window&&window===c?c:"undefined"!=typeof global&&null!=global?global:c};$jscomp.global=$jscomp.getGlobal(this);
$jscomp.polyfill=function(c,f,b,d){if(f){b=$jscomp.global;c=c.split(".");for(d=0;d<c.length-1;d++){var e=c[d];e in b||(b[e]={});b=b[e]}c=c[c.length-1];d=b[c];f=f(d);f!=d&&null!=f&&$jscomp.defineProperty(b,c,{configurable:!0,writable:!0,value:f})}};$jscomp.polyfill("Object.assign",function(c){return c||$jscomp.assign},"es6","es3");
(function(c,f,b){"function"===typeof define&&define.amd?define([],b):"object"===typeof module&&module.exports?module.exports=b():c[f]=b()})(this,"SocketIOFileUpload",function(){return function(c,f){var b=this;if(!window.File||!window.FileReader)throw Error("Socket.IO File Upload: Browser Not Supported");window.siofu_global||(window.siofu_global={instances:0,downloads:0});var d={},e={},A={},z={},l={},h=function(a,b){return f?f[a]||b:b};b.fileInputElementId="siofu_input_"+window.siofu_global.instances++;
b.resetFileInputs=!0;b.useText=h("useText",!1);b.serializedOctets=h("serializedOctets",!1);b.useBuffer=h("useBuffer",!0);b.chunkSize=h("chunkSize",102400);b.topicName=h("topicName","siofu");b.wrapData=h("wrapData",!1);var E=function(){return"boolean"===typeof b.wrapData?!0:"object"===typeof b.wrapData&&!Array.isArray(b.wrapData)&&b.wrapData.wrapKey&&"string"===typeof b.wrapData.wrapKey.action&&"string"===typeof b.wrapData.wrapKey.message&&b.wrapData.unwrapKey&&"string"===typeof b.wrapData.unwrapKey.action&&
"string"===typeof b.wrapData.unwrapKey.message?!0:!1};b.exposePrivateFunction=h("exposePrivateFunction",!1);var m=function(a){return b.wrapData?b.topicName:b.topicName+a},x=function(a,g){if(!E()||!b.wrapData)return a;var c={};b.wrapData.additionalData&&Object.assign(c,b.wrapData.additionalData);var d=b.wrapData.wrapKey&&"string"===typeof b.wrapData.wrapKey.message?b.wrapData.wrapKey.message:"message";c[b.wrapData.wrapKey&&"string"===typeof b.wrapData.wrapKey.action?b.wrapData.wrapKey.action:"action"]=
g;c[d]=a;return c},v=function(a,g){var c=document.createEvent("Event");c.initEvent(a,!1,!1);for(var d in g)g.hasOwnProperty(d)&&(c[d]=g[d]);return b.dispatchEvent(c)},u=[],k=function(a,b,c,d){a.addEventListener(b,c,d);u.push(arguments)},B=function(a,b,c,d){a.removeEventListener&&a.removeEventListener(b,c,d)},H=function(){for(var a=u.length-1;0<=a;a--)B.apply(this,u[a]);u=[]},I=function(a){if(null!==b.maxFileSize&&a.size>b.maxFileSize)v("error",{file:a,message:"Attempt by client to upload file exceeding the maximum file size",
code:1});else if(v("start",{file:a})){var g=new FileReader,d=window.siofu_global.downloads++,f=!1,h=b.useText,l=0,u;g._realReader&&(g=g._realReader);e[d]=a;var w={id:d},y=b.chunkSize;if(y>=a.size||0>=y)y=a.size;var p=function(){if(!w.abort){var b=a.slice(l,Math.min(l+y,a.size));h?g.readAsText(b):g.readAsArrayBuffer(b)}},q=function(e){if(!w.abort){var F=Math.min(l+y,a.size);a:{var k=l;e=e.target.result;var q=!1;if(!h)try{var r=new Uint8Array(e);if(b.serializedOctets)e=r;else if(b.useBuffer)e=r.buffer;
else{q=!0;var t,p=r.buffer.byteLength,n="";for(t=0;t<p;t+=3)n+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[r[t]>>2],n+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(r[t]&3)<<4|r[t+1]>>4],n+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(r[t+1]&15)<<2|r[t+2]>>6],n+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[r[t+2]&63];2===p%3?n=n.substring(0,n.length-1)+"=":1===p%3&&(n=n.substring(0,n.length-2)+"==");e=n}}catch(K){c.emit(m("_done"),
x({id:d,interrupt:!0},"done"));break a}c.emit(m("_progress"),x({id:d,size:a.size,start:k,end:F,content:e,base64:q},"progress"))}v("progress",{file:a,bytesLoaded:F,name:u});l+=y;l>=a.size&&(c.emit(m("_done"),x({id:d},"done")),v("load",{file:a,reader:g,name:u}),f=!0)}};k(g,"load",q);k(g,"error",function(){c.emit(m("_done"),x({id:d,interrupt:!0},"done"));B(g,"load",q)});k(g,"abort",function(){c.emit(m("_done"),x({id:d,interrupt:!0},"done"));B(g,"load",q)});c.emit(m("_start"),x({name:a.name,mtime:a.lastModified,
meta:a.meta,size:a.size,encoding:h?"text":"octet",id:d},"start"));z[d]=function(a){u=a;p()};A[d]=function(){f||p()};return w}},w=function(a){if(0!==a.length){for(var b=0;b<a.length;b++)a[b].meta||(a[b].meta={});if(v("choose",{files:a}))for(b=0;b<a.length;b++){var c=I(a[b]);l[c.id]=c}}},p=function(a){var c=a.target.files||a.dataTransfer.files;a.preventDefault();w(c);if(b.resetFileInputs){try{a.target.value=""}catch(J){}if(a.target.value){c=document.createElement("form");var d=a.target.parentNode,e=
a.target.nextSibling;c.appendChild(a.target);c.reset();d.insertBefore(a.target,e)}}};this.submitFiles=function(a){a&&w(a)};this.listenOnSubmit=function(a,b){b.files&&k(a,"click",function(){w(b.files)},!1)};this.listenOnArraySubmit=function(a,b){for(var c in b)this.listenOnSubmit(a,b[c])};this.listenOnInput=function(a){a.files&&k(a,"change",p,!1)};this.listenOnDrop=function(a){k(a,"dragover",function(a){a.preventDefault()},!1);k(a,"drop",p)};this.prompt=function(){var a=document.getElementById(b.fileInputElementId);
a||(a=document.createElement("input"),a.setAttribute("type","file"),a.setAttribute("id",b.fileInputElementId),a.style.display="none",document.body.appendChild(a));k(a,"change",p,!1);var c=document.createEvent("MouseEvents");c.initMouseEvent("click",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null);a.dispatchEvent(c)};this.destroy=function(){H();var a=document.getElementById(b.fileInputElementId);a&&a.parentNode.removeChild(a);for(var c in l)l.hasOwnProperty(c)&&(l[c].abort=!0);l=z=e=d=null};this.addEventListener=
function(a,b){d[a]||(d[a]=[]);d[a].push(b)};this.removeEventListener=function(a,b){if(!d[a])return!1;for(var c=0;c<d[a].length;c++)if(d[a][c]===b)return d[a].splice(c,1),!0;return!1};this.dispatchEvent=function(a){var b=d[a.type];if(!b)return!0;for(var c=!0,e=0;e<b.length;e++)!1===b[e](a)&&(c=!1);return c};h=function(a){if(A[a.id])A[a.id]()};var q=function(a){if(z[a.id])z[a.id](a.name)},C=function(a){e[a.id]&&v("complete",{file:e[a.id],detail:a.detail,success:a.success})},D=function(a){e[a.id]&&(v("error",
{file:e[a.id],message:a.message,code:0}),l&&(l[a.id].abort=!0))};if(E()&&b.wrapData){var G={chunk:h,ready:q,complete:C,error:D};k(c,m(),function(a){if("object"!==typeof a)console.log("SocketIOFileUploadClient Error: You choose to wrap your data so the message from the server need to be an object");else{var c=a[b.wrapData.unwrapKey&&"string"===typeof b.wrapData.unwrapKey.action?b.wrapData.unwrapKey.action:"action"];a=a[b.wrapData.unwrapKey&&"string"===typeof b.wrapData.unwrapKey.message?b.wrapData.unwrapKey.message:
"message"];if(c&&a&&G[c])G[c](a);else console.log("SocketIOFileUploadClient Error: You choose to wrap your data but the message from the server is wrong configured. Check the message and your wrapData option")}})}else k(c,m("_chunk"),h),k(c,m("_ready"),q),k(c,m("_complete"),C),k(c,m("_error"),D);this.exposePrivateFunction&&(this.chunckCallback=h,this.readyCallback=q,this.completCallback=C,this.errorCallback=D)}});