feature(cloudcmd) jag -> jaguar: add ability to pack couple files in one directory

This commit is contained in:
coderaiser 2015-07-02 10:58:28 -04:00
parent 54bf705240
commit cc8693be60
4 changed files with 140 additions and 80 deletions

View file

@ -460,46 +460,57 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
});
}
function twopack(current, operation) {
function twopack(operation) {
var op,
nameDir = '',
nameFile = '',
RESTful = DOM.RESTful,
Images = DOM.Images,
name = Cmd.getCurrentName(current),
dir = Cmd.getCurrentDirPath(),
path = dir + name,
fileFrom = {
from : path
};
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 (name === '..') {
if (!names.length) {
Dialog.alert('No files selected!');
} else {
if (operation.pack) {
op = RESTful.pack;
nameDir = name + '.tar.gz';
nameFile = name + '.gz';
} else if (operation.unpack) {
switch(operation) {
case 'unpack':
op = RESTful.unpack;
nameDir = name.replace('.tar.gz', '');
nameFile = name.replace('.gz', '');
fileFrom = {
from : path,
to : dirPath
};
name = name.replace(/\.tar\.gz$/, '');
break;
case 'pack':
op = RESTful.pack;
name += '.tar.gz';
fileFrom = {
from : dirPath,
to : dirPath,
names : names
};
break;
}
Images.show.load();
Images.show.load('top');
if (name && name !== '..')
op(fileFrom, function() {
CloudCmd.refresh(null, function() {
var byName = DOM.getCurrentByName,
dir = byName(nameDir),
file = byName(nameFile);
DOM.setCurrentFile(dir || file);
});
op(fileFrom, function() {
CloudCmd.refresh(null, function() {
var file = DOM.getCurrentByName(name);
DOM.setCurrentFile(file);
});
});
}
}
@ -507,20 +518,16 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
* zip file
*
*/
this.pack = function(current) {
twopack(current, {
pack: true
});
this.pack = function() {
twopack('pack');
};
/**
* unzip file
*
*/
this.unpack = function(current) {
twopack(current, {
unpack: true
});
this.unpack = function() {
twopack('unpack');
};
/**
@ -622,9 +629,10 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
this.getActiveFiles = function() {
var current = DOM.getCurrentFile(),
files = DOM.getSelectedFiles(),
selected = ~files.indexOf(current);
selected = ~files.indexOf(current),
name = DOM.getCurrentName(current);
if (!selected)
if (!selected && name !== '..')
files.push(current);
return files;

View file

@ -171,8 +171,8 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
setTimeout(DOM.renameCurrent, 100);
},
'Delete' : Operation.show.bind(null, 'delete'),
'Pack' : getActiveFunc(DOM.pack),
'Unpack' : getActiveFunc(DOM.unpack),
'Pack' : DOM.pack,
'Unpack' : DOM.unpack,
'Upload To' : {},
'Download' : download,
'Cut' : Buffer.cut,
@ -305,12 +305,6 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
});
}
function getActiveFunc(callback) {
return function() {
DOM.getActiveFiles().forEach(callback);
};
}
function getCurrentPosition() {
var current = Info.element,
rect = current.getBoundingClientRect();

View file

@ -23,7 +23,7 @@
markdown = require(DIR + 'rest/markdown'),
github = require('faust'),
packer = require('jag'),
jaguar = require('jaguar'),
flop = require('flop'),
pipe = require('pipe-io'),
@ -173,7 +173,7 @@
* @param pParams {command, method, body, requrest, response}
*/
function onPUT(name, body, callback) {
var cmd, files, data, from, to, msg;
var cmd, files, data, msg;
check
.type('callback', callback, 'function')
@ -237,43 +237,17 @@
break;
case 'pack':
if (!files.from) {
if (!files.from)
callback(body);
} else {
from = root(files.from);
if (files.to)
to = root(files.to);
else
to = from + '.gz';
packer.pack(from, to, function(error) {
var name = path.basename(files.from),
msg = formatMsg('pack', name);
callback(error, msg);
});
}
else
pack(files.from, files.to, files.names, callback);
break;
case 'unpack':
if (!files.from) {
if (!files.from)
callback(body);
} else {
from = root(files.from);
if (files.to)
to = root(files.to);
else
to = files.from.replace(/(\.gz|\.tar\.gz)$/, '');
packer.unpack(from, to, function(error) {
var name = path.basename(files.from),
data = formatMsg('unpack', name);
callback(error, data);
});
}
else
unpack(files.from, files.to, callback);
break;
@ -283,6 +257,90 @@
}
}
function pack(from, to, names, fn) {
var name;
from = root(from);
if (to)
to = root(to);
else
to = from;
if (names.length > 1) {
name = path.basename(to);
} else {
name = names[0];
}
to = path.join(to, name);
if (!/\.tar\.gz$/.test(to)) {
to += '.tar.gz';
}
if (!names) {
names = [
path.basename(from)
];
from = path.dirname(from);
}
operation('pack', from, to, names, fn);
}
function unpack(from, to, fn) {
from = root(from);
if (to)
to = root(to);
else
to = from.replace(/\.tar\.gz$/, '');
operation('extract', from, to, fn);
}
function operation(op, from, to, names, fn) {
var packer, wasError;
if (!fn) {
fn = names;
names = [
path.basename(from)
];
}
console.log(from, to, names);
packer = jaguar[op](from, to, names);
packer.on('error', function(error) {
wasError = true;
fn(error);
});
packer.on('progress', function(count) {
process.stdout.write(rendy('\r{{ operation }} "{{ name }}": {{ count }}%', {
operation : op,
name : names[0],
count : count
}));
});
packer.on('end', function() {
var name, msg;
process.stdout.write('\n');
if (!wasError) {
name = path.basename(from),
msg = formatMsg(op, name);
fn(null, msg);
}
});
}
function copy(from, to, names, fn) {
var error,
tmpl = '\r copy {{ from }} {{ to }} {{ count }}%',

View file

@ -46,7 +46,7 @@
"flop": "~1.3.0",
"format-io": "~0.9.6",
"http-auth": "~2.2.3",
"jag": "~1.0.0",
"jaguar": "~1.0.2",
"join-io": "~1.4.0",
"jonny": "~1.0.0",
"markdown-it": "~4.3.0",