From 3a8c71d36375a931020db7fba59b4189aef0c5a9 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 7 Apr 2015 03:23:59 -0400 Subject: [PATCH 1/8] feature(cloudcmd) add --root --- HELP.md | 1 + bin/cloudcmd.js | 4 +++- json/bin.json | 1 + lib/server/rest.js | 18 +++++++++--------- lib/server/root.js | 17 +++++++++++++++++ lib/server/route.js | 13 +++++++------ 6 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 lib/server/root.js diff --git a/HELP.md b/HELP.md index 93807a4a..c501d12e 100644 --- a/HELP.md +++ b/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 diff --git a/bin/cloudcmd.js b/bin/cloudcmd.js index ed78a849..cf45114d 100755 --- a/bin/cloudcmd.js +++ b/bin/cloudcmd.js @@ -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); diff --git a/json/bin.json b/json/bin.json index 62501a1a..8cfaa73b 100644 --- a/json/bin.json +++ b/json/bin.json @@ -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", diff --git a/lib/server/rest.js b/lib/server/rest.js index 845b4d8e..0679c7c1 100644 --- a/lib/server/rest.js +++ b/lib/server/rest.js @@ -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)$/, ''); diff --git a/lib/server/root.js b/lib/server/root.js new file mode 100644 index 00000000..8ae10076 --- /dev/null +++ b/lib/server/root.js @@ -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); + }; +})(); diff --git a/lib/server/route.js b/lib/server/route.js index 9b025a6c..8c3183cf 100644 --- a/lib/server/route.js +++ b/lib/server/route.js @@ -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); From 142daeb924e16a35289d2b0a5b667182f279b01c Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 7 Apr 2015 04:15:08 -0400 Subject: [PATCH 2/8] feature(package) restafary v1.2.0 --- lib/cloudcmd.js | 3 ++- lib/server/route.js | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/cloudcmd.js b/lib/cloudcmd.js index 84cf72eb..36759c8b 100644 --- a/lib/cloudcmd.js +++ b/lib/cloudcmd.js @@ -89,7 +89,8 @@ authFunc, config(), restafary({ - prefix: cloudfunc.apiURL + '/fs' + prefix : cloudfunc.apiURL + '/fs', + root : config('root') || '/' }), rest, route, diff --git a/lib/server/route.js b/lib/server/route.js index 8c3183cf..7ff5c7b1 100644 --- a/lib/server/route.js +++ b/lib/server/route.js @@ -158,12 +158,12 @@ p.name = DIR_HTML + name + '.html'; ponse.sendFile(p); } else if (isFS) { - name = name.replace(CloudFunc.FS, '') || '/'; + fullPath = name.replace(CloudFunc.FS, '') || '/'; fullPath = root(name); mellow.read(fullPath, function(error, dir) { if (dir) - dir.path = format.addSlashToEnd(name); + dir.path = format.addSlashToEnd(fullPath); if (!error) buildIndex(dir, function(error, data) { diff --git a/package.json b/package.json index b51c9d40..e2e1647c 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "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", "tryrequire": "~1.1.5" }, From 0c76d2dbdf87cc90bda81a554fd3aa2c9f409260 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 7 Apr 2015 05:22:36 -0400 Subject: [PATCH 3/8] feature(package) mellow v1.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e2e1647c..ac8ff9c8 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "join-io": "~1.3.0", "jonny": "~1.0.0", "markdown-it": "~4.1.0", - "mellow": "~1.0.0", + "mellow": "~1.1.0", "minify": "~1.4.0", "minimist": "~1.1.0", "mollify": "~1.0.0", From 29beabb1147d425c0f933c5e548356921122de3a Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 7 Apr 2015 05:22:52 -0400 Subject: [PATCH 4/8] fix(root) pathToWin only when root dir fix(route) fullPath -> name --- lib/server/root.js | 4 +++- lib/server/route.js | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/server/root.js b/lib/server/root.js index 8ae10076..a05aa3f4 100644 --- a/lib/server/root.js +++ b/lib/server/root.js @@ -11,7 +11,9 @@ if (root === '/') dir = mellow.pathToWin(dir); + else + dir = path.join(root + dir); - return path.join(root + dir); + return dir; }; })(); diff --git a/lib/server/route.js b/lib/server/route.js index 7ff5c7b1..8c3183cf 100644 --- a/lib/server/route.js +++ b/lib/server/route.js @@ -158,12 +158,12 @@ p.name = DIR_HTML + name + '.html'; ponse.sendFile(p); } else if (isFS) { - fullPath = name.replace(CloudFunc.FS, '') || '/'; + name = name.replace(CloudFunc.FS, '') || '/'; fullPath = root(name); mellow.read(fullPath, function(error, dir) { if (dir) - dir.path = format.addSlashToEnd(fullPath); + dir.path = format.addSlashToEnd(name); if (!error) buildIndex(dir, function(error, data) { From 99d55be497c979bd10255c2d84ac214756b5697c Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 7 Apr 2015 06:26:17 -0400 Subject: [PATCH 5/8] feature(config) tryrequire -> try-catch --- lib/server/config.js | 18 +++++++++++++++--- lib/server/root.js | 5 ++++- package.json | 2 ++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/server/config.js b/lib/server/config.js index c76a3999..b026ee9c 100644 --- a/lib/server/config.js +++ b/lib/server/config.js @@ -17,7 +17,7 @@ CloudFunc = require(DIR_LIB + 'cloudfunc'), check = require('checkup'), - tryRequire = require('tryrequire'), + tryCatch = require('try-catch'), pipe = require('pipe-io'), ponse = require('ponse'), json = require('jonny'), @@ -29,12 +29,24 @@ config = tryRequire(ConfigHome) || - tryRequire(ConfigPath, {log: true}) || {}; - + tryRequire(ConfigPath); + module.exports = manage; module.exports.save = save; module.exports.socket = socket; + function tryRequire(path) { + var ret, + error = tryCatch(function() { + ret = require(path); + }); + + if (error && error.code !== 'MODULE_NOT_FOUND') + console.error(error.message); + + return ret; + } + function manage(key, value) { var result; diff --git a/lib/server/root.js b/lib/server/root.js index a05aa3f4..8fcea13a 100644 --- a/lib/server/root.js +++ b/lib/server/root.js @@ -4,7 +4,8 @@ var DIR = './', path = require('path'), config = require(DIR + 'config'), - mellow = require('mellow'); + mellow = require('mellow'), + log = require('debug')('cloudcmd-root'); module.exports = function(dir) { var root = config('root') || '/'; @@ -14,6 +15,8 @@ else dir = path.join(root + dir); + log(dir); + return dir; }; })(); diff --git a/package.json b/package.json index ac8ff9c8..e37de7ee 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "checkup": "~1.0.3", "console-io": "~2.2.0", "copymitter": "~1.6.0", + "debug": "~2.1.3", "dword": "~1.3.2", "edward": "~1.4.0", "execon": "~1.1.0", @@ -55,6 +56,7 @@ "rendy": "~1.0.2", "restafary": "~1.2.0", "socket.io": "~1.3.5", + "try-catch": "~1.0.0", "tryrequire": "~1.1.5" }, "devDependencies": { From d6e9fa7c88696228f43f5f2e26fb94b75d8df581 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 7 Apr 2015 09:25:40 -0400 Subject: [PATCH 6/8] feature(package) mellow v1.3.0 --- lib/server/root.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/server/root.js b/lib/server/root.js index 8fcea13a..787072e3 100644 --- a/lib/server/root.js +++ b/lib/server/root.js @@ -10,10 +10,10 @@ module.exports = function(dir) { var root = config('root') || '/'; - if (root === '/') + if (root === '/' && dir !== '/') dir = mellow.pathToWin(dir); else - dir = path.join(root + dir); + dir = path.join(root, dir); log(dir); diff --git a/package.json b/package.json index e37de7ee..1aa3ba8f 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "join-io": "~1.3.0", "jonny": "~1.0.0", "markdown-it": "~4.1.0", - "mellow": "~1.1.0", + "mellow": "~1.3.0", "minify": "~1.4.0", "minimist": "~1.1.0", "mollify": "~1.0.0", From 7c466558437415fc4a9e4c32f4b357a9f3175d7c Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 7 Apr 2015 09:35:10 -0400 Subject: [PATCH 7/8] feature(root) add condition dir and root --- lib/server/root.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/server/root.js b/lib/server/root.js index 787072e3..8668e57a 100644 --- a/lib/server/root.js +++ b/lib/server/root.js @@ -10,10 +10,13 @@ module.exports = function(dir) { var root = config('root') || '/'; - if (root === '/' && dir !== '/') - dir = mellow.pathToWin(dir); + if (dir === '/') + dir = root; else - dir = path.join(root, dir); + if (root === '/') + dir = mellow.pathToWin(dir); + else + dir = path.join(root, dir); log(dir); From 03402e7a55756ce906555bfd51b3382a28bf7ced Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 7 Apr 2015 10:27:20 -0400 Subject: [PATCH 8/8] feature(cloudcmd) dword, edward: add root --- lib/cloudcmd.js | 8 +++++--- lib/server/root.js | 5 +---- package.json | 5 ++--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/cloudcmd.js b/lib/cloudcmd.js index 36759c8b..dcfddc38 100644 --- a/lib/cloudcmd.js +++ b/lib/cloudcmd.js @@ -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') }); }; @@ -90,7 +92,7 @@ config(), restafary({ prefix : cloudfunc.apiURL + '/fs', - root : config('root') || '/' + root : config('root') }), rest, route, diff --git a/lib/server/root.js b/lib/server/root.js index 8668e57a..95f50d05 100644 --- a/lib/server/root.js +++ b/lib/server/root.js @@ -4,8 +4,7 @@ var DIR = './', path = require('path'), config = require(DIR + 'config'), - mellow = require('mellow'), - log = require('debug')('cloudcmd-root'); + mellow = require('mellow'); module.exports = function(dir) { var root = config('root') || '/'; @@ -18,8 +17,6 @@ else dir = path.join(root, dir); - log(dir); - return dir; }; })(); diff --git a/package.json b/package.json index 1aa3ba8f..1d653880 100644 --- a/package.json +++ b/package.json @@ -33,9 +33,8 @@ "checkup": "~1.0.3", "console-io": "~2.2.0", "copymitter": "~1.6.0", - "debug": "~2.1.3", - "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",