feature(cloudcmd) add ability to set packer with: --packer: "tar" or "zip"

This commit is contained in:
coderaiser 2016-11-17 17:37:06 +02:00
parent a4d8c19247
commit 689dd037c1
23 changed files with 235 additions and 41 deletions

View file

@ -69,6 +69,7 @@ Cloud Commander supports command line parameters:
| `-p, --password` | set password
| `-c, --config` | configuration file path
| `--editor` | set editor: "dword", "edward" or "deepword"
| `--packer` | set packer: "tar" or "zip"
| `--root` | set root directory
| `--prefix` | set url prefix
| `--port` | set port number
@ -236,6 +237,7 @@ Here is description of options:
"password" : "toor", /* password hash in sha-1 for authentication*/
"algo" : "sha512WithRSAEncryption", /* cryptographic algorithm */
"editor" : "edward", /* default, could be "dword" or "edward" */
"packer" : "tar", /* default, could be "tar" or "zip" */
"diff" : true, /* when save - send patch, not whole file */
"zip" : true, /* zip text before send / unzip before save */
"notifications" : false, /* show notifications when tab is not active*/

View file

@ -18,6 +18,7 @@ const args = require('minimist')(argv.slice(2), {
'username',
'config',
'editor',
'packer',
'root',
'prefix'
],
@ -42,6 +43,8 @@ const args = require('minimist')(argv.slice(2), {
online : config('online'),
open : config('open'),
editor : config('editor') || 'edward',
packer : config('packer') || 'tar',
zip : config('zip'),
username : config('username'),
root : config('root') || '/',
prefix : config('prefix') || '',
@ -96,6 +99,7 @@ if (args.version) {
const options = {
root: args.root,
editor: args.editor,
packer: args.packer,
prefix: args.prefix
};

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 57 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 38 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 55 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

After

Width:  |  Height:  |  Size: 170 KiB

Before After
Before After

View file

@ -4,6 +4,7 @@
"password": "2b64f2e3f9fee1942af9ff60d40aa5a719db33b8ba8dd4864bb4f11e25ca2bee00907de32a59429602336cac832c8f2eeff5177cc14c864dd116c8bf6ca5d9a9",
"algo": "sha512WithRSAEncryption",
"editor": "edward",
"packer": "tar",
"diff": true,
"zip" : true,
"notifications": false,

View file

@ -8,6 +8,7 @@
"-p, --password ": "set password",
"-c, --config ": "configuration file path",
"--editor ": "set editor: \"dword\" or \"edward\"",
"--packer ": "set packer: \"tar\" or \"zip\"",
"--root ": "set root directory",
"--prefix ": "set url prefix",
"--port ": "set port number",

View file

@ -144,6 +144,9 @@ var CloudCmd, Util, DOM, io;
obj[obj.editor + '-selected'] = 'selected';
delete obj.editor;
obj[obj.packer + '-selected'] = 'selected';
delete obj.packer;
data = rendy(Template, obj);
Element = DOM.load({
name : 'div',

View file

@ -1516,6 +1516,13 @@ var CloudCmd, Util, DOM, CloudFunc;
return this;
};
this.getPackerExt = function(type) {
if (type === 'zip')
return '.zip';
return '.tar.gz';
}
this.goToDirectory = function() {
var msg = 'Go to directory:',
path = CurrentInfo.dirPath,

View file

@ -17,14 +17,24 @@ var Util, DOM, CloudFunc, CloudCmd;
'touchstart': Util.exec.with(execIfNotUL, onTouch)
};
var EXT;
this.init = function () {
contextMenu();
dragndrop();
unload();
pop();
resize();
config();
};
function config() {
DOM.Files.get('config', function(e, config) {
var type = config && config.packer;
EXT = DOM.getPackerExt(type);
});
}
this.initKeysPanel = function() {
var keysElement = DOM.getById('js-keyspanel');
@ -226,17 +236,16 @@ var Util, DOM, CloudFunc, CloudCmd;
function onDragStart(event) {
var apiURL = CloudFunc.apiURL,
element = getLIElement(event.target),
EXT = '.tar.gz',
isDir = Info.isDir,
link = DOM.getCurrentLink(element),
name = DOM.getCurrentName(element);
/* if it's directory - adding json extension */
if (isDir) {
name += EXT;
link = document.createElement('a');
link.textContent = name;
link.href = apiURL + '/pack' + Info.path + EXT;
name += EXT;
link = document.createElement('a');
link.textContent = name;
link.href = apiURL + '/pack' + Info.path + EXT;
}
event.dataTransfer.setData('DownloadURL',

View file

@ -187,7 +187,7 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
'Extract' : function() {
CloudCmd.Operation.show('extract');
},
'Download' : download,
'Download' : preDownload,
'Upload To Cloud': curry(uploadTo, 'Cloud'),
'Cut' : function() {
isCurrent(Buffer.cut, function() {
@ -281,7 +281,13 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
});
}
function download() {
function preDownload() {
DOM.Files.get('config', function(e, config) {
download(config && config.packer);
});
}
function download(type) {
var TIME = 30 * 1000,
prefixUr = CloudCmd.PREFIX_URL,
FS = CloudFunc.FS,
@ -310,7 +316,7 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
path = encodeURI(path);
if (isDir)
path = prefixUr + PACK + path + '.tar.gz';
path = prefixUr + PACK + path + DOM.getPackerExt(type);
else
path = prefixUr + FS + path + '?download';

View file

@ -6,6 +6,7 @@
/* global spero */
/* global remedy */
/* global ishtar */
/* global salam */
(function(CloudCmd, Util, DOM, rendy) {
'use strict';
@ -116,8 +117,8 @@
});
}
function _initIshtar(prefix, fn) {
ishtar(prefix + '/ishtar', prefix, function(packer) {
function _setPacker(prefix, name, pack, fn) {
pack(prefix + '/' + name, prefix, function(packer) {
fn();
packer.on('connect', function() {
authCheck(packer, function() {
@ -140,15 +141,27 @@
});
}
function _initPacker(prefix, fn) {
DOM.Files.get('config', function(e, config) {
if (e)
CloudCmd.log(e);
if (config.packer === 'zip')
return _setPacker(prefix, 'salam', salam, fn);
_setPacker(prefix, 'ishtar', ishtar, fn);
});
}
function create(prefix) {
var initSpero = currify(_initSpero);
var initRemedy = currify(_initRemedy);
var initIshtar = currify(_initIshtar);
var initPacker = currify(_initPacker);
exec.parallel([
initSpero(prefix),
initRemedy(prefix),
initIshtar(prefix),
initPacker(prefix)
], exec.ret);
}
@ -251,14 +264,19 @@
};
this.pack = function() {
twopack('pack');
DOM.Files.get('config', function(e, config) {
var zip = config && config.packer === 'zip';
twopack('pack', zip ? 'zip' : 'tar');
});
};
this.extract = function() {
twopack('extract');
DOM.Files.get('config', function(e, config) {
var zip = config && config.packer === 'zip';
twopack('extract', zip ? 'zip' : 'tar');
});
};
/**
* prompt and delete current file or selected files
*
@ -444,16 +462,23 @@
}
}
function twopack(operation) {
function getTypeReg(type) {
if (type === 'zip')
return /\.zip$/;
return /\.tar\.gz$/
}
function twopack(operation, type) {
var op,
fileFrom,
Images = DOM.Images,
Info = DOM.CurrentInfo,
name = Info.name,
path = Info.path,
dirPath = Info.dirPath,
activeFiles = DOM.getActiveFiles(),
names = DOM.getFilenames(activeFiles),
fileFrom;
names = DOM.getFilenames(activeFiles);
Util.check(arguments, ['operation']);
@ -462,14 +487,14 @@
} else {
switch(operation) {
case 'extract':
op = extractFn;
op = extractFn;
fileFrom = {
from : path,
to : dirPath
};
name = name.replace(/\.tar\.gz$/, '');
name = name.replace(getTypeReg(type), '');
break;
@ -479,7 +504,7 @@
if (names.length > 1)
name = Info.dir;
name += '.tar.gz';
name += DOM.getPackerExt(type);
fileFrom = {
from : dirPath,
@ -525,7 +550,8 @@
files = [
'/spero/spero.js',
'/remedy/remedy.js',
'/ishtar/ishtar.js'
'/ishtar/ishtar.js',
'/salam/salam.js'
].map(function(name) {
return prefix + name;
});

View file

@ -25,6 +25,7 @@ var DIR = __dirname + '/',
spero = require('spero'),
remedy = require('remedy'),
ishtar = require('ishtar'),
salam = require('salam/legacy'),
criton = require('criton'),
root = function() {
@ -66,6 +67,9 @@ module.exports = function(params) {
case 'editor':
validate.editor(value);
break;
case 'packer':
validate.packer(value);
break;
case 'password':
/* could be useful when used as middleware */
value = criton(value, config('algo'));
@ -147,6 +151,12 @@ function listen(prefix, socket) {
authCheck: authCheck
});
salam.listen(socket, {
root: root,
prefix: prefix + '/salam',
authCheck: authCheck
});
config('console') && konsole.listen(socket, {
prefix: prefix + '/console',
authCheck: authCheck
@ -217,6 +227,10 @@ function cloudcmd(prefix) {
online : isOnline
}),
salam({
prefix: prefix + '/salam',
}),
setUrl(prefix),
logout,

View file

@ -12,6 +12,7 @@ var DIR = './',
markdown = require(DIR + 'markdown'),
jaguar = require('jaguar/legacy'),
onezip = require('onezip/legacy'),
flop = require('flop'),
pullout = require('pullout/legacy'),
@ -142,9 +143,16 @@ function onGET(params, callback) {
}
}
function getPackReg() {
if (config('zip') === 'zip')
return /\.zip$/;
return /\.tar\.gz$/;
}
function streamPack(cmd, response) {
var noop = function() {};
var filename = cmd.replace(/\.tar\.gz$/, '');
var filename = cmd.replace(getPackReg(), '');
var dir = path.dirname(filename);
var names = [
path.basename(filename)
@ -261,9 +269,14 @@ function extract(from, to, fn) {
operation('extract', from, to, fn);
}
function operation(op, from, to, names, fn) {
var packer;
function getPacker() {
if (config('packer') === 'zip')
return onezip;
return jaguar;
}
function operation(op, from, to, names, fn) {
if (!fn) {
fn = names;
names = [
@ -271,7 +284,7 @@ function operation(op, from, to, names, fn) {
];
}
packer = jaguar[op](from, to, names);
var packer = getPacker()[op](from, to, names);
packer.on('error', function(error) {
fn(error);

View file

@ -2,8 +2,9 @@
var exit = require('./exit');
module.exports.root = root;
module.exports.editor = editor;
module.exports.root = root;
module.exports.editor = editor;
module.exports.packer = packer;
function root(dir, fn) {
var fs;
@ -26,3 +27,10 @@ function editor(name) {
exit('cloudcmd --editor: could be "dword", "edward" or "deepword" only');
}
function packer(name) {
var reg = /^(tar|zip)$/;
if (!reg.test(name))
exit('cloudcmd --packer: could be "tar" or "zip" only');
}

View file

@ -31,6 +31,7 @@ programs in browser from any computer, mobile or tablet device.
-p, --password set password
-c, --config configuration file path
--editor set editor: "dword", "edward" or "deepword"
--packer set packer: "tar" or "zip"
--root set root directory
--prefix set url prefix
--port set port number

View file

@ -111,6 +111,7 @@
"minify": "^2.0.0",
"minimist": "^1.2.0",
"mollify": "^1.0.0",
"onezip": "^1.0.5",
"opn": "^4.0.1",
"os-homedir": "^1.0.0",
"package-json": "^2.3.0",
@ -120,6 +121,7 @@
"remedy": "^1.5.0",
"rendy": "^1.1.0",
"restafary": "^1.6.0",
"salam": "^1.0.0",
"socket.io": "^1.4.3",
"spero": "^1.5.0",
"squad": "^1.1.3",

BIN
test/fixture/pack.zip Normal file

Binary file not shown.

View file

@ -14,8 +14,13 @@ const warp = (fn, ...a) => (...b) => fn(...b, ...a);
const _pullout = promisify(pullout);
const pathFixture = path.join(__dirname, '..', 'fixture/pack.tar.gz');
const fixture = fs.readFileSync(pathFixture);
const pathTarFixture = path.join(__dirname, '..', 'fixture/pack.tar.gz');
const pathZipFixture = path.join(__dirname, '..', 'fixture/pack.zip');
const fixture = {
tar: fs.readFileSync(pathTarFixture),
zip: fs.readFileSync(pathZipFixture),
};
const get = promisify((url, fn) => {
fn(null, request(url));
@ -25,12 +30,13 @@ const put = promisify((options, fn) => {
fn(null, request.put(options));
});
test('cloudcmd: rest: pack: get', (t) => {
before((port, after) => {
test('cloudcmd: rest: pack: tar: get', (t) => {
const options = {packer: 'tar'};
before(options, (port, after) => {
get(`http://localhost:${port}/api/v1/pack/fixture/pack`)
.then(_pullout)
.then((pack) => {
t.ok(fixture.compare(pack), 'should pack data');
t.ok(fixture.tar.compare(pack), 'should pack data');
t.end();
after();
})
@ -40,8 +46,9 @@ test('cloudcmd: rest: pack: get', (t) => {
});
});
test('cloudcmd: rest: pack: put: file', (t) => {
before((port, after) => {
test('cloudcmd: rest: pack: tar: put: file', (t) => {
const options = {packer: 'tar'};
before(options, (port, after) => {
const name = String(Math.random()) + '.tar.gz';
const options = getPackOptions(port, name);
@ -51,7 +58,7 @@ test('cloudcmd: rest: pack: put: file', (t) => {
const file = fs.readFileSync(__dirname + '/../' + name);
fs.unlinkSync(`${__dirname}/../${name}`);
t.ok(fixture.compare(file), 'should create archive');
t.ok(fixture.tar.compare(file), 'should create archive');
t.end();
after();
@ -62,8 +69,9 @@ test('cloudcmd: rest: pack: put: file', (t) => {
});
});
test('cloudcmd: rest: pack: put: response', (t) => {
before((port, after) => {
test('cloudcmd: rest: pack: tar: put: response', (t) => {
const options = {packer: 'tar'};
before(options, (port, after) => {
const name = String(Math.random()) + '.tar.gz';
const options = getPackOptions(port, name);
@ -83,8 +91,91 @@ test('cloudcmd: rest: pack: put: response', (t) => {
});
});
test('cloudcmd: rest: pack: put: error', (t) => {
before((port, after) => {
test('cloudcmd: rest: pack: tar: put: error', (t) => {
const options = {packer: 'tar'};
before(options, (port, after) => {
const options = getPackOptions(port, 'name', [
'not found'
]);
put(options)
.then(warp(_pullout, 'string'))
.then((msg) => {
t.ok(/^ENOENT: no such file or directory/.test(msg), 'should return error');
t.end();
after();
})
.catch((error) => {
console.log(error);
});
});
});
test('cloudcmd: rest: pack: zip: get', (t) => {
const options = {packer: 'zip'};
before(options, (port, after) => {
get(`http://localhost:${port}/api/v1/pack/fixture/pack`)
.then(_pullout)
.then((pack) => {
t.ok(fixture.zip.compare(pack), 'should pack data');
t.end();
after();
})
.catch((error) => {
console.log(error);
});
});
});
test('cloudcmd: rest: pack: zip: put: file', (t) => {
const options = {packer: 'zip'};
before(options, (port, after) => {
const name = String(Math.random()) + '.zip';
const options = getPackOptions(port, name);
put(options)
.then(warp(_pullout, 'string'))
.then(() => {
const file = fs.readFileSync(__dirname + '/../' + name);
fs.unlinkSync(`${__dirname}/../${name}`);
t.ok(fixture.zip.compare(file), 'should create archive');
t.end();
after();
})
.catch((error) => {
console.log(error);
});
});
});
test('cloudcmd: rest: pack: zip: put: response', (t) => {
const options = {packer: 'zip'};
before(options, (port, after) => {
const name = String(Math.random()) + '.zip';
const options = getPackOptions(port, name);
put(options)
.then(warp(_pullout, 'string'))
.then((msg) => {
t.equal(msg, 'pack: ok("fixture")', 'should return result message');
fs.unlinkSync(`${__dirname}/../${name}`);
t.end();
after();
})
.catch((error) => {
console.log(error);
});
});
});
test('cloudcmd: rest: pack: zip: put: error', (t) => {
const options = {packer: 'zip'};
before(options, (port, after) => {
const options = getPackOptions(port, 'name', [
'not found'
]);

View file

@ -91,6 +91,12 @@
Online
</label>
</li>
<li>
<select data-name="js-packer" class="form-control full-width" title="Packer">
<option {{ tar-selected }}>tar</option>
<option {{ zip-selected }}>zip</option>
</select>
</li>
<li>
<label>
<input data-name="js-cache" type="checkbox" {{ cache }} >
@ -104,7 +110,7 @@
</label>
</li>
<li>
<input
<input
data-name="js-root"
title="Root"
value="{{ root }}"