diff --git a/.gitignore b/.gitignore
index 12255bfd..c6f29842 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,9 +19,6 @@ modules/jquery-mousewheel
modules/execon
modules/emitify
-legacy
-server_
-
.nyc_output
*.swp
diff --git a/.npmignore b/.npmignore
index b3951b1a..2ae7e11d 100644
--- a/.npmignore
+++ b/.npmignore
@@ -28,8 +28,5 @@ bin/legacy.js
client
-legacy/bin/release.js
-legacy/bin/legacy.js
-
webpack.config.js
diff --git a/ChangeLog b/ChangeLog
index fc3cd4dd..c9f69294 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2017.07.12, v7.0.0
+
+feature:
+- (auth) add currify
+- (cloudcmd) require es2015 versions of packages
+- (package) opn v5.1.0
+- (package) http-auth v3.2.3
+- (package) package-json v4.0.1
+- (package) chalk v2.0.1
+- (cloudcmd) rm support of node.js < 4.0.0
+- (cloudcmd) rm config option: minify
+- (route) rm minify
+- (package) extract-text-webpack-plugin v3.0.0
+
+
2017.07.10, v6.15.4
feature:
diff --git a/HELP.md b/HELP.md
index 379aa7d9..849fe1de 100644
--- a/HELP.md
+++ b/HELP.md
@@ -1,4 +1,4 @@
-# Cloud Commander v6.15.4
+# Cloud Commander v7.0.0
### [Main][MainURL] [Blog][BlogURL] Live(![Heroku][Heroku_LIVE_IMG] [Heroku][HerokuURL])
@@ -77,7 +77,6 @@ Cloud Commander supports command line parameters:
| `--root` | set root directory
| `--prefix` | set url prefix
| `--port` | set port number
-| `--minify` | enable minification
| `--progress` | show progress of file operations
| `--html-dialogs` | use html dialogs
| `--open` | open web browser when server started
@@ -90,7 +89,6 @@ Cloud Commander supports command line parameters:
| `--no-auth` | disable authorization
| `--no-online` | load scripts from local server
| `--no-open` | do not open web browser when server started
-| `--no-minify` | disable minification
| `--no-progress` | do not show progress of file operations
| `--no-html-dialogs` | do not use html dialogs
| `--no-one-panel-mode` | unset one panel mode
@@ -309,7 +307,6 @@ Here is description of options:
"localStorage" : true, /* local storage */
"buffer" : true, /* buffer for copying files */
"dirStorage" : true, /* store directory listing to localStorage */
- "minify" : false, /* minification of js,css,html and img */
"online" : true, /* load js files from cdn or local path */
"open" : false /* open web browser when server started */
"cache" : true, /* add cache-control */
@@ -592,6 +589,7 @@ There is a lot ways to be involved in `Cloud Commander` development:
Version history
---------------
+- *2017.07.12*, **[v7.0.0](//github.com/coderaiser/cloudcmd/releases/tag/v7.0.0)**
- *2017.07.10*, **[v6.15.4](//github.com/coderaiser/cloudcmd/releases/tag/v6.15.4)**
- *2017.06.26*, **[v6.15.3](//github.com/coderaiser/cloudcmd/releases/tag/v6.15.3)**
- *2017.06.22*, **[v6.15.2](//github.com/coderaiser/cloudcmd/releases/tag/v6.15.2)**
diff --git a/README.md b/README.md
index ea4871f5..0ac74251 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# Cloud Commander v6.15.4 [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Package Quality][PackageQualityIMGURL]][PackageQualityURL] [![Codacy][CodacyIMG]][CodacyURL] [![Gitter][GitterIMGURL]][GitterURL] [](#backers) [](#sponsors)
+# Cloud Commander v7.0.0 [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Package Quality][PackageQualityIMGURL]][PackageQualityURL] [![Codacy][CodacyIMG]][CodacyURL] [![Gitter][GitterIMGURL]][GitterURL] [](#backers) [](#sponsors)
### [Main][MainURL] [Blog][BlogURL] Live([Heroku][HerokuURL])
diff --git a/bin/cloudcmd.js b/bin/cloudcmd.js
index 93006a2f..c279db61 100755
--- a/bin/cloudcmd.js
+++ b/bin/cloudcmd.js
@@ -36,7 +36,6 @@ const args = require('minimist')(argv.slice(2), {
'server',
'online',
'open',
- 'minify',
'progress',
'config-dialog',
'console',
@@ -49,7 +48,6 @@ const args = require('minimist')(argv.slice(2), {
server : true,
auth : choose(env('auth'), config('auth')),
port : config('port'),
- minify : config('minify'),
online : config('online'),
open : config('open'),
editor : env('editor') || config('editor'),
@@ -100,7 +98,6 @@ function main() {
config('auth', args.auth);
config('online', args.online);
config('open', args.open);
- config('minify', args.minify);
config('username', args.username);
config('progress', args.progress);
config('console', args.console);
diff --git a/bin/legacy.js b/bin/legacy.js
deleted file mode 100755
index 890a56a0..00000000
--- a/bin/legacy.js
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/usr/bin/env node
-
-'use strict';
-
-const fs = require('fs');
-const path = require('path');
-
-const dir = path.join(__dirname, '../server');
-const dir_ = path.join(__dirname, '../legacy/server');
-
-const setDir = (name) => {
- return path.join(dir_, name);
-};
-
-fs.readdirSync(dir)
- .map(fillFile)
- .map(writeFile);
-
-function fillFile(name) {
- return {
- name: setDir(name),
- data: `module.exports = require('../../server_/${name}');`
- };
-}
-
-function writeFile({name, data}) {
- return fs.writeFileSync(name, data);
-}
-
diff --git a/common/cloudfunc.js b/common/cloudfunc.js
index e4b9f994..fb262c0e 100644
--- a/common/cloudfunc.js
+++ b/common/cloudfunc.js
@@ -1,4 +1,231 @@
'use strict';
-module.exports = require('../server/cloudfunc');
+const rendy = require('rendy');
+const store = require('fullstore/legacy');
+const Entity = require('./entity');
+
+/* КОНСТАНТЫ (общие для клиента и сервера)*/
+
+/* название программы */
+const NAME = 'Cloud Commander';
+const FS = '/fs';
+
+const Path = store();
+
+Path('/');
+
+module.exports.FS = FS;
+module.exports.apiURL = '/api/v1';
+module.exports.MAX_FILE_SIZE = 500 * 1024;
+module.exports.Entity = Entity;
+
+module.exports.formatMsg = (msg, name, status) => {
+ status = status || 'ok';
+
+ if (name)
+ name = '("' + name + '")';
+ else
+ name = '';
+
+ return msg + ': ' + status + name;
+};
+
+/**
+ * Функция возвращает заголовок веб страницы
+ * @path
+ */
+module.exports.getTitle = (path) => {
+ return NAME + ' - ' + (path || Path());
+};
+
+/** Функция получает адреса каждого каталога в пути
+ * возвращаеться массив каталогов
+ * @param url - адрес каталога
+ */
+function getPathLink(url, prefix, template) {
+ if (!url)
+ throw Error('url could not be empty!');
+
+ if (!template)
+ throw Error('template could not be empty!');
+
+ const names = url
+ .split('/')
+ .slice(1, -1);
+
+ const allNames = ['/', ...names];
+ const length = allNames.length - 1;
+
+ let path = '/';
+
+ const pathHTML = allNames.map((name, index) => {
+ const isLast = index === length;
+
+ if (index)
+ path += name + '/';
+
+ if (index && isLast)
+ return name + '/';
+
+ const slash = index ? '/' : '';
+
+ return rendy(template, {
+ path,
+ name,
+ slash,
+ prefix,
+ });
+ }).join('');
+
+ return pathHTML;
+}
+
+/**
+ * Функция строит таблицу файлв из JSON-информации о файлах
+ * @param params - информация о файлах
+ *
+ */
+module.exports.buildFromJSON = (params) => {
+ const prefix = params.prefix;
+ const template = params.template;
+ const templateFile = template.file;
+ const templateLink = template.link;
+ const json = params.data;
+
+ const {path, files} = json;
+
+ const sort = params.sort || 'name';
+ const order = params.order || 'asc';
+
+ /*
+ * Строим путь каталога в котором мы находимся
+ * со всеми подкаталогами
+ */
+ const htmlPath = getPathLink(path, prefix, template.pathLink);
+
+ let fileTable = rendy(template.path, {
+ link : prefix + FS + path,
+ fullPath : path,
+ path : htmlPath
+ });
+
+ let name = 'name';
+ let size = 'size';
+ let date = 'date';
+ const owner = 'owner';
+ const mode = 'mode';
+ const arrow = order === 'asc' ? '↑' : '↓';
+
+ if (sort === 'name' && order !== 'asc')
+ name += arrow;
+ else if (sort === 'size')
+ size += arrow;
+ else if (sort === 'date')
+ date += arrow;
+
+ const header = rendy(templateFile, {
+ tag : 'div',
+ attribute : 'data-name="js-fm-header" ',
+ className : 'fm-header',
+ type : '',
+ name,
+ size,
+ date,
+ owner,
+ mode,
+ });
+
+ /* сохраняем путь */
+ Path(path);
+
+ fileTable += header + '
';
+ /* Если мы не в корне */
+ if (path !== '/') {
+ /* убираем последний слеш и каталог в котором мы сейчас находимся*/
+ const lastSlash = path.substr(path, path.lastIndexOf('/'));
+ const dotDot = lastSlash.substr(lastSlash, lastSlash.lastIndexOf('/'));
+
+ const link = prefix + FS + (dotDot || '/');
+
+ const linkResult = rendy(template.link, {
+ link,
+ title : '..',
+ name : '..'
+ });
+
+ const dataName = 'data-name="js-file-.." ';
+ const attribute = 'draggable="true" ' + dataName;
+
+ /* Сохраняем путь к каталогу верхнего уровня*/
+ fileTable += rendy(template.file, {
+ tag : 'li',
+ attribute,
+ className : '',
+ type : 'directory',
+ name : linkResult,
+ size : '<dir>',
+ date : '--.--.----',
+ owner : '.',
+ mode : '--- --- ---'
+ });
+ }
+
+ fileTable += files.map((file) => {
+ const link = prefix + FS + path + file.name;
+
+ const type = getType(file.size);
+ const size = getSize(file.size);
+
+ const date = file.date || '--.--.----';
+ const owner = file.owner || 'root';
+ const mode = file.mode;
+
+ const linkResult = rendy(templateLink, {
+ link,
+ title: file.name,
+ name: Entity.encode(file.name),
+ attribute: getAttribute(file.size)
+ });
+
+ const dataName = 'data-name="js-file-' + file.name + '" ';
+ const attribute = 'draggable="true" ' + dataName;
+
+ return rendy(templateFile, {
+ tag: 'li',
+ attribute,
+ className: '',
+ type,
+ name: linkResult,
+ size,
+ date,
+ owner,
+ mode,
+ });
+ }).join('');
+
+ fileTable += '
';
+
+ return fileTable;
+};
+
+function getType(size) {
+ if (size === 'dir')
+ return 'directory';
+
+ return 'text-file';
+}
+
+function getAttribute(size) {
+ if (size === 'dir')
+ return '';
+
+ return 'target="_blank" ';
+}
+
+function getSize(size) {
+ if (size === 'dir')
+ return '<dir>';
+
+ return size;
+}
diff --git a/common/entity.js b/common/entity.js
index 0aa9ab40..8472a1bd 100644
--- a/common/entity.js
+++ b/common/entity.js
@@ -1,4 +1,32 @@
'use strict';
-module.exports = require('../server/common/entity');
+const Entities = {
+ ' ': ' ',
+ '<': '<',
+ '>': '>',
+};
+
+const keys = Object.keys(Entities);
+
+module.exports.encode = (str) => {
+ keys.forEach((code) => {
+ const char = Entities[code];
+ const reg = RegExp(char, 'g');
+
+ str = str.replace(reg, code);
+ });
+
+ return str;
+};
+
+module.exports.decode = (str) => {
+ keys.forEach((code) => {
+ const char = Entities[code];
+ const reg = RegExp(code, 'g');
+
+ str = str.replace(reg, char);
+ });
+
+ return str;
+};
diff --git a/img/screen/config.png b/img/screen/config.png
index 5510f0f5..43b330aa 100644
Binary files a/img/screen/config.png and b/img/screen/config.png differ
diff --git a/img/screen/console.png b/img/screen/console.png
index e5feebc3..349bb7fd 100644
Binary files a/img/screen/console.png and b/img/screen/console.png differ
diff --git a/img/screen/edit.png b/img/screen/edit.png
index eadd8d33..81f365f3 100644
Binary files a/img/screen/edit.png and b/img/screen/edit.png differ
diff --git a/img/screen/terminal.png b/img/screen/terminal.png
index 911a9d08..df6e236c 100644
Binary files a/img/screen/terminal.png and b/img/screen/terminal.png differ
diff --git a/img/screen/view.png b/img/screen/view.png
index 6c9ea67b..0e8ddb40 100644
Binary files a/img/screen/view.png and b/img/screen/view.png differ
diff --git a/json/config.json b/json/config.json
index 4981a102..5728938a 100644
--- a/json/config.json
+++ b/json/config.json
@@ -10,7 +10,6 @@
"localStorage": true,
"buffer": true,
"dirStorage": false,
- "minify": false,
"online": true,
"open": false,
"cache": true,
diff --git a/json/help.json b/json/help.json
index 20b5ba54..7d9bfe0e 100644
--- a/json/help.json
+++ b/json/help.json
@@ -13,7 +13,6 @@
"--root ": "set root directory",
"--prefix ": "set url prefix",
"--port ": "set port number",
- "--minify ": "enable minification",
"--progress ": "show progress of file operations",
"--html-dialogs ": "use html dialogs",
"--one-panel-mode ": "set one panel mode",
@@ -26,7 +25,6 @@
"--no-auth ": "disable authorization",
"--no-online ": "load scripts from local server",
"--no-open ": "do not open web browser when server started",
- "--no-minify ": "disable minification",
"--no-progress ": "do not show progress of file operations",
"--no-html-dialogs ": "do not use html dialogs",
"--no-one-panel-mode ": "unset one panel mode",
diff --git a/man/cloudcmd.1 b/man/cloudcmd.1
index 2841a05f..e351052d 100644
--- a/man/cloudcmd.1
+++ b/man/cloudcmd.1
@@ -36,7 +36,6 @@ programs in browser from any computer, mobile or tablet device.
--root set root directory
--prefix set url prefix
--port set port number
- --minify enable minification
--progress show progress of file operations
--html-dialogs use html dialogs
--open open web browser when server started
@@ -49,7 +48,6 @@ programs in browser from any computer, mobile or tablet device.
--no-server do not start server
--no-online load scripts from local server
--no-open do not open web browser when server started
- --no-minify disable minification
--no-progress do not show progress of file operations
--no-html-dialogs do not use html dialogs
--no-one-panel-mode unset one panel mode
diff --git a/package.json b/package.json
index 9acae9c4..e9742d85 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "cloudcmd",
- "version": "6.15.4",
+ "version": "7.0.0",
"author": "coderaiser (https://github.com/coderaiser)",
"description": "Orthodox web file manager with console and editor",
"homepage": "http://cloudcmd.io",
@@ -36,8 +36,7 @@
"server"
],
"bin": {
- "cloudcmd": "legacy/bin/cloudcmd.js",
- "cloudcmd+": "bin/cloudcmd.js"
+ "cloudcmd": "bin/cloudcmd.js"
},
"config": {
"dirs": "bin server test webpack.config.js"
@@ -80,8 +79,6 @@
"docker:rm-old": "redrun --parallel docker:rm:*",
"coverage": "nyc npm test",
"report": "nyc report --reporter=text-lcov | coveralls",
- "6to5:bin": "babel bin -d legacy/bin",
- "6to5:server": "babel server -d server_",
"6to5:client": "webpack --progress",
"6to5:client:dev": "NODE_ENV=development redrun 6to5:client",
"watch:client": "redrun 6to5:client -- --watch",
@@ -93,16 +90,9 @@
"watch:coverage": "nodemon -w server -w test -w common -x \"npm run coverage\"",
"w:c": "redrun watch:client",
"w:c:d": "redrun watch:client:dev",
- "build": "redrun rm:* 6to5:* mkdir:* legacy:*",
+ "build": "redrun 6to5:*",
"build:client": "redrun 6to5:client",
"build:client:dev": "redrun 6to5:client:dev",
- "legacy:package": "echo \"module.exports = require('../package');\" > legacy/package.js",
- "mkdir:server": "mkdirp legacy/server",
- "mkdir:json": "mkdirp legacy/json",
- "legacy:server": "bin/legacy.js",
- "legacy:help": "cp json/help.json legacy/json/",
- "rm:server": "rimraf server_ legacy",
- "rm:client": "rimraf dist dist-dev",
"heroku-postbuild": "redrun 6to5:client",
"postheroku-postbuild": "npm i gritty"
},
@@ -112,7 +102,7 @@
"subdomain": "cloudcmd",
"dependencies": {
"apart": "^1.0.1",
- "chalk": "^1.1.0",
+ "chalk": "^2.0.1",
"checkup": "^1.3.0",
"console-io": "^4.0.0",
"copymitter": "^2.0.0",
@@ -128,7 +118,7 @@
"flop": "^2.0.0",
"format-io": "^0.9.6",
"fullstore": "^1.0.0",
- "http-auth": "^2.3.1",
+ "http-auth": "^3.2.3",
"inly": "^1.0.2",
"ishtar": "^2.0.0",
"jaguar": "^3.0.0",
@@ -137,14 +127,13 @@
"jonny": "^1.0.0",
"markdown-it": "^8.0.0",
"mellow": "^2.0.0",
- "minify": "^2.0.0",
"minimist": "^1.2.0",
"nomine": "^1.0.1",
"omnes": "^1.0.3",
"onezip": "^1.0.5",
- "opn": "^4.0.1",
+ "opn": "^5.1.0",
"os-homedir": "^1.0.0",
- "package-json": "^2.3.0",
+ "package-json": "^4.0.1",
"ponse": "^1.4.0",
"pullout": "^1.0.1",
"remedy": "^2.0.0",
@@ -171,14 +160,17 @@
"es6-promise": "^4.0.5",
"es6-promisify": "^5.0.0",
"eslint": "^4.0.0",
- "extract-text-webpack-plugin": "^2.1.2",
+ "extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^0.11.2",
"gunzip-maybe": "^1.3.1",
"html-looks-like": "^1.0.2",
+ "html-webpack-exclude-assets-plugin": "^0.0.5",
+ "html-webpack-plugin": "^2.29.0",
"jscs": "^3.0.1",
"jshint": "^2.8.0",
"minor": "^1.2.2",
"mkdirp": "^0.5.1",
+ "mock-require": "^2.0.2",
"morgan": "^1.6.1",
"nodemon": "^1.9.1",
"nsp": "^2.2.1",
@@ -203,8 +195,8 @@
"yaspeller": "^3.0.0"
},
"engines": {
- "node": ">=0.10"
+ "node": ">=4.0.0"
},
"license": "MIT",
- "main": "legacy/server/cloudcmd.js"
+ "main": "server/cloudcmd.js"
}
diff --git a/server/auth.js b/server/auth.js
index 18943e92..39e30d73 100644
--- a/server/auth.js
+++ b/server/auth.js
@@ -2,6 +2,8 @@
const httpAuth = require('http-auth');
const criton = require('criton');
+const currify = require('currify');
+const middle = currify(_middle);
const config = require('./config');
@@ -13,16 +15,14 @@ module.exports = () => {
return middle(auth);
};
-function middle(authentication) {
- return (req, res, next) => {
- const is = config('auth');
-
- if (!is)
- return next();
-
- const success = () => next(/* success */);
- authentication.check(req, res, success);
- };
+function _middle(authentication, req, res, next) {
+ const is = config('auth');
+
+ if (!is)
+ return next();
+
+ const success = () => next(/* success */);
+ authentication.check(req, res, success);
}
function check(username, password, callback) {
diff --git a/server/cloudcmd.js b/server/cloudcmd.js
index 644d6af3..976d06a3 100644
--- a/server/cloudcmd.js
+++ b/server/cloudcmd.js
@@ -2,8 +2,9 @@
const DIR = __dirname + '/';
const DIR_ROOT = DIR + '../';
+const DIR_COMMON = DIR + '../common/';
-const cloudfunc = require(DIR + 'cloudfunc');
+const cloudfunc = require(DIR_COMMON + 'cloudfunc');
const auth = require(DIR + 'auth');
const config = require(DIR + 'config');
const modulas = require(DIR + 'modulas');
@@ -18,17 +19,17 @@ const currify = require('currify');
const apart = require('apart');
const join = require('join-io');
const ponse = require('ponse');
-const restafary = require('restafary/legacy');
-const konsole = require('console-io/legacy');
-const edward = require('edward/legacy');
-const dword = require('dword/legacy');
-const deepword = require('deepword/legacy');
-const nomine = require('nomine/legacy');
-const spero = require('spero/legacy');
-const remedy = require('remedy/legacy');
-const ishtar = require('ishtar/legacy');
-const salam = require('salam/legacy');
-const omnes = require('omnes/legacy');
+const restafary = require('restafary');
+const konsole = require('console-io');
+const edward = require('edward');
+const dword = require('dword');
+const deepword = require('deepword');
+const nomine = require('nomine');
+const spero = require('spero');
+const remedy = require('remedy');
+const ishtar = require('ishtar');
+const salam = require('salam');
+const omnes = require('omnes');
const criton = require('criton');
const setUrl = currify(_setUrl);
@@ -193,7 +194,6 @@ function cloudcmd(prefix, plugins, modules) {
return config(name);
};
- const minify = apart(isOption, 'minify');
const online = apart(isOption, 'online');
const cache = apart(isOption, 'cache');
const diff = apart(isOption, 'diff');
@@ -275,8 +275,8 @@ function cloudcmd(prefix, plugins, modules) {
route,
join({
- dir : DIR_ROOT,
- minify,
+ dir: DIR_ROOT,
+ minify: false,
}),
pluginer(plugins),
diff --git a/server/cloudfunc.js b/server/cloudfunc.js
deleted file mode 100644
index 93af81e8..00000000
--- a/server/cloudfunc.js
+++ /dev/null
@@ -1,231 +0,0 @@
-'use strict';
-
-const rendy = require('rendy');
-const store = require('fullstore/legacy');
-const Entity = require('./common/entity');
-
-/* КОНСТАНТЫ (общие для клиента и сервера)*/
-
-/* название программы */
-const NAME = 'Cloud Commander';
-const FS = '/fs';
-
-const Path = store();
-
-Path('/');
-
-module.exports.FS = FS;
-module.exports.apiURL = '/api/v1';
-module.exports.MAX_FILE_SIZE = 500 * 1024;
-module.exports.Entity = Entity;
-
-module.exports.formatMsg = (msg, name, status) => {
- status = status || 'ok';
-
- if (name)
- name = '("' + name + '")';
- else
- name = '';
-
- return msg + ': ' + status + name;
-};
-
-/**
- * Функция возвращает заголовок веб страницы
- * @path
- */
-module.exports.getTitle = (path) => {
- return NAME + ' - ' + (path || Path());
-};
-
-/** Функция получает адреса каждого каталога в пути
- * возвращаеться массив каталогов
- * @param url - адрес каталога
- */
-function getPathLink(url, prefix, template) {
- if (!url)
- throw Error('url could not be empty!');
-
- if (!template)
- throw Error('template could not be empty!');
-
- const names = url
- .split('/')
- .slice(1, -1);
-
- const allNames = ['/', ...names];
- const length = allNames.length - 1;
-
- let path = '/';
-
- const pathHTML = allNames.map((name, index) => {
- const isLast = index === length;
-
- if (index)
- path += name + '/';
-
- if (index && isLast)
- return name + '/';
-
- const slash = index ? '/' : '';
-
- return rendy(template, {
- path,
- name,
- slash,
- prefix,
- });
- }).join('');
-
- return pathHTML;
-}
-
-/**
- * Функция строит таблицу файлв из JSON-информации о файлах
- * @param params - информация о файлах
- *
- */
-module.exports.buildFromJSON = (params) => {
- const prefix = params.prefix;
- const template = params.template;
- const templateFile = template.file;
- const templateLink = template.link;
- const json = params.data;
-
- const {path, files} = json;
-
- const sort = params.sort || 'name';
- const order = params.order || 'asc';
-
- /*
- * Строим путь каталога в котором мы находимся
- * со всеми подкаталогами
- */
- const htmlPath = getPathLink(path, prefix, template.pathLink);
-
- let fileTable = rendy(template.path, {
- link : prefix + FS + path,
- fullPath : path,
- path : htmlPath
- });
-
- let name = 'name';
- let size = 'size';
- let date = 'date';
- const owner = 'owner';
- const mode = 'mode';
- const arrow = order === 'asc' ? '↑' : '↓';
-
- if (sort === 'name' && order !== 'asc')
- name += arrow;
- else if (sort === 'size')
- size += arrow;
- else if (sort === 'date')
- date += arrow;
-
- const header = rendy(templateFile, {
- tag : 'div',
- attribute : 'data-name="js-fm-header" ',
- className : 'fm-header',
- type : '',
- name,
- size,
- date,
- owner,
- mode,
- });
-
- /* сохраняем путь */
- Path(path);
-
- fileTable += header + '';
- /* Если мы не в корне */
- if (path !== '/') {
- /* убираем последний слеш и каталог в котором мы сейчас находимся*/
- const lastSlash = path.substr(path, path.lastIndexOf('/'));
- const dotDot = lastSlash.substr(lastSlash, lastSlash.lastIndexOf('/'));
-
- const link = prefix + FS + (dotDot || '/');
-
- const linkResult = rendy(template.link, {
- link,
- title : '..',
- name : '..'
- });
-
- const dataName = 'data-name="js-file-.." ';
- const attribute = 'draggable="true" ' + dataName;
-
- /* Сохраняем путь к каталогу верхнего уровня*/
- fileTable += rendy(template.file, {
- tag : 'li',
- attribute,
- className : '',
- type : 'directory',
- name : linkResult,
- size : '<dir>',
- date : '--.--.----',
- owner : '.',
- mode : '--- --- ---'
- });
- }
-
- fileTable += files.map((file) => {
- const link = prefix + FS + path + file.name;
-
- const type = getType(file.size);
- const size = getSize(file.size);
-
- const date = file.date || '--.--.----';
- const owner = file.owner || 'root';
- const mode = file.mode;
-
- const linkResult = rendy(templateLink, {
- link,
- title: file.name,
- name: Entity.encode(file.name),
- attribute: getAttribute(file.size)
- });
-
- const dataName = 'data-name="js-file-' + file.name + '" ';
- const attribute = 'draggable="true" ' + dataName;
-
- return rendy(templateFile, {
- tag: 'li',
- attribute,
- className: '',
- type,
- name: linkResult,
- size,
- date,
- owner,
- mode,
- });
- }).join('');
-
- fileTable += '
';
-
- return fileTable;
-};
-
-function getType(size) {
- if (size === 'dir')
- return 'directory';
-
- return 'text-file';
-}
-
-function getAttribute(size) {
- if (size === 'dir')
- return '';
-
- return 'target="_blank" ';
-}
-
-function getSize(size) {
- if (size === 'dir')
- return '<dir>';
-
- return size;
-}
-
diff --git a/server/common/entity.js b/server/common/entity.js
deleted file mode 100644
index 8472a1bd..00000000
--- a/server/common/entity.js
+++ /dev/null
@@ -1,32 +0,0 @@
-'use strict';
-
-const Entities = {
- ' ': ' ',
- '<': '<',
- '>': '>',
-};
-
-const keys = Object.keys(Entities);
-
-module.exports.encode = (str) => {
- keys.forEach((code) => {
- const char = Entities[code];
- const reg = RegExp(char, 'g');
-
- str = str.replace(reg, code);
- });
-
- return str;
-};
-
-module.exports.decode = (str) => {
- keys.forEach((code) => {
- const char = Entities[code];
- const reg = RegExp(code, 'g');
-
- str = str.replace(reg, char);
- });
-
- return str;
-};
-
diff --git a/server/config.js b/server/config.js
index e085419f..9e0d7246 100644
--- a/server/config.js
+++ b/server/config.js
@@ -1,13 +1,14 @@
'use strict';
const DIR_SERVER = __dirname + '/';
+const DIR_COMMON = '../common/';
const DIR = DIR_SERVER + '../';
const path = require('path');
const fs = require('fs');
const exit = require(DIR_SERVER + 'exit');
-const CloudFunc = require(DIR_SERVER + 'cloudfunc');
+const CloudFunc = require(DIR_COMMON + 'cloudfunc');
const pullout = require('pullout/legacy');
const ponse = require('ponse');
diff --git a/server/rest.js b/server/rest.js
index fe8370e5..5da7b1a3 100644
--- a/server/rest.js
+++ b/server/rest.js
@@ -1,20 +1,21 @@
'use strict';
const DIR = './';
+const DIR_COMMON = '../common/';
const path = require('path');
const root = require(DIR + 'root');
const config = require(DIR + 'config');
-const CloudFunc = require(DIR + 'cloudfunc');
+const CloudFunc = require(DIR_COMMON + 'cloudfunc');
const markdown = require(DIR + 'markdown');
-const jaguar = require('jaguar/legacy');
-const onezip = require('onezip/legacy');
-const inly = require('inly/legacy');
-const flop = require('flop/legacy');
-const pullout = require('pullout/legacy');
+const jaguar = require('jaguar');
+const onezip = require('onezip');
+const inly = require('inly');
+const flop = require('flop');
+const pullout = require('pullout');
const ponse = require('ponse');
-const copymitter = require('copymitter/legacy');
+const copymitter = require('copymitter');
const json = require('jonny');
const check = require('checkup');
diff --git a/server/route.js b/server/route.js
index 40b7ba9c..e7196ede 100644
--- a/server/route.js
+++ b/server/route.js
@@ -3,18 +3,17 @@
const DIR = __dirname + '/../';
const DIR_TMPL = DIR + 'tmpl/';
const DIR_HTML = DIR + 'html/';
-const DIR_JSON = DIR + 'json/';
const DIR_SERVER = './';
+const DIR_COMMON = '../common/';
const DIR_FS = DIR_TMPL + 'fs/';
const fs = require('fs');
-const flop = require('flop/legacy');
+const flop = require('flop');
const ponse = require('ponse');
const files = require('files-io');
const rendy = require('rendy');
const exec = require('execon');
-const minify = require('minify');
const format = require('format-io');
const squad = require('squad');
const apart = require('apart');
@@ -22,10 +21,16 @@ const apart = require('apart');
const config = require(DIR_SERVER + 'config');
const root = require(DIR_SERVER + 'root');
const prefixer = require(DIR_SERVER + 'prefixer');
-const CloudFunc = require(DIR_SERVER + 'cloudfunc');
+const CloudFunc = require(DIR_COMMON + 'cloudfunc');
const prefix = squad(prefixer, apart(config, 'prefix'));
-const PATH_INDEX = DIR_HTML + 'index.html';
+const isDev = process.env.NODE_ENV === 'development';
+
+const getIndexPath = () => {
+ const dist = isDev ? 'dist-dev' : 'dist';
+
+ return DIR + `${dist}/index.html`;
+}
const TMPL_PATH = [
'file',
@@ -154,26 +159,16 @@ function readFiles(callback) {
function route(request, response, callback) {
let name = ponse.getPathName(request);
- const isAuth = RegExp('^(/auth|/auth/github)$').test(name);
const isFS = RegExp('^/$|^' + FS).test(name);
const p = {
- request : request,
- response : response,
+ request,
+ response,
gzip : true,
- name : name
+ name,
};
- if (!isAuth && !isFS)
- return callback();
-
- if (isAuth) {
- p.name = DIR_HTML + name + '.html';
- ponse.sendFile(p);
- return;
- }
-
if (!isFS)
- return;
+ return callback();
name = name.replace(CloudFunc.FS, '') || '/';
const fullPath = root(name);
@@ -184,7 +179,7 @@ function route(request, response, callback) {
if (!error)
return buildIndex(dir, (error, data) => {
- p.name = PATH_INDEX;
+ p.name = getIndexPath();
if (error)
return ponse.sendError(error, p);
@@ -208,28 +203,22 @@ function route(request, response, callback) {
}
function buildIndex(json, callback) {
- const isMinify = config('minify');
-
- exec.if(!isMinify, (error, name) => {
- fs.readFile(name || PATH_INDEX, 'utf8', (error, template) => {
- if (error)
- return;
-
- const panel = CloudFunc.buildFromJSON({
- data : json,
- prefix : prefix(),
- template : Template
- });
-
- const data = indexProcessing({
- panel : panel,
- data : template
- });
-
- callback(error, data);
+ fs.readFile(getIndexPath(), 'utf8', (error, template) => {
+ if (error)
+ return;
+
+ const panel = CloudFunc.buildFromJSON({
+ data : json,
+ prefix : prefix(),
+ template : Template
});
- }, (callback) => {
- minify(PATH_INDEX, 'name', callback);
+
+ const data = indexProcessing({
+ panel : panel,
+ data : template
+ });
+
+ callback(error, data);
});
}
diff --git a/test/server/terminal.js b/test/server/terminal.js
index 42813006..13dac032 100644
--- a/test/server/terminal.js
+++ b/test/server/terminal.js
@@ -1,13 +1,13 @@
'use strict';
const test = require('tape');
+const mock = require('mock-require');
const diff = require('sinon-called-with-diff');
const sinon = diff(require('sinon'));
const configPath = '../../server/config';
const terminalPath = '../../server/terminal';
-
test('cloudcmd: terminal: disabled', (t) => {
clean(terminalPath);
stub(configPath, () => {
@@ -59,6 +59,31 @@ test('cloudcmd: terminal: enabled', (t) => {
console.log = log;
clean(configPath);
+ require(configPath);
+
+ t.end();
+});
+
+test('cloudcmd: terminal: no arg', (t) => {
+ const gritty = {};
+
+ mock('gritty', gritty);
+
+ clean(terminalPath);
+ stub(configPath, (a) => {
+ if (a === 'terminal')
+ return true;
+
+ return 'gritty';
+ });
+
+ const terminal = require(terminalPath);
+ const result = terminal();
+
+ t.equal(result, gritty, 'should equal');
+
+ clean(configPath);
+ require(configPath);
t.end();
});
diff --git a/tmpl/config.hbs b/tmpl/config.hbs
index 05824506..bd7c4c1a 100644
--- a/tmpl/config.hbs
+++ b/tmpl/config.hbs
@@ -70,12 +70,6 @@
Directory Storage
-
-
-