Compare commits
15 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a9bac620f | ||
|
|
b8ba564c99 | ||
|
|
c6ed4fc4ac | ||
|
|
3bb8198d71 | ||
|
|
287d60451c | ||
|
|
a73c80687c | ||
|
|
67be90bcd2 | ||
|
|
cc64990b27 | ||
|
|
63ec716801 | ||
|
|
7e07f586c3 | ||
|
|
1c1582b48b | ||
|
|
1d9b1177b8 | ||
|
|
92bac91c6e | ||
|
|
5c647bc372 | ||
|
|
040b06903b |
3
.gitignore
vendored
|
|
@ -19,9 +19,6 @@ modules/jquery-mousewheel
|
|||
modules/execon
|
||||
modules/emitify
|
||||
|
||||
legacy
|
||||
server_
|
||||
|
||||
.nyc_output
|
||||
|
||||
*.swp
|
||||
|
|
|
|||
|
|
@ -28,8 +28,5 @@ bin/legacy.js
|
|||
|
||||
client
|
||||
|
||||
legacy/bin/release.js
|
||||
legacy/bin/legacy.js
|
||||
|
||||
webpack.config.js
|
||||
|
||||
|
|
|
|||
15
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:
|
||||
|
|
|
|||
6
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)**
|
||||
|
|
|
|||
|
|
@ -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])
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
@ -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 + '<ul data-name="js-files" class="files">';
|
||||
/* Если мы не в корне */
|
||||
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 += '</ul>';
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 205 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 100 KiB |
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 91 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 140 KiB |
|
Before Width: | Height: | Size: 184 KiB After Width: | Height: | Size: 580 KiB |
|
|
@ -10,7 +10,6 @@
|
|||
"localStorage": true,
|
||||
"buffer": true,
|
||||
"dirStorage": false,
|
||||
"minify": false,
|
||||
"online": true,
|
||||
"open": false,
|
||||
"cache": true,
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
34
package.json
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "cloudcmd",
|
||||
"version": "6.15.4",
|
||||
"version": "7.0.0",
|
||||
"author": "coderaiser <mnemonic.enemy@gmail.com> (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"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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 + '<ul data-name="js-files" class="files">';
|
||||
/* Если мы не в корне */
|
||||
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 += '</ul>';
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -70,12 +70,6 @@
|
|||
Directory Storage
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label>
|
||||
<input data-name="js-minify" type="checkbox" {{ minify }}>
|
||||
Minify
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label>
|
||||
<input data-name="js-online" type="checkbox" {{ online }}>
|
||||
|
|
|
|||
|
|
@ -17,7 +17,10 @@ const distDev = path.resolve(__dirname, 'dist-dev');
|
|||
const devtool = isDev ? 'eval' : 'source-map';
|
||||
const notEmpty = (a) => a;
|
||||
const clean = (array) => array.filter(notEmpty);
|
||||
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||
const HtmlWebpackExcludeAssetsPlugin = require('html-webpack-exclude-assets-plugin')
|
||||
|
||||
const extractMain = new ExtractTextPlugin('[name].css');
|
||||
const extractNojs = new ExtractTextPlugin('nojs.css');
|
||||
|
|
@ -34,6 +37,12 @@ const plugins = clean([
|
|||
name: 'cloudcmd',
|
||||
filename: 'cloudcmd.js',
|
||||
}),
|
||||
new HtmlWebpackPlugin({
|
||||
template: 'html/index.html',
|
||||
minify: !isDev && getMinifyHtmlOptions(),
|
||||
excludeAssets: [/\\*/],
|
||||
}),
|
||||
new HtmlWebpackExcludeAssetsPlugin(),
|
||||
extractMain,
|
||||
extractNojs,
|
||||
extractView,
|
||||
|
|
@ -119,7 +128,7 @@ function devtoolModuleFilenameTemplate(info) {
|
|||
|
||||
function extract(name, extractCss) {
|
||||
return {
|
||||
test: RegExp(`css\/${name}\.css`),
|
||||
test: RegExp(`css/${name}.css`),
|
||||
use: extractCss.extract([
|
||||
isDev ?
|
||||
'css-loader'
|
||||
|
|
@ -129,3 +138,28 @@ function extract(name, extractCss) {
|
|||
};
|
||||
}
|
||||
|
||||
function getMinifyHtmlOptions() {
|
||||
return {
|
||||
removeComments: true,
|
||||
removeCommentsFromCDATA: true,
|
||||
removeCDATASectionsFromCDATA: true,
|
||||
collapseWhitespace: true,
|
||||
collapseBooleanAttributes: true,
|
||||
removeAttributeQuotes: true,
|
||||
removeRedundantAttributes: true,
|
||||
useShortDoctype: true,
|
||||
removeEmptyAttributes: true,
|
||||
/* оставляем, поскольку у нас
|
||||
* в элемент fm генерируеться
|
||||
* таблица файлов
|
||||
*/
|
||||
removeEmptyElements: false,
|
||||
removeOptionalTags: true,
|
||||
removeScriptTypeAttributes: true,
|
||||
removeStyleLinkTypeAttributes: true,
|
||||
|
||||
minifyJS: true,
|
||||
minifyCSS: true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||