diff --git a/cloudcmd.js b/cloudcmd.js index 2e3ea81d..8e293918 100644 --- a/cloudcmd.js +++ b/cloudcmd.js @@ -1,4 +1,4 @@ -(function(){ +(function() { 'use strict'; var DIR = __dirname + '/', @@ -86,7 +86,7 @@ /** * init and process of appcache if it allowed in config */ - function appCacheProcessing(){ + function appCacheProcessing() { var lFONT_REMOTE = '//themes.googleusercontent.com/static/fonts/droidsansmono/v4/ns-m2xQYezAtqh7ai59hJUYuTAAIFFn5GTWtryCmBQ4.woff', lFONT_LOCAL = './font/DroidSansMono.woff', lJQUERY_REMOTE = '//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js', @@ -107,7 +107,7 @@ * Функция минимизирует css/js/html * если установлены параметры минимизации */ - function minimize(pAllowed){ + function minimize(pAllowed) { var lOptimizeParams = [], lStyles = [{}, {}], lStyleCSS = DIR + 'css/style.css', @@ -139,11 +139,11 @@ * rest interface * @pParams pConnectionData {request, responce} */ - function rest(pConnectionData){ + function rest(pConnectionData) { return Util.exec(main.rest, pConnectionData); } - function init(){ + function init() { var lServerDir, lArg, lParams, lFiles; if (update) @@ -182,8 +182,8 @@ } if (Config.server) - Util.tryCatchLog(function(){ - fs.watch(CONFIG_PATH, function(){ + Util.tryCatchLog(function() { + fs.watch(CONFIG_PATH, function() { /* every catch up - calling twice */ setTimeout(function() { readConfig(); @@ -203,7 +203,7 @@ if (Config.ssl) lFiles.push(CA, KEY, CERT); - main.readFiles(lFiles, function(pErrors, pFiles){ + main.readFiles(lFiles, function(pErrors, pFiles) { if (pErrors) Util.log(pErrors); else { @@ -222,10 +222,10 @@ }); } - function readConfig(pCallBack){ - fs.readFile(CONFIG_PATH, function(pError, pData){ + function readConfig(pCallBack) { + fs.readFile(CONFIG_PATH, function(pError, pData) { var msg, status; - if (!pError){ + if (!pError) { status = 'ok'; var lStr = pData.toString(), @@ -234,7 +234,7 @@ if (!Config.minify) main.config = Config = lReadedConf; - Util.tryCatchLog(function(){ + Util.tryCatchLog(function() { Config.minify = lReadedConf.minify; Config.cache = lReadedConf.cache; @@ -254,13 +254,13 @@ /** * routing of server queries */ - function route(pParams){ + function route(pParams) { var lRet = main.checkParams(pParams); - if (lRet){ + if (lRet) { var p = pParams; - if ( Util.strCmp(p.name, ['/auth', '/auth/github']) ){ + if ( Util.strCmp(p.name, ['/auth', '/auth/github']) ) { Util.log('* Routing' + '-> ' + p.name); @@ -277,14 +277,14 @@ return lRet; } - function sendCommanderContent(pParams){ + function sendCommanderContent(pParams) { var p, lRet = main.checkParams(pParams); - if (lRet){ + if (lRet) { p = pParams; p.name = Util.removeStrOneTime(p.name, CloudFunc.FS) || main.SLASH; - fs.stat(p.name, function(pError, pStat){ + fs.stat(p.name, function(pError, pStat) { if (!pError) if ( pStat.isDirectory() ) processCommanderContent(pParams); @@ -298,22 +298,22 @@ return lRet; } - function processCommanderContent(pParams){ + function processCommanderContent(pParams) { var lRet = main.checkParams(pParams); - if (lRet){ + if (lRet) { var p = pParams; - main.commander.getDirContent(p.name, function(pError, pJSON){ - if (!pError){ + main.commander.getDirContent(p.name, function(pError, pJSON) { + if (!pError) { var lQuery = main.getQuery(p.request); - if ( Util.isContainStr(lQuery, 'json') ){ + if ( Util.isContainStr(lQuery, 'json') ) { p.data = Util.stringifyJSON(pJSON); p.name +='.json'; main.sendResponse(p, null, true); } else{ /* get back html*/ p.name = Minify.allowed ? Minify.getName(INDEX) : INDEX; - fs.readFile(p.name, function(pError, pData){ + fs.readFile(p.name, function(pError, pData) { if (!pError) { var lPanel = CloudFunc.buildFromJSON(pJSON, FileTemplate, PathTemplate), lList = '' + diff --git a/lib/client.js b/lib/client.js index b5dbbd28..d9118657 100644 --- a/lib/client.js +++ b/lib/client.js @@ -4,7 +4,7 @@ */ var Util, DOM, CloudFunc, CloudCmd; -(function(Util, DOM){ +(function(Util, DOM) { 'use strict'; var Key, Config, Modules, FileTemplate, PathTemplate, Listeners, @@ -19,7 +19,7 @@ var Util, DOM, CloudFunc, CloudCmd; MIN_ONE_PANEL_WIDTH : 1155, OLD_BROWSER : false, - HOST : (function(){ + HOST : (function() { var lLocation = document.location; return lLocation.protocol + '//' + lLocation.host; })() @@ -32,8 +32,8 @@ var Util, DOM, CloudFunc, CloudCmd; * @param pLink - ссылка * @param pNeedRefresh - необходимость обязательной загрузки данных с сервера */ - CloudCmd.loadDir = function(pLink, pNeedRefresh){ - return function(pEvent){ + CloudCmd.loadDir = function(pLink, pNeedRefresh) { + return function(pEvent) { /* показываем гиф загрузки возле пути папки сверху * ctrl+r нажата? */ @@ -43,7 +43,7 @@ var Util, DOM, CloudFunc, CloudCmd; lLink += '?json'; - if(lLink || lCurrentLink.target !== '_blank'){ + if (lLink || lCurrentLink.target !== '_blank') { DOM.Images.showLoad(pNeedRefresh ? {top:true} : null); /* загружаем содержимое каталога */ @@ -61,13 +61,13 @@ var Util, DOM, CloudFunc, CloudCmd; * в верх по файловой структуре * @param pDirName - имя каталога с которого мы пришли */ - function currentToParent(pDirName){ + function currentToParent(pDirName) { var lRootDir; /* убираем слэш с имени каталога */ pDirName = Util.removeStr(pDirName, '/'); lRootDir = DOM.getCurrentFileByName(pDirName); - if (lRootDir){ + if (lRootDir) { DOM.setCurrentFile(lRootDir); DOM.scrollIntoViewIfNeeded(lRootDir, true); } @@ -77,36 +77,36 @@ var Util, DOM, CloudFunc, CloudCmd; * function load modules * @pParams = {name, path, func, dobefore, arg} */ - function loadModule(pParams){ - if(pParams){ + function loadModule(pParams) { + if (pParams) { var lName = pParams.name, lPath = pParams.path, lFunc = pParams.func, lDoBefore = pParams.dobefore; - if( Util.isString(pParams) ) + if ( Util.isString(pParams) ) lPath = pParams; - if(lPath && !lName){ + if (lPath && !lName) { lName = Util.getStrBigFirst(lPath); lName = Util.removeStr(lName, '.js'); var lSlash = lName.indexOf('/'); - if(lSlash > 0){ + if (lSlash > 0) { var lAfterSlash = lName.substr(lSlash); lName = Util.removeStr(lName, lAfterSlash); } } - if( !Util.isContainStr(lPath, '.js') ) + if ( !Util.isContainStr(lPath, '.js') ) lPath += '.js'; - if(!CloudCmd[lName]) - CloudCmd[lName] = function(pArg){ + if (!CloudCmd[lName]) + CloudCmd[lName] = function(pArg) { Util.exec(lDoBefore); return DOM.jsload(CloudCmd.LIBDIRCLIENT + lPath, lFunc || - function(){ + function() { Util.exec(CloudCmd[lName].init, pArg); }); }; @@ -117,7 +117,7 @@ var Util, DOM, CloudFunc, CloudCmd; * выполняет весь функционал по * инициализации */ - CloudCmd.init = function(){ + CloudCmd.init = function() { var lCallBack, lFunc, lHeight; /* устанавливаем размер высоты таблицы файлов * исходя из размеров разрешения экрана @@ -141,14 +141,14 @@ var Util, DOM, CloudFunc, CloudCmd; '}' }); - lCallBack = function(){ + lCallBack = function() { Util.loadOnLoad([ Util.retFunc(CloudCmd.route, location.hash), baseInit, initModules, ]); }, - lFunc = function(pCallBack){ + lFunc = function(pCallBack) { CloudCmd.OLD_BROWSER = true; var lSrc = CloudCmd.LIBDIRCLIENT + 'polyfill.js'; @@ -160,7 +160,7 @@ var Util, DOM, CloudFunc, CloudCmd; Util.ifExec(document.body.scrollIntoViewIfNeeded, lCallBack, lFunc); }; - CloudCmd.route = function(pPath){ + CloudCmd.route = function(pPath) { var lQuery, lModule, lFile, lCurrent, lMsg; if (pPath.length > 0) { @@ -181,11 +181,11 @@ var Util, DOM, CloudFunc, CloudCmd; } }; - function initModules(pCallBack){ + function initModules(pCallBack) { loadModule({ /* привязываем клавиши к функциям */ path : 'key.js', - func : function(){ + func : function() { Key = CloudCmd.Key; Key.bind(); } @@ -214,14 +214,14 @@ var Util, DOM, CloudFunc, CloudCmd; for (i = 0, n = pModules.length; i < n ; i++) { var lModule = pModules[i]; - if( Util.isString(lModule) ) + if ( Util.isString(lModule) ) lLoad(null, lModule, lDoBefore[lModule]); } var lStorageObj = Util.findObjByNameInArr( pModules, lStorage ), lMod = Util.getNamesFromObjArray( lStorageObj ); - for (i = 0, n = lMod.length; i < n; i++){ + for (i = 0, n = lMod.length; i < n; i++) { var lName = lMod[i], lPath = lStorage + '/_' + lName.toLowerCase(); @@ -270,7 +270,7 @@ var Util, DOM, CloudFunc, CloudCmd; /* выделяем строку с первым файлом */ var lFmHeader = DOM.getByClass('fm-header'); - if(lFmHeader && lFmHeader[0]){ + if (lFmHeader && lFmHeader[0]) { var lCurrent = lFmHeader[0].nextSibling; DOM.setCurrentFile(lCurrent); } @@ -282,14 +282,14 @@ var Util, DOM, CloudFunc, CloudCmd; CloudCmd.Key(); } - function getSystemFile(pGlobal, pURL){ + function getSystemFile(pGlobal, pURL) { - function lGetSysFile(pCallBack){ - Util.ifExec(pGlobal, pCallBack, function(pCallBack){ - if(!pGlobal) + function lGetSysFile(pCallBack) { + Util.ifExec(pGlobal, pCallBack, function(pCallBack) { + if (!pGlobal) DOM.ajax({ url : pURL, - success : function(pLocal){ + success : function(pLocal) { pGlobal = pLocal; Util.exec(pCallBack, pLocal); } @@ -307,20 +307,20 @@ var Util, DOM, CloudFunc, CloudCmd; CloudCmd.getFileTemplate = getSystemFile(FileTemplate, CloudCmd.HTMLDIR + 'file.html'); CloudCmd.getPathTemplate = getSystemFile(PathTemplate, CloudCmd.HTMLDIR + 'path.html'); - CloudCmd.execFromModule = function(pModuleName, pFuncName, pParams){ + CloudCmd.execFromModule = function(pModuleName, pFuncName, pParams) { var lObject = CloudCmd[pModuleName]; Util.ifExec(Util.isObject(lObject), - function(){ + function() { var lObj = CloudCmd[pModuleName]; Util.exec( lObj[pFuncName], pParams); }, - function(pCallBack){ + function(pCallBack) { Util.exec(lObject, pCallBack); }); }; - CloudCmd.refresh = function(pCurrent){ + CloudCmd.refresh = function(pCurrent) { var lNEEDREFRESH = true, lPanel = pCurrent && pCurrent.parentElement, lPath = DOM.getCurrentDirPath(lPanel), @@ -338,8 +338,8 @@ var Util, DOM, CloudFunc, CloudCmd; * @param pOptions * { refresh, nohistory } - необходимость обновить данные о каталоге */ - CloudCmd.ajaxLoad = function(pPath, pOptions){ - if(!pOptions) + CloudCmd.ajaxLoad = function(pPath, pOptions) { + if (!pOptions) pOptions = {}; /* Отображаем красивые пути */ @@ -350,12 +350,12 @@ var Util, DOM, CloudFunc, CloudCmd; lOldURL = window.location.pathname; - if(lCleanPath === lSLASH) + if (lCleanPath === lSLASH) lNOJSPath = lSLASH; Util.log ('reading dir: "' + lCleanPath + '";'); - if(!pOptions.nohistory) + if (!pOptions.nohistory) DOM.setHistory(lNOJSPath, null, lNOJSPath); DOM.setTitle( CloudFunc.getTitle(lCleanPath) ); @@ -369,10 +369,10 @@ var Util, DOM, CloudFunc, CloudCmd; * перезагружаемся */ var lRet = pOptions.refresh; - if(!lRet){ + if (!lRet) { var lJSON = Cache.get(lCleanPath); - if (lJSON){ + if (lJSON) { lJSON = Util.parseJSON(lJSON); createFileTable(lPanel, lJSON); } @@ -380,17 +380,17 @@ var Util, DOM, CloudFunc, CloudCmd; lRet = true; } - if(lRet) + if (lRet) DOM.getCurrentFileContent({ url : lFSPath, dataType: 'json', - error : function(){ + error : function() { DOM.setHistory(lOldURL, null, lOldURL); }, - success : function(pData){ + success : function(pData) { createFileTable(lPanel, pData); /* переводим таблицу файлов в строку, для * @@ -400,7 +400,7 @@ var Util, DOM, CloudFunc, CloudCmd; /* если размер данных не очень бошьой * * сохраняем их в кэше */ - if(lJSON_s.length < 50000 ) + if (lJSON_s.length < 50000 ) Cache.set(lCleanPath, lJSON_s); } }); @@ -411,7 +411,7 @@ var Util, DOM, CloudFunc, CloudCmd; * @param pEleme - родительский элемент * @param pJSON - данные о файлах */ - function createFileTable(pElem, pJSON){ + function createFileTable(pElem, pJSON) { var lElem = DOM.getById(pElem), /* getting current element if was refresh */ lPath = DOM.getByClass('path', lElem), @@ -438,28 +438,28 @@ var Util, DOM, CloudFunc, CloudCmd; /* если нажали на ссылку на верхний каталог*/ var lFound; /* searching current file */ - if(lWasRefresh_b){ + if (lWasRefresh_b) { var n = lElem.childNodes.length; - for(i = 2; i < n ; i++){ + for(i = 2; i < n ; i++) { var lVarCurrent = lElem.childNodes[i], lVarName = DOM.getCurrentName(lVarCurrent); lFound = lVarName === lName; - if(lFound){ + if (lFound) { lCurrent = lElem.childNodes[i]; break; } } } - if(!lFound) /* .. */ + if (!lFound) /* .. */ lCurrent = lElem.childNodes[2]; DOM.setCurrentFile(lCurrent); Listeners.changeLinks(pElem); - if(lName === '..' && lDir !== '/') + if (lName === '..' && lDir !== '/') currentToParent(lDir); }); } @@ -468,7 +468,7 @@ var Util, DOM, CloudFunc, CloudCmd; * Функция генерирует JSON из html-таблицы файлов и * используеться при первом заходе в корень */ - function getJSONfromFileTable(){ + function getJSONfromFileTable() { var lLeft = DOM.getById('left'), lPath = DOM.getByClass('path')[0].textContent, @@ -487,7 +487,7 @@ var Util, DOM, CloudFunc, CloudCmd; */ /* пропускам Path и Header*/ - for(i = 2, n = lLI.length; i < n; i++){ + for(i = 2, n = lLI.length; i < n; i++) { var lCurrent = lLI[i], lName = DOM.getCurrentName(lCurrent), lSize = DOM.getCurrentSize(lCurrent), @@ -495,7 +495,7 @@ var Util, DOM, CloudFunc, CloudCmd; lMode = DOM.getCurrentMode(lCurrent); lMode = CloudFunc.getNumericPermissions(lMode); - if(lName !== '..') + if (lName !== '..') lFileTable[ j++ ] = { name: lName, size: lSize, diff --git a/lib/server/main.js b/lib/server/main.js index 442df33a..4308fda6 100644 --- a/lib/server/main.js +++ b/lib/server/main.js @@ -1,4 +1,4 @@ -(function(){ +(function() { 'use strict'; /* Global var accessible from any loaded module */ @@ -121,13 +121,13 @@ * function do safe require of needed module * @param {Strin} pSrc */ - function mrequire(pSrc){ + function mrequire(pSrc) { var lModule, msg, lError = Util.tryCatch(function() { lModule = require(pSrc); }); - if(lError) + if (lError) msg = CloudFunc.formatMsg('require', pSrc, 'error'); Util.log(msg); @@ -135,37 +135,37 @@ return lModule; } - function quietrequire(pSrc){ + function quietrequire(pSrc) { var lModule; - Util.tryCatch(function(){ + Util.tryCatch(function() { lModule = require(pSrc); }); return lModule; } - function rootrequire(pSrc){ return mrequire(DIR + pSrc); } + function rootrequire(pSrc) { return mrequire(DIR + pSrc); } - function librequire(pSrc){ return mrequire(LIBDIR + pSrc); } + function librequire(pSrc) { return mrequire(LIBDIR + pSrc); } - function srvrequire(pSrc){ return mrequire(SRVDIR + pSrc); } + function srvrequire(pSrc) { return mrequire(SRVDIR + pSrc); } - function jsonrequire(pSrc){ return mrequire(JSONDIR + pSrc);} + function jsonrequire(pSrc) { return mrequire(JSONDIR + pSrc);} /** * function check is current platform is win32 */ - function isWin32(){ return process.platform === 'win32'; } + function isWin32() { return process.platform === 'win32'; } /** * get volumes if win32 or get nothing if nix */ - function getVolumes(){ + function getVolumes() { var lRet = ISWIN32 ? [] : '/'; - if(ISWIN32) - srvrequire('win').getVolumes(function(pVolumes){ + if (ISWIN32) + srvrequire('win').getVolumes(function(pVolumes) { console.log(pVolumes); exports.VOLUMES = pVolumes; }); @@ -183,20 +183,20 @@ * query * https://developers.google.com/speed/docs/best-practices/caching?hl=ru#LeverageProxyCaching */ - function generateHeaders(pParams){ + function generateHeaders(pParams) { var lRet = Util.checkObjTrue(pParams, ['name']); - if(lRet){ + if (lRet) { var p = pParams, lExt = Util.getExtension(p.name), lType = ext[lExt] || 'text/plain', lContentEncoding = ''; /* if type of file any, but img - then we shoud specify charset */ - if( !Util.isContainStr(lType, 'img') ) + if ( !Util.isContainStr(lType, 'img') ) lContentEncoding = '; charset=UTF-8'; - if( Util.isContainStr(p.query, 'download') ) + if ( Util.isContainStr(p.query, 'download') ) lType = 'application/octet-stream'; lRet = { @@ -206,10 +206,10 @@ 'Vary' : 'Accept-Encoding' }; - if( !Util.strCmp(lExt, '.appcache') && p.cache) + if (!Util.strCmp(lExt, '.appcache') && p.cache) lRet['cache-control'] = 'max-age=' + 31337 * 21; - if(p.gzip) + if (p.gzip) lRet['content-encoding'] = 'gzip'; } @@ -223,7 +223,7 @@ * @param pName - имя файла * @param pGzip - данные сжаты gzip'ом */ - function sendFile(pParams){ + function sendFile(pParams) { var lRet = checkParams(pParams); if (lRet) { var p = pParams, @@ -263,7 +263,7 @@ function sendResponse(pParams, pData, pNotLog) { var lRet = checkParams(pParams); - if(lRet){ + if (lRet) { var p = pParams, lQuery = getQuery(p.request), /* download, json */ @@ -283,7 +283,7 @@ function(pParams) { var lRet = Util.checkObj(pParams, ['data']); - if(lRet) { + if (lRet) { p.status = pParams.status || p.status; p.data = pParams.data; } @@ -304,11 +304,11 @@ /** * redirect to another URL */ - function redirect(pParams){ + function redirect(pParams) { var lRet = Util.checkObjTrue(pParams, [RESPONSE]); - if(lRet){ + if (lRet) { var p = pParams; p.response.writeHead(MOVED_PERMANENTLY, {'Location': p.url}); @@ -339,18 +339,18 @@ * @param pHeader - заголовок файла * @pName */ - function gzipData(pParams){ + function gzipData(pParams) { var lRet = checkCallBackParams(pParams), p = pParams; - if(lRet) + if (lRet) lRet = Util.checkObj(pParams.params, ['callback']); - if(lRet){ + if (lRet) { var lCallBack = p.params.callback, lParams = {}; - if(!p.error) + if (!p.error) lParams.data = p.data; else{ lParams.status = FILE_NOT_FOUND; @@ -362,27 +362,27 @@ } - function checkCallBackParams(pParams){ + function checkCallBackParams(pParams) { return Util.checkObj(pParams, ['error', 'data', 'params']); } - function readFiles(pFiles, pCallBack){ + function readFiles(pFiles, pCallBack) { var lDone = [], lFiles, lErrors, lReadedFiles = {}, - lDoneFunc = function (pParams){ + lDoneFunc = function (pParams) { var msg, status, lRet = Util.checkObj(pParams, ['error', 'data', 'params']); - if(lRet){ + if (lRet) { lDone.pop(); var p = pParams, lName = p.params; - if(p.error){ + if (p.error) { status = 'error'; - if(!lErrors) lErrors = {}; + if (!lErrors) lErrors = {}; lErrors[lName] = p.error; } @@ -396,12 +396,12 @@ Util.log(msg); - if( !lDone.length ) + if ( !lDone.length ) Util.exec(pCallBack, lErrors, lReadedFiles); } }; - if( Util.isArray(pFiles) ) + if ( Util.isArray(pFiles) ) lFiles = pFiles; else lFiles = [pFiles]; @@ -414,7 +414,7 @@ } } - function checkParams(pParams, pAdditional){ + function checkParams(pParams, pAdditional) { var lRet = Util.checkObjTrue( pParams, ['name', REQUEST, RESPONSE] ); if (lRet && pAdditional) @@ -423,7 +423,7 @@ return lRet; } - function getQuery(pReq){ + function getQuery(pReq) { var lQuery, lParsedUrl; if (pReq) { @@ -434,7 +434,7 @@ return lQuery; } - function isGZIP(pReq){ + function isGZIP(pReq) { var lEnc, lGZIP; if (pReq) { lEnc = pReq.headers['accept-encoding'] || ''; diff --git a/lib/util.js b/lib/util.js index a07af434..c360c2ba 100644 --- a/lib/util.js +++ b/lib/util.js @@ -30,7 +30,7 @@ Util = exports || {}; } function callCheckFunc(pNum, pFunc) { - Util.exec(pFunc, function(pData){ + Util.exec(pFunc, function(pData) { checkFunc(pNum, pData); }); }