feature(cloudcmd) simplify archive extraction for: zip, tar, gz, tar.gz, tgz

This commit is contained in:
coderaiser 2017-01-27 15:19:52 +02:00
parent d3caa9dcd4
commit d5aee29558
4 changed files with 50 additions and 16 deletions

View file

@ -7,6 +7,7 @@
/* global remedy */
/* global ishtar */
/* global salam */
/* global omnes */
(function(CloudCmd, Util, DOM, rendy) {
'use strict';
@ -115,17 +116,11 @@
setListeners(packer, {noContinue: true}, callback);
packer.pack(data.from, data.to, data.names);
};
extractFn = function(data, callback) {
setListeners(packer, {noContinue: true}, callback);
packer.extract(data.from, data.to);
};
});
});
packer.on('disconnect', function() {
packFn = RESTful.pack;
extractFn = RESTful.extract;
});
});
}
@ -137,15 +132,35 @@
_setPacker(prefix, 'ishtar', ishtar, fn);
}
function _initExtractor(prefix, fn) {
omnes(prefix + '/omnes', prefix, function(packer) {
fn();
packer.on('connect', function() {
authCheck(packer, function() {
extractFn = function(data, callback) {
setListeners(packer, {noContinue: true}, callback);
packer.extract(data.from, data.to);
};
});
});
packer.on('disconnect', function() {
extractFn = RESTful.extract;
});
});
}
function create(prefix) {
var initSpero = currify(_initSpero);
var initRemedy = currify(_initRemedy);
var initPacker = currify(_initPacker);
var initExtractor = currify(_initExtractor);
exec.parallel([
initSpero(prefix),
initRemedy(prefix),
initPacker(prefix)
initPacker(prefix),
initExtractor(prefix)
], exec.ret);
}
@ -536,7 +551,8 @@
'/spero/spero.js',
'/remedy/remedy.js',
'/ishtar/ishtar.js',
'/salam/salam.js'
'/salam/salam.js',
'/omnes/omnes.js'
].map(function(name) {
return prefix + name;
});

View file

@ -112,6 +112,7 @@
"flop": "^1.4.0",
"format-io": "^0.9.6",
"http-auth": "^2.3.1",
"inly": "^1.0.2",
"ishtar": "^1.5.0",
"jaguar": "^3.0.0",
"jju": "^1.3.0",
@ -123,6 +124,7 @@
"minimist": "^1.2.0",
"mollify": "^1.0.0",
"nomine": "^1.0.1",
"omnes": "^1.0.3",
"onezip": "^1.0.5",
"opn": "^4.0.1",
"os-homedir": "^1.0.0",

View file

@ -28,6 +28,7 @@ const spero = require('spero');
const remedy = require('remedy');
const ishtar = require('ishtar');
const salam = require('salam/legacy');
const omnes = require('omnes/legacy');
const criton = require('criton');
const root = () => config('root');
@ -163,6 +164,12 @@ function listen(prefix, socket) {
prefix: prefix + '/salam',
});
omnes.listen(socket, {
root,
authCheck,
prefix: prefix + '/omnes',
});
config('console') && konsole.listen(socket, {
authCheck,
prefix: prefix + '/console',
@ -235,6 +242,10 @@ function cloudcmd(prefix, plugins) {
prefix: prefix + '/salam',
}),
omnes({
prefix: prefix + '/omnes',
}),
nomine({
prefix: prefix + '/rename',
}),

View file

@ -11,6 +11,7 @@ const markdown = require(DIR + 'markdown');
const jaguar = require('jaguar/legacy');
const onezip = require('onezip/legacy');
const inly = require('inly/legacy');
const flop = require('flop');
const pullout = require('pullout/legacy');
const ponse = require('ponse');
@ -253,11 +254,14 @@ function extract(from, to, fn) {
operation('extract', from, to, fn);
}
function getPacker() {
if (config('packer') === 'zip')
return onezip;
function getPacker(operation) {
if (operation === 'extract')
return inly;
return jaguar;
if (config('packer') === 'zip')
return onezip.pack;
return jaguar.pack;
}
function operation(op, from, to, names, fn) {
@ -268,13 +272,14 @@ function operation(op, from, to, names, fn) {
];
}
const packer = getPacker()[op](from, to, names);
const packer = getPacker(op);
const pack = packer(from, to, names);
packer.on('error', error => {
pack.on('error', error => {
fn(error);
});
packer.on('progress', (count) => {
pack.on('progress', (count) => {
process.stdout.write(rendy('\r{{ operation }} "{{ name }}": {{ count }}%', {
operation : op,
name : names[0],
@ -282,7 +287,7 @@ function operation(op, from, to, names, fn) {
}));
});
packer.on('end', () => {
pack.on('end', () => {
process.stdout.write('\n');
const name = path.basename(from);