mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
feature(cloudcmd) add command line parameter --root
This commit is contained in:
commit
03319626be
8 changed files with 53 additions and 23 deletions
1
HELP.md
1
HELP.md
|
|
@ -65,6 +65,7 @@ Cloud Commander supports command line parameters:
|
|||
| `-u, --username` | set username
|
||||
| `-p, --password` | set password
|
||||
| `-c, --config` | configuration file path
|
||||
| `--root` | set root folder
|
||||
| `--port` | set port number
|
||||
| `--no-auth` | disable authorization
|
||||
| `--no-server` | do not start server
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@
|
|||
'username',
|
||||
'online',
|
||||
'offline',
|
||||
'config'
|
||||
'config',
|
||||
'root'
|
||||
],
|
||||
boolean: [
|
||||
'auth',
|
||||
|
|
@ -61,6 +62,7 @@
|
|||
config('auth', args.auth);
|
||||
config('online', args.online);
|
||||
config('username', args.username);
|
||||
config('root', args.root);
|
||||
|
||||
readConfig(args.config);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
"-u, --username " : "set username",
|
||||
"-p, --password " : "set password",
|
||||
"-c, --config " : "configuration file path",
|
||||
"--root" : "set root folder",
|
||||
"--port " : "set port number",
|
||||
"--no-auth " : "disable authorization",
|
||||
"--no-server " : "do not start server",
|
||||
|
|
|
|||
|
|
@ -60,11 +60,13 @@
|
|||
config.socket(socket);
|
||||
|
||||
edward.listen(socket, {
|
||||
size: size
|
||||
size: size,
|
||||
root: config('root')
|
||||
});
|
||||
|
||||
dword.listen(socket, {
|
||||
size: size
|
||||
size: size,
|
||||
root: config('root')
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -89,7 +91,8 @@
|
|||
authFunc,
|
||||
config(),
|
||||
restafary({
|
||||
prefix: cloudfunc.apiURL + '/fs'
|
||||
prefix : cloudfunc.apiURL + '/fs',
|
||||
root : config('root')
|
||||
}),
|
||||
rest,
|
||||
route,
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
DIR_JSON = DIR_LIB + '../json/',
|
||||
|
||||
path = require('path'),
|
||||
root = require(DIR + 'root'),
|
||||
|
||||
Util = require(DIR_LIB + 'util'),
|
||||
CloudFunc = require(DIR_LIB + 'cloudfunc'),
|
||||
|
|
@ -23,7 +24,6 @@
|
|||
github = require('faust'),
|
||||
packer = require('jag'),
|
||||
|
||||
mellow = require('mellow'),
|
||||
flop = require('flop'),
|
||||
pipe = require('pipe-io'),
|
||||
ponse = require('ponse'),
|
||||
|
|
@ -198,8 +198,8 @@
|
|||
callback(error);
|
||||
|
||||
} else {
|
||||
files.from = mellow.pathToWin(files.from);
|
||||
files.to = mellow.pathToWin(files.to);
|
||||
files.from = root(files.from);
|
||||
files.to = root(files.to);
|
||||
|
||||
if (files.names)
|
||||
data = files.names.slice();
|
||||
|
|
@ -227,8 +227,8 @@
|
|||
error = getWin32RootMsg('from');
|
||||
callback(error);
|
||||
} else {
|
||||
files.from = mellow.pathToWin(files.from);
|
||||
files.to = mellow.pathToWin(files.to);
|
||||
files.from = root(files.from);
|
||||
files.to = root(files.to);
|
||||
|
||||
msg = formatMsg('copy', files.names);
|
||||
|
||||
|
|
@ -242,10 +242,10 @@
|
|||
if (!files.from) {
|
||||
callback(body);
|
||||
} else {
|
||||
from = mellow.pathToWin(files.from);
|
||||
from = root(files.from);
|
||||
|
||||
if (files.to)
|
||||
to = mellow.pathToWin(files.to);
|
||||
to = root(files.to);
|
||||
else
|
||||
to = from + '.gz';
|
||||
|
||||
|
|
@ -262,10 +262,10 @@
|
|||
if (!files.from) {
|
||||
callback(body);
|
||||
} else {
|
||||
from = mellow.pathToWin(files.from);
|
||||
from = root(files.from);
|
||||
|
||||
if (files.to)
|
||||
to = mellow.pathToWin(files.to);
|
||||
to = root(files.to);
|
||||
else
|
||||
to = files.from.replace(/(\.gz|\.tar\.gz)$/, '');
|
||||
|
||||
|
|
|
|||
22
lib/server/root.js
Normal file
22
lib/server/root.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
var DIR = './',
|
||||
path = require('path'),
|
||||
config = require(DIR + 'config'),
|
||||
mellow = require('mellow');
|
||||
|
||||
module.exports = function(dir) {
|
||||
var root = config('root') || '/';
|
||||
|
||||
if (dir === '/')
|
||||
dir = root;
|
||||
else
|
||||
if (root === '/')
|
||||
dir = mellow.pathToWin(dir);
|
||||
else
|
||||
dir = path.join(root, dir);
|
||||
|
||||
return dir;
|
||||
};
|
||||
})();
|
||||
|
|
@ -19,6 +19,7 @@
|
|||
format = require('format-io'),
|
||||
|
||||
config = require(DIR_SERVER + 'config'),
|
||||
root = require(DIR_SERVER + 'root'),
|
||||
|
||||
CloudFunc = require(DIR_LIB + 'cloudfunc'),
|
||||
|
||||
|
|
@ -126,7 +127,7 @@
|
|||
* routing of server queries
|
||||
*/
|
||||
function route(request, response, callback) {
|
||||
var name, p, isAuth, isFS, path;
|
||||
var name, p, isAuth, isFS, fullPath;
|
||||
|
||||
if (!request)
|
||||
throw Error('request could not be empty!');
|
||||
|
|
@ -157,10 +158,10 @@
|
|||
p.name = DIR_HTML + name + '.html';
|
||||
ponse.sendFile(p);
|
||||
} else if (isFS) {
|
||||
name = name.replace(CloudFunc.FS, '') || '/';
|
||||
path = mellow.pathToWin(name);
|
||||
name = name.replace(CloudFunc.FS, '') || '/';
|
||||
fullPath = root(name);
|
||||
|
||||
mellow.read(path, function(error, dir) {
|
||||
mellow.read(fullPath, function(error, dir) {
|
||||
if (dir)
|
||||
dir.path = format.addSlashToEnd(name);
|
||||
|
||||
|
|
@ -176,11 +177,11 @@
|
|||
else if (error.code !== 'ENOTDIR')
|
||||
ponse.sendError(error, p);
|
||||
else
|
||||
fs.realpath(path, function(error, pathReal) {
|
||||
fs.realpath(fullPath, function(error, pathReal) {
|
||||
if (!error)
|
||||
p.name = pathReal;
|
||||
else
|
||||
p.name = path;
|
||||
p.name = name;
|
||||
|
||||
p.gzip = false;
|
||||
ponse.sendFile(p);
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@
|
|||
"checkup": "~1.0.3",
|
||||
"console-io": "~2.2.0",
|
||||
"copymitter": "~1.6.0",
|
||||
"dword": "~1.3.2",
|
||||
"edward": "~1.4.0",
|
||||
"dword": "~1.4.0",
|
||||
"edward": "~1.5.0",
|
||||
"execon": "~1.1.0",
|
||||
"express": "~4.12.0",
|
||||
"faust": "~1.0.0",
|
||||
|
|
@ -46,14 +46,14 @@
|
|||
"join-io": "~1.3.0",
|
||||
"jonny": "~1.0.0",
|
||||
"markdown-it": "~4.1.0",
|
||||
"mellow": "~1.0.0",
|
||||
"mellow": "~1.3.0",
|
||||
"minify": "~1.4.0",
|
||||
"minimist": "~1.1.0",
|
||||
"mollify": "~1.0.0",
|
||||
"pipe-io": "~1.1.1",
|
||||
"ponse": "~1.3.0",
|
||||
"rendy": "~1.0.2",
|
||||
"restafary": "~1.1.0",
|
||||
"restafary": "~1.2.0",
|
||||
"socket.io": "~1.3.5",
|
||||
"try-catch": "~1.0.0",
|
||||
"tryrequire": "~1.1.5"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue