window.elFinderSupportVer1=function(e){"use strict";var r,a,t,i=this,n=function(e){return e.replace("Today",a).replace("Yesterday",t)};r=new Date,a=r.getFullYear()+"/"+(r.getMonth()+1)+"/"+r.getDate(),r=new Date(Date.now()-864e5),t=r.getFullYear()+"/"+(r.getMonth()+1)+"/"+r.getDate(),this.upload=e||"auto",this.init=function(e){this.fm=e,this.fm.parseUploadData=function(e){var r;if(!$.trim(e))return{error:["errResponse","errDataEmpty"]};try{r=JSON.parse(e)}catch(a){return{error:["errResponse","errDataNotJSON"]}}return i.normalize("upload",r)}},this.send=function(e){var r,a,t=this,i=this.fm,n=$.Deferred(),s=e.data.cmd,d={};switch(n.abort=function(){"pending"==a.state()&&(a.quiet=!0,a.abort())},s){case"open":e.data.tree=1;break;case"parents":case"tree":return n.resolve({tree:[]});case"get":e.data.cmd="read",e.data.current=i.file(e.data.target).phash;break;case"put":e.data.cmd="edit",e.data.current=i.file(e.data.target).phash;break;case"archive":case"rm":e.data.current=i.file(e.data.targets[0]).phash;break;case"extract":case"rename":case"resize":e.data.current=i.file(e.data.target).phash;break;case"duplicate":return d=$.extend(!0,{},e),$.each(e.data.targets,(function(e,r){$.ajax(Object.assign(d,{data:{cmd:"duplicate",target:r,current:i.file(r).phash}})).fail((function(e){i.error(i.res("error","connect"))})).done((function(e){e=t.normalize("duplicate",e),e.error?i.error(e.error):e.added&&i.trigger("add",{added:e.added})}))})),n.resolve({});case"mkdir":case"mkfile":e.data.current=e.data.target;break;case"paste":e.data.current=e.data.dst,e.data.tree||$.each(e.data.targets,(function(r,a){if(i.file(a)&&"directory"===i.file(a).mime)return e.data.tree="1",!1}));break;case"size":return n.resolve({error:i.res("error","cmdsupport")});case"search":return n.resolve({error:i.res("error","cmdsupport")});case"file":e.data.cmd="open",e.data.current=i.file(e.data.target).phash;break}return a=$.ajax(e).fail((function(e){n.reject(e)})).done((function(e){r=t.normalize(s,e),n.resolve(r)})),n},this.normalize=function(e,r){var a,t,i,s,d=this,o=this.fm,c={},m=function(e){return e&&e.hash&&e.name&&e.mime?e:null},h=function(e){return $.grep(e,(function(e){return!(!e||!e.mime||"directory"!==e.mime)}))},l=function(e){var r=h(e);if(s=o.diff(r,null,["date","ts"]),s.added.length&&(s.added=h(s.added)),s.changed.length&&(s.changed=h(s.changed)),s.removed.length){var a=[];$.each(s.removed,(function(e,r){var t;(t=o.file(r))&&"directory"===t.mime&&a.push(r)})),s.removed=a}return s};return"tmb"==e||"get"==e?r:("upload"==e&&r.error&&r.cwd&&(r.warning=Object.assign({},r.error),r.error=!1),r.error?r:"put"==e?(a=o.file(r.target.hash).phash,{changed:[this.normalizeFile(r.target,a)]}):(a=r.cwd.hash,i=a==o.cwd().hash,r.tree&&$.each(this.normalizeTree(r.tree),(function(e,r){c[r.hash]=r})),$.each(r.cdc||[],(function(e,t){var i,s=t.hash;c[s]?(t.date&&(i=Date.parse(n(t.date)),i&&!isNaN(i)?c[s].ts=Math.floor(i/1e3):c[s].date=t.date||o.formatDate(t)),c[s].locked=t.hash==a||void 0!==t.rm&&!t.rm):c[s]=d.normalizeFile(t,a,r.tmb)})),r.tree||$.each(o.files(),(function(e,r){c[e]||r.phash==a||"directory"!=r.mime||(c[e]=r)})),"open"==e?{cwd:c[a]||this.normalizeFile(r.cwd),files:$.map(c,(function(e){return e})),options:d.normalizeOptions(r),init:!!r.params,debug:r.debug}:(i?t=o.diff($.map(c,m)):r.tree&&"paste"!==e?t=l(c):(t={added:[],removed:[],changed:[]},"paste"===e&&(t.sync=!0)),Object.assign({current:r.cwd.hash,error:r.error,warning:r.warning,options:{tmb:!!r.tmb}},t))))},this.normalizeTree=function(e){var r=this,a=[],t=function(e,i){var n,s;for(n=0;n<e.length;n++)s=e[n],a.push(r.normalizeFile(s,i)),s.dirs.length&&t(s.dirs,s.hash)};return t([e]),a},this.normalizeFile=function(e,r,a){var t=e.mime||"directory",i="directory"!=t||e.linkTo?e.size:0,s=e.date?Date.parse(n(e.date)):void 0,d={url:e.url,hash:e.hash,phash:r,name:e.name,mime:t,ts:e.ts,size:i,read:e.read,write:e.write,locked:!r||void 0!==e.rm&&!e.rm};return d.ts||(s&&!isNaN(s)?d.ts=Math.floor(s/1e3):d.date=e.date||this.fm.formatDate(e)),"application/x-empty"!=e.mime&&"inode/x-empty"!=e.mime||(d.mime="text/plain"),e.linkTo&&(d.alias=e.linkTo),e.linkTo&&(d.linkTo=e.linkTo),e.tmb?d.tmb=e.tmb:0===d.mime.indexOf("image/")&&a&&(d.tmb=1),e.dirs&&e.dirs.length&&(d.dirs=!0),e.dim&&(d.dim=e.dim),e.resize&&(d.resize=e.resize),d},this.normalizeOptions=function(e){var r={path:e.cwd.rel,disabled:$.merge(e.disabled||[],["search","netmount","zipdl"]),tmb:!!e.tmb,copyOverwrite:!0};return e.params&&(r.api=1,r.url=e.params.url,r.archivers={create:e.params.archives||[],extract:e.params.extract||[]}),-1!==r.path.indexOf("/")?r.separator="/":-1!==r.path.indexOf("\\")&&(r.separator="\\"),r}};