feature(cloudcmd) add --root

This commit is contained in:
coderaiser 2015-04-07 03:23:59 -04:00
parent 2e6474cf8f
commit 3a8c71d363
6 changed files with 38 additions and 16 deletions

View file

@ -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

View file

@ -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);

View file

@ -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",

View file

@ -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)$/, '');

17
lib/server/root.js Normal file
View file

@ -0,0 +1,17 @@
(function() {
'use strict';
var DIR = './',
path = require('path'),
config = require(DIR + 'config'),
mellow = require('mellow');
module.exports = function(dir) {
var root = config('root') || '/';
if (root === '/')
dir = mellow.pathToWin(dir);
return path.join(root + dir);
};
})();

View file

@ -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);