From c8345f531c8feffbd4993dd4b60b37962ab56b2b Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 30 Nov 2012 06:30:54 -0500 Subject: [PATCH] added description --- lib/server/appcache.js | 9 +++++++++ lib/server/main.js | 46 +++++++++++++++++++++++++----------------- lib/util.js | 26 ++++++++++++++++++------ 3 files changed, 56 insertions(+), 25 deletions(-) diff --git a/lib/server/appcache.js b/lib/server/appcache.js index ef86fc11..4a43225e 100644 --- a/lib/server/appcache.js +++ b/lib/server/appcache.js @@ -2,6 +2,15 @@ (function(){ "use strict"; + if(!global.cloudcmd) + return console.log( + '# appcache.js' + '\n' + + '# -----------' + '\n' + + '# Module is part of Cloud Commander,' + '\n' + + '# used for work with Aplication Cache.' + '\n' + + '# If you wont to see at work set appcache: true' + '\n' + + '# in config.json and start cloudcmd.js' + '\n'); + var main = global.cloudcmd.main, fs = main.fs, Util = main.util, diff --git a/lib/server/main.js b/lib/server/main.js index 51c52a33..bce4758a 100644 --- a/lib/server/main.js +++ b/lib/server/main.js @@ -11,7 +11,10 @@ SLASH, ISWIN32, + + fs, path, + zlib, OK = 200, ERROR = 404, @@ -30,7 +33,7 @@ /* Native Modules*/ exports.crypto = require('crypto'), exports.child_process = require('child_process'), - exports.fs = require('fs'), + exports.fs = fs = require('fs'), exports.http = require('http'), exports.https = require('https'), exports.path = path = require('path'), @@ -60,7 +63,7 @@ /* Needed Modules */ exports.util = Util = require(LIBDIR + 'util'), - exports.zlib = mrequire('zlib'), + exports.zlib = zlib = mrequire('zlib'), /* Main Information */ exports.config = rootrequire('config'); @@ -181,29 +184,34 @@ lEnc = lReq.headers['accept-encoding'] || '', lGzip = lEnc.match(/\bgzip\b/), - lReadStream; + lReadStream, - main.fs.exists(lName, function(pExist){ - lRet = pExist; - if(pExist){ - lReadStream = main.fs.createReadStream(lName, { - 'bufferSize': 4 * 1024 - }); - lRes.writeHead(OK, generateHeaders(lName, lGzip) ); - - if (lGzip) - lReadStream = lReadStream.pipe( main.zlib.createGzip() ); - - lReadStream.pipe(lRes); - } - else{ + lSendError = function(pError){ var lJson = JSON.stringify({ - error: 'File not Found' + error: pError }); lRes.writeHead(ERROR, 'OK'); lRes.end(lJson); - } + }; + + main.fs.exists(lName, function(pExist){ + lRet = pExist; + if(pExist) + Util.tryCatch(function(){ + lReadStream = fs.createReadStream(lName, { + 'bufferSize': 4 * 1024 + }); + lRes.writeHead(OK, generateHeaders(lName, lGzip) ); + + if (lGzip) + lReadStream = lReadStream.pipe( zlib.createGzip() ); + + lReadStream.pipe(lRes); + }, lSendError); + + else + lSendError('File not Found'); }); return lRet; diff --git a/lib/util.js b/lib/util.js index 7d5c16c2..bf844703 100644 --- a/lib/util.js +++ b/lib/util.js @@ -303,10 +303,10 @@ var Util, exports; * function execute param function in * try...catch block and log result * - * @param pCallBack + * @param pTryFunc */ - Util.tryCatchDebug = function(pCallBack){ - var lRet = Util.tryCatch(pCallBack); + Util.tryCatchDebug = function(pTryFunc){ + var lRet = Util.tryCatch(pTryFunc); if(lRet) Util.debug(); @@ -318,16 +318,30 @@ var Util, exports; * function execute param function in * try...catch block and log result * - * @param pCallBack + * @param pTryFunc */ - Util.tryCatchLog = function(pCallBack){ + Util.tryCatchLog = function(pTryFunc){ var lRet; - lRet = Util.tryCatch(pCallBack); + lRet = Util.tryCatch(pTryFunc); return Util.log(lRet); }; + /** + * function execute param function in + * try...catch block and log result + * + * @param pCallBack + */ + Util.tryCatchCall = function(pTryFunc, pCallBack){ + var lRet; + + lRet = Util.tryCatch(pTryFunc); + + return Util.exec(pCallBack, lRet); + }; + /** * function do save exec of function * @param pCallBack