UNPKG

cloudcmd

Version:

File manager for the web with console and editor

2 lines 6.84 kB
!function(e){function t(t){for(var o,a,c=t[0],s=t[1],l=t[2],f=0,p=[];f<c.length;f++)a=c[f],Object.prototype.hasOwnProperty.call(r,a)&&r[a]&&p.push(r[a][0]),r[a]=0;for(o in s)Object.prototype.hasOwnProperty.call(s,o)&&(e[o]=s[o]);for(u&&u(t);p.length;)p.shift()();return i.push.apply(i,l||[]),n()}function n(){for(var e,t=0;t<i.length;t++){for(var n=i[t],o=!0,c=1;c<n.length;c++){var s=n[c];0!==r[s]&&(o=!1)}o&&(i.splice(t--,1),e=a(a.s=n[0]))}return e}var o={},r={14:0},i=[];function a(t){if(o[t])return o[t].exports;var n=o[t]={i:t,l:!1,exports:{}};return e[t].call(n.exports,n,n.exports,a),n.l=!0,n.exports}a.m=e,a.c=o,a.d=function(e,t,n){a.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,t){if(1&t&&(e=a(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(a.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)a.d(n,o,function(t){return e[t]}.bind(null,o));return n},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="/dist/";var c=window.webpackJsonp=window.webpackJsonp||[],s=c.push.bind(c);c.push=t,c=c.slice();for(var l=0;l<c.length;l++)t(c[l]);var u=s;i.push([106,0]),n()}({106:function(e,t,n){"use strict";const o=n(0),r=n(8),{promisify:i}=n(13),a=n(5),c=n(4),s=n(3),{encode:l}=n(17),u=n(107),f=n(108),p=n(111);CloudCmd.Operation=t;const{config:m}=CloudCmd,{Dialog:d,Images:g}=DOM,h=r((function(e,t){const n=r(t),o=r(d.alert);e.on("accept",n(e)),e.on("reject",o("Wrong credentials!")),e.emit("auth",m("username"),m("password"))})),y={};let O,v,C,b,M,D,x;const w=DOM.CurrentInfo,k=g.show.load.bind(null,"top"),P=o((async function(e,t){let n,o,r,i,a,c="",s="",u=[];t?(({from:c,to:s,names:u}=t),({panel:r}=w)):(c=w.dirPath,s=DOM.getNotCurrentDirPath(),n=DOM.getSelectedFiles(),u=DOM.getFilenames(n),t={},i=!0,r=w.panelPassive);u.length||u.push(DOM.getCurrentName());const[f]=u,p=DOM.getCurrentByName(f,r);if(!t&&j())return;const{type:g}=e,h="copy"===g,y=h?"confirmCopy":"confirmMove",O=h?"Copy":"Rename/Move",b=h?v:C;if(i&&m(y)){const[e,t]=await async function(e,t,n){const o=n.length,[r]=n;e+=" ",n.length>1?e+=o+" file(s)":e+=`"${r}"`;return e+=" to",await d.prompt(e,t)}(O,s,u.map(l));return void(e||M(t))}function M(e){if(a=c!==e&&e,a&&!i||!p)return n();const t=`"${f}" already exist. Overwrite?`;function n(){k(),o={from:c,to:e,names:u},b(o,async()=>{await DOM.Storage.remove(c);const{panel:e,panelPassive:t}=w;w.isOnePanel||CloudCmd.refresh({panel:t,noCurrent:!0}),CloudCmd.refresh({panel:e})})}d.confirm(t,{cancel:!1}).then(n)}M(s)})),j=()=>{const{length:e}=DOM.getActiveFiles(),t=Boolean(!e);return t?d.alert.noFiles():t};e.exports.init=i(e=>{k(),a.series([DOM.loadSocket,async e=>{if(m("dropbox"))return e();const{prefix:t,prefixSocket:n}=CloudCmd;await async function(){const{prefix:e}=CloudCmd,t=e+"/fileop/fileop.js",[n]=await s(c.js,t);n&&d.alert(n.message);O=!0}(),await async function(e,t,n){t+="/fileop";const o=await fileop({prefix:e,socketPrefix:t});o.on("connect",h(o,F(n)))}(t,n,e)},e=>{O=!0,g.hide(),e()}],e)});const F=o((e,t)=>{!function(e){x=({from:t,to:n,names:o},r)=>{const i=f({operation:"Tar",callback:r,noContinue:!0,from:t,to:n});e.tar(t,n,o).then(i)},D=({from:t,to:n,names:o},r)=>{const i=f({operation:"Zip",callback:r,noContinue:!0,from:t,to:n});e.zip(t,n,o).then(i)},b=(t,n,o)=>{t=t.replace(/\?.*/,"");const r=f({operation:"Delete",callback:o,from:t});e.remove(t,n).then(r)},v=({from:t,to:n,names:o},r)=>{const i=f({operation:"Copy",callback:r,from:t,to:n,names:o});e.copy(t,n,o).then(i)},C=({from:t,to:n,names:o},r)=>{const i=f({operation:"Move",callback:r,from:t,to:n});e.move(t,n,o).then(i)},M=({from:t,to:n},o)=>{const r=f({operation:"Extract",callback:o,noContinue:!0,from:t,to:n});e.extract(t,n).then(r)}}(t),e()});function S(e=DOM.getActiveFiles()){const t=w.dirPath;if(j())return;k();const n=DOM.getFilenames(e),o=DOM.CurrentInfo.files.map(DOM.getCurrentName),r=DOM.getCurrentName(),i=p(r,o,n);b(t+"?files",n,async()=>{await CloudCmd.refresh();const e=w.files.map(DOM.getCurrentName).includes(r)?r:i;DOM.setCurrentByName(e)})}function N(e,t){let n,o,r=w.name;const{path:i,dirPath:a}=w,c=DOM.getActiveFiles(),s=DOM.getFilenames(c);if(function(e,t){if(!t)throw Error(e+" could not be empty!")}("operation",e),!s.length)return d.alert.noFiles();switch(e){case"extract":n=M,o={from:i,to:a},r=u(r);break;case"pack":n=function(e){return"zip"===e?D:x}(t),s.length>1&&(r=w.dir),r+=DOM.getPackerExt(t),o={from:a,to:a+r,names:s}}k(),n(o,e=>{!e&&CloudCmd.refresh({currentName:r})})}e.exports.hide=()=>{CloudCmd.View.hide()},e.exports.show=(e,t)=>{if(O)return"copy"===e?y.copy(t):"move"===e?y.move(t):"delete"===e?y.delete():"delete:silent"===e?y.deleteSilent():"pack"===e?y.pack():"extract"===e?y.extract():void 0},y.copy=P({type:"copy"}),y.move=P({type:"move"}),y.delete=async function(){if(j())return;const e="Do you really want to delete the ",t=DOM.getActiveFiles(),n=DOM.getFilenames(t),o=n.length;let r;if(o){let t="";for(let e=0;e<5&&e<o;e++)t+="\n"+n[e];o>=5&&(t+="\n..."),r=e+"selected "+o+" files/directories?\n"+l(t)}else{const t=DOM.getCurrentFile(),n=DOM.isCurrentIsDir(t),o=(e=>e?"directory":"file")(n)+" ",i=DOM.getCurrentName(t);r=e+"selected "+o+i+"?"}const[i]=await d.confirm(r);if(i)return;S(t)},y.deleteSilent=S,y.pack=()=>{N("pack","zip"===m("packer")?"zip":"tar")},y.extract=()=>{N("extract")}},107:function(e,t,n){"use strict";const{getExt:o}=n(10);e.exports=e=>{const t=function(e){return/\.tar\.gz$/.test(e)?".tar.gz":/\.tar\.bz2$/.test(e)?".tar.bz2":o(e)}(e);return e.replace(t,"")}},108:function(e,t,n){"use strict";const o=n(109),r=n(8),i=n(110),{Dialog:a,Images:c}=DOM;e.exports=e=>t=>{const{operation:n,callback:s,noContinue:l,from:u,to:f}=e;let p,m;const d=r(({emitter:e,operation:t})=>{e.abort();const n=t+" aborted";m=!0,a.alert(n,{cancel:!1})}),g=t.removeListener.bind(t),h=t.on.bind(t),y=i(n,u,f),O=a.progress(y);O.catch(d({emitter:t,operation:n}));const v={progress:e=>{p=100===e,O.setProgress(e)},end:()=>{c.hide(),o(g,v),O.remove(),(m||p)&&s()},error:async e=>{if(m=e,l)return v.end(e),a.alert(e),void O.remove();const[n]=await a.confirm(e+"\n Continue?");if(!p&&!n)return t.continue();t.abort(),O.remove()}};o(h,v)}},110:function(e,t,n){"use strict";e.exports=(e,t,n)=>n?`${e} ${t} -> ${n}`:`${e} ${t}`},111:function(e,t,n){"use strict";const o=n(0),r=o((e,t)=>!e.includes(t)),i=o((e,t)=>e.filter(r(t)));e.exports=(e,t,n)=>{const o=t.indexOf(e),r=i(t,n),{length:a}=r;return r[o]?r[o]:r[a-1]}}}); //# sourceMappingURL=operation.js.map