diff --git a/lib/client/dom.js b/lib/client/dom.js index 1f845a62..55750786 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -466,80 +466,6 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; }); } - function twopack(operation) { - var op, - RESTful = DOM.RESTful, - Images = DOM.Images, - Info = DOM.CurrentInfo, - name = Info.name, - path = Info.path, - dirPath = Info.dirPath, - activeFiles = DOM.getActiveFiles(), - names = DOM.getSelectedNames(activeFiles), - fileFrom; - - Util.check(arguments, ['operation']); - - if (!names.length) { - Dialog.alert.noFiles(); - } else { - switch(operation) { - case 'extract': - op = RESTful.extract; - - fileFrom = { - from : path, - to : dirPath - }; - - name = name.replace(/\.tar\.gz$/, ''); - - break; - - case 'pack': - op = RESTful.pack; - - if (names.length > 1) - name = Info.dir; - - name += '.tar.gz'; - - fileFrom = { - from : dirPath, - to : dirPath + name, - names : names - }; - break; - } - - Images.show.load('top'); - - op(fileFrom, function(error) { - !error && CloudCmd.refresh(null, function() { - var file = DOM.getCurrentByName(name); - - DOM.setCurrentFile(file); - }); - }); - } - } - - /** - * zip file - * - */ - this.pack = function() { - twopack('pack'); - }; - - /** - * unzip file - * - */ - this.extract = function() { - twopack('extract'); - }; - /** * get current direcotory name */ diff --git a/lib/client/menu.js b/lib/client/menu.js index 20e767ed..df1786b4 100644 --- a/lib/client/menu.js +++ b/lib/client/menu.js @@ -171,8 +171,12 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO; 'Delete' : function() { CloudCmd.Operation.show('delete'); }, - 'Pack' : DOM.pack, - 'Extract' : DOM.extract, + 'Pack' : function() { + CloudCmd.Operation.show('pack'); + }, + 'Extract' : function() { + CloudCmd.Operation.show('extract'); + }, 'Upload To' : {}, 'Download' : download, 'Cut' : Buffer.cut, diff --git a/lib/client/operation.js b/lib/client/operation.js index eda0ad0b..e8ea2be5 100644 --- a/lib/client/operation.js +++ b/lib/client/operation.js @@ -4,6 +4,7 @@ /* global rendy */ /* global spero */ /* global remedy */ +/* global ishtar */ (function(CloudCmd, Util, DOM, rendy) { 'use strict'; @@ -18,6 +19,8 @@ copyFn = RESTful.cp, moveFn = RESTful.mv, deleteFn = RESTful.delete, + packFn = RESTful.pack, + extractFn = RESTful.extract, Images = DOM.Images, Dialog = DOM.Dialog, @@ -86,6 +89,26 @@ }); }); + ishtar(function() { + ishtar.on('connect', function() { + packFn = function(data, callback) { + setListeners(ishtar, callback); + + ishtar.pack(data.from, data.to, data.names); + }; + + extractFn = function(data, callback) { + setListeners(ishtar, callback); + ishtar.pack(data.from, data.to); + }; + }); + + ishtar.on('disconnect', function() { + packFn = RESTful.pack; + extractFn = RESTful.extract; + }); + }); + Util.exec(callback); } @@ -149,6 +172,16 @@ case 'delete:silent': Operation.deleteShift(); + break; + + case 'pack': + Operation.pack(); + break; + + case 'extract': + Operation.extract(); + break; + } }; @@ -168,6 +201,15 @@ deleteSilent(); }; + this.pack = function() { + twopack('pack'); + }; + + this.extract = function() { + twopack('extract'); + }; + + /** * prompt and delete current file or selected files * @@ -345,6 +387,63 @@ } } + function twopack(operation) { + var op, + Images = DOM.Images, + Info = DOM.CurrentInfo, + name = Info.name, + path = Info.path, + dirPath = Info.dirPath, + activeFiles = DOM.getActiveFiles(), + names = DOM.getSelectedNames(activeFiles), + fileFrom; + + Util.check(arguments, ['operation']); + + if (!names.length) { + Dialog.alert.noFiles(); + } else { + switch(operation) { + case 'extract': + op = extractFn; + + fileFrom = { + from : path, + to : dirPath + }; + + name = name.replace(/\.tar\.gz$/, ''); + + break; + + case 'pack': + op = packFn; + + if (names.length > 1) + name = Info.dir; + + name += '.tar.gz'; + + fileFrom = { + from : dirPath, + to : dirPath + name, + names : names + }; + break; + } + + Images.show.load('top'); + + op(fileFrom, function(error) { + !error && CloudCmd.refresh(null, function() { + var file = DOM.getCurrentByName(name); + + DOM.setCurrentFile(file); + }); + }); + } + } + function message(msg) { return function(to, names) { var ret, @@ -369,7 +468,8 @@ function load(callback) { var files = [ '/spero/spero.js', - '/remedy/remedy.js' + '/remedy/remedy.js', + '/ishtar/ishtar.js' ]; DOM.load.parallel(files, function(error) { diff --git a/lib/cloudcmd.js b/lib/cloudcmd.js index 330cd6e6..1bb9b29e 100644 --- a/lib/cloudcmd.js +++ b/lib/cloudcmd.js @@ -24,6 +24,7 @@ dword = require('dword'), spero = require('spero'), remedy = require('remedy'), + ishtar = require('ishtar'), root = function() { return config('root'); @@ -104,6 +105,10 @@ remedy.listen(socket, { root: root }); + + ishtar.listen(socket, { + root: root + }); } function cloudcmd(prefix, socket) { @@ -171,6 +176,11 @@ online: isOnline }), + ishtar({ + minify: isMinify, + online: isOnline + }), + mollify({ dir : DIR_ROOT, is : isMinify diff --git a/package.json b/package.json index 456c9513..f539efe2 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "flop": "~1.3.0", "format-io": "~0.9.6", "http-auth": "~2.2.3", + "ishtar": "~1.0.0", "jaguar": "~1.1.0", "join-io": "~1.4.0", "jonny": "~1.0.0",