From 9641415a00bcd1dfdd102c9e8ff9872759b023e0 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 24 Apr 2017 14:06:52 +0300 Subject: [PATCH] feature(operation) add support of unpacking bzip2 archives: .bz2, .tar.bz2, .tbz2 --- HELP.md | 3 ++ .../{operation.js => operation/index.js} | 15 +++------ client/modules/operation/remove-extension.js | 20 ++++++++++++ .../modules/operation/remove-extension.js | 31 +++++++++++++++++++ webpack.config.js | 2 +- 5 files changed, 59 insertions(+), 12 deletions(-) rename client/modules/{operation.js => operation/index.js} (97%) create mode 100644 client/modules/operation/remove-extension.js create mode 100644 test/client/modules/operation/remove-extension.js diff --git a/HELP.md b/HELP.md index 8f658487..db4f023e 100644 --- a/HELP.md +++ b/HELP.md @@ -12,6 +12,7 @@ [DEEPWORD]: https://github.com/cloudcmd/deepword "Editor based on Monaco" [EDWARD_KEYS]: https://github.com/cloudcmd/edward/#hot-keys "Edward Hot keys" [TERMUX]: https://termux.com "Termux" +[INLY]: https://github.com/coderaiser/node-inly "Extract archive" **Cloud Commander** is an orthodox web file manager with console and editor. Will help you manage the server and work with files, directories and programs in browser from any computer, mobile or tablet. ![Cloud Commander](/img/logo/cloudcmd.png "Cloud Commander") @@ -29,6 +30,8 @@ Benefits - **3 built-in editors** with support of **syntax highlighting**: [Dword][DWORD], [Edward][EDWARD] and [Deepword][DEEPWORD]. - [Console](https://github.com/cloudcmd/console "Console") with support of default OS command line. - Written in **JavaScript/Node.js**. +- Built-in archives pack: **zip** and **tar.gz**. +- Built-in archives extract: **zip**, **tar**, **gz**, **bz2**, **.tar.gz** and **.tar.bz2** (with help of [inly][INLY]). Install --------------- diff --git a/client/modules/operation.js b/client/modules/operation/index.js similarity index 97% rename from client/modules/operation.js rename to client/modules/operation/index.js index 90b00cfc..4ca7da29 100644 --- a/client/modules/operation.js +++ b/client/modules/operation/index.js @@ -14,7 +14,8 @@ CloudCmd.Operation = OperationProto; const currify = require('currify/legacy'); const exec = require('execon'); -const RESTful = require('../dom/rest'); +const RESTful = require('../../dom/rest'); +const removeExtension = require('./remove-extension'); function OperationProto(operation, data) { const Name = 'Operation'; @@ -272,8 +273,7 @@ function OperationProto(operation, data) { }; this.extract = () => { - const isZip = config('packer') === 'zip'; - twopack('extract', isZip ? 'zip' : 'tar'); + twopack('extract'); }; /** @@ -456,13 +456,6 @@ function OperationProto(operation, data) { } } - function getTypeReg(type) { - if (type === 'zip') - return /\.zip$/; - - return /\.tar\.gz$/; - } - function checkEmpty(name, operation) { if (!operation) throw Error(name + ' could not be empty!'); @@ -493,7 +486,7 @@ function OperationProto(operation, data) { to: dirPath }; - currentName = currentName.replace(getTypeReg(type), ''); + currentName = removeExtension(currentName); break; diff --git a/client/modules/operation/remove-extension.js b/client/modules/operation/remove-extension.js new file mode 100644 index 00000000..52772c30 --- /dev/null +++ b/client/modules/operation/remove-extension.js @@ -0,0 +1,20 @@ +'use strict'; + +const {getExt} = require('../../../common/util'); + +module.exports = (name) => { + const ext = getExtension(name); + + return name.replace(ext, ''); +}; + +function getExtension(name) { + if (/\.tar\.gz$/.test(name)) + return '.tar.gz'; + + if (/\.tar\.bz2$/.test(name)) + return '.tar.bz2'; + + return getExt(name); +} + diff --git a/test/client/modules/operation/remove-extension.js b/test/client/modules/operation/remove-extension.js new file mode 100644 index 00000000..6491f052 --- /dev/null +++ b/test/client/modules/operation/remove-extension.js @@ -0,0 +1,31 @@ +'use strict'; + +const test = require('tape'); +const dir = '../../../../client/modules/operation'; + +const removeExtension = require(`${dir}/remove-extension`); + +test('cloudcmd: client: modules: operation: removeExtension: .tar.gz', (t) => { + const name = 'hello'; + const fullName = `${name}.tar.gz`; + + t.equal(removeExtension(fullName), name, 'should remove .tar.gz'); + t.end(); +}); + +test('cloudcmd: client: modules: operation: removeExtension: .tar.bz2', (t) => { + const name = 'hello'; + const fullName = `${name}.tar.bz2`; + + t.equal(removeExtension(fullName), name, 'should remove .tar.bz2'); + t.end(); +}); + +test('cloudcmd: client: modules: operation: removeExtension: .bz2', (t) => { + const name = 'hello'; + const fullName = `${name}.bz2`; + + t.equal(removeExtension(fullName), name, 'should remove .bz2'); + t.end(); +}); + diff --git a/webpack.config.js b/webpack.config.js index 6be46582..656a86ac 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -50,7 +50,7 @@ module.exports = { [modules + '/config']: `${dirModules}/config.js`, [modules + '/contact']: `${dirModules}/contact.js`, [modules + '/upload']: `${dirModules}/upload.js`, - [modules + '/operation']: `${dirModules}/operation.js`, + [modules + '/operation']: `${dirModules}/operation/index.js`, [modules + '/konsole']: `${dirModules}/konsole.js`, [modules + '/terminal']: `${dirModules}/terminal.js`, [modules + '/cloud']: `${dirModules}/cloud.js`,