diff --git a/html/fs/index.html b/html/fs/index.html index 052b7b1b..2c028205 100644 --- a/html/fs/index.html +++ b/html/fs/index.html @@ -42,6 +42,7 @@ client = 'client/', files = [ 'util', + 'join', 'format', 'promise', 'cloudfunc', diff --git a/lib/client/console.js b/lib/client/console.js index c3af8bf6..b4478ae9 100644 --- a/lib/client/console.js +++ b/lib/client/console.js @@ -1,6 +1,6 @@ -var CloudCmd, Util, DOM, CloudFunc, $; +var CloudCmd, Util, join, DOM, CloudFunc, $; -(function(CloudCmd, Util, DOM, CloudFunc) { +(function(CloudCmd, Util, join, DOM, CloudFunc) { 'use strict'; CloudCmd.Console = ConsoleProto; @@ -147,14 +147,15 @@ var CloudCmd, Util, DOM, CloudFunc, $; function load(callback) { var dir = CloudCmd.LIBDIRCLIENT + 'console/', jsPath = dir + 'lib/', - css = [ + + css = join([ '/css/console.css', dir + 'css/ansi.css', - ], - cssAll = CloudFunc.getJoinURL(css), + ]), + files = [ jsPath + 'jqconsole.js', - cssAll + css ]; DOM.load.parallel(files, function() { @@ -217,4 +218,4 @@ var CloudCmd, Util, DOM, CloudFunc, $; init(); } -})(CloudCmd, Util, DOM, CloudFunc); +})(CloudCmd, Util, join, DOM, CloudFunc); diff --git a/lib/client/edit.js b/lib/client/edit.js index 461374c8..404492cd 100644 --- a/lib/client/edit.js +++ b/lib/client/edit.js @@ -1,5 +1,5 @@ -var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuIO, Format; -(function(CloudCmd, Util, DOM, CloudFunc) { +var CloudCmd, Util, join, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuIO, Format; +(function(CloudCmd, Util, Join, DOM, CloudFunc) { 'use strict'; CloudCmd.Edit = EditProto; @@ -157,7 +157,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI if (!isHTML) Util.exec(callback); else { - url = CloudFunc.getJoinURL([ + url = join([ DIR + 'emmet.js', DIR + 'ext-emmet.js' ]); @@ -287,11 +287,10 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI } function diff(newValue, callback) { - var libs = [ + var url = join([ LIBDIR + 'diff/diff-match-patch.js', LIBDIR + 'diff.js' - ], - url = CloudFunc.getJoinURL(libs); + ]); DOM.load.js(url, function(error) { var patch, @@ -322,11 +321,10 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI function zip(value, callback) { var dir = CloudCmd.LIBDIRCLIENT, - libs = [ + url = join([ dir + 'zip/dist/pako.js', dir + 'zip.js' - ], - url = CloudFunc.getJoinURL(libs); + ]); DOM.load.js(url, function() { Zip.pack(value, callback); @@ -412,7 +410,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI } function load(callback) { - var url = CloudFunc.getJoinURL([ + var url = join([ 'theme-tomorrow_night_blue', 'ext-language_tools', 'ext-searchbox', @@ -512,4 +510,4 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI init(); } -})(CloudCmd, Util, DOM, CloudFunc); +})(CloudCmd, Util, join, DOM, CloudFunc); diff --git a/lib/client/storage/_github.js b/lib/client/storage/_github.js index b2a8ab1d..1d2624de 100644 --- a/lib/client/storage/_github.js +++ b/lib/client/storage/_github.js @@ -1,6 +1,6 @@ -var CloudCmd, Util, DOM, CloudFunc, Github, cb; +var CloudCmd, Util, join, DOM, CloudFunc, Github, cb; -(function(CloudCmd, Util, DOM, CloudFunc) { +(function(CloudCmd, Util, join, DOM, CloudFunc) { 'use strict'; CloudCmd.GitHub = GitHubProto; @@ -32,13 +32,11 @@ var CloudCmd, Util, DOM, CloudFunc, Github, cb; function load(callback) { var dir = CloudCmd.LIBDIRCLIENT + 'storage/github/', - files = [ + url = join([ dir + 'lib/underscore.js', dir + 'lib/base64.js', dir + 'github.js' - - ], - url = CloudFunc.getJoinURL(files); + ]); Util.time('github'); @@ -163,4 +161,4 @@ var CloudCmd, Util, DOM, CloudFunc, Github, cb; init(callback); } -})(CloudCmd, Util, DOM, CloudFunc); +})(CloudCmd, Util, join, DOM, CloudFunc); diff --git a/lib/cloudfunc.js b/lib/cloudfunc.js index de53496d..55481cea 100644 --- a/lib/cloudfunc.js +++ b/lib/cloudfunc.js @@ -13,8 +13,7 @@ var Util; function CloudFuncProto(Util) { var CloudFunc = this, - FS, - JOIN = '/join/'; + FS; /* КОНСТАНТЫ (общие для клиента и сервера)*/ @@ -58,25 +57,6 @@ var Util; return str; }; - this.getJoinURL = function(names) { - var url, - regExp = new RegExp(',', 'g'), - nameStr = names + ''; - - nameStr = nameStr.replace(regExp, ':'); - nameStr = this.rmFirstSlash(nameStr); - url = JOIN + nameStr; - - return url; - }; - - this.getJoinArray = function(url) { - var str = Util.rmStrOnce(url, JOIN), - names = str.split(':'); - - return names; - }; - this.formatMsg = function(msg, name, status) { if (!status) status = 'ok'; diff --git a/lib/server/join.js b/lib/server/join.js index a4dc7016..0276a4eb 100644 --- a/lib/server/join.js +++ b/lib/server/join.js @@ -7,7 +7,6 @@ ponse = require(DIR_SERVER + 'ponse'), Util = require(DIR + 'util'), - CloudFunc = require(DIR + 'cloudfunc'), zlib = require('zlib'); module.exports = function(before) { @@ -20,12 +19,21 @@ readFunc = exec.with(readPipe, req, res), path = ponse.getPathName(req), regExp = new RegExp('^/join/'), - isJoin = path.match(regExp); + regExpFile = new RegExp('^/join/join.js$'), + isJoin = path.match(regExp), + isJoinFile = path.match(regExpFile); - if (!isJoin) { + if (isJoinFile) { + ponse.sendFile({ + name : __dirname + '/../join.js', + gzip : true, + request : req, + response: res + }); + } else if (!isJoin) { next(); } else { - names = CloudFunc.getJoinArray(path); + names = parse(path); exec.if(!before, readFunc, function(callback) { before(names, callback); @@ -35,6 +43,19 @@ return isJoin; } + function parse(url) { + var names, + isStr = typeof url === 'string'; + + if (!isStr) + throw(Error('url must be string!')); + + names = url.replace('/join', '') + .split(':'); + + return names; + } + function readPipe(req, res, names) { var stream, path = ponse.getPathName(req), @@ -61,10 +82,11 @@ if (res.headersSent) stream.end(msg); else - ponse.send.error(msg, { + ponse.sendError(msg, { + name : path, + gzip : isGzip, request : req, - response : res, - name : path + response : res }); } }