mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-19 09:24:51 +00:00
refactored
This commit is contained in:
parent
0d156f28fa
commit
c88e446c24
4 changed files with 169 additions and 81 deletions
|
|
@ -3,31 +3,36 @@ var CloudFunc, exports;
|
|||
(function(){
|
||||
"use strict";
|
||||
|
||||
/** Модуль, содержащий функции, которые будут работать
|
||||
* и на клиенте и на сервере
|
||||
/**
|
||||
* Модуль, содержащий функции, которые
|
||||
* будут работать и на клиенте и на сервере
|
||||
*/
|
||||
|
||||
CloudFunc = {
|
||||
/* Путь с которым мы сейчас работаем */
|
||||
Path : '',
|
||||
/* КОНСТАНТЫ (общие для клиента и сервера)*/
|
||||
/* название программы */
|
||||
NAME : 'Cloud Commander',
|
||||
/* если в ссылке будет эта строка -
|
||||
* в браузере js отключен
|
||||
*/
|
||||
NOJS : '/no-js',
|
||||
FS : '/fs',
|
||||
/* название css-класа кнопки обновления файловой структуры*/
|
||||
REFRESHICON : 'refresh-icon',
|
||||
/* id панелей с файлами */
|
||||
LEFTPANEL : 'left',
|
||||
RIGHTPANEL : 'right',
|
||||
/* length of longest
|
||||
* file name
|
||||
*/
|
||||
SHORTNAMELENGTH : 16
|
||||
};
|
||||
CloudFunc = exports || {};
|
||||
|
||||
/* Путь с которым мы сейчас работаем */
|
||||
CloudFunc.Path = '';
|
||||
|
||||
/* КОНСТАНТЫ (общие для клиента и сервера)*/
|
||||
|
||||
/* название программы */
|
||||
CloudFunc.NAME = 'Cloud Commander';
|
||||
|
||||
/* если в ссылке будет эта строка - в браузере js отключен */
|
||||
CloudFunc.NOJS = '/no-js';
|
||||
CloudFunc.FS = '/fs';
|
||||
|
||||
/* название css-класа кнопки обновления файловой структуры*/
|
||||
CloudFunc.REFRESHICON = 'refresh-icon';
|
||||
|
||||
/* id панелей с файлами */
|
||||
CloudFunc.LEFTPANEL = 'left';
|
||||
CloudFunc.RIGHTPANEL = 'right';
|
||||
|
||||
/* length of longest
|
||||
* file name
|
||||
*/
|
||||
CloudFunc.SHORTNAMELENGTH = 16;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -483,21 +488,4 @@ var CloudFunc, exports;
|
|||
|
||||
return lFileTable;
|
||||
};
|
||||
|
||||
/*
|
||||
* Если мы на стороне сервера -
|
||||
* прописываем экспортируемые функции
|
||||
*/
|
||||
if(exports){
|
||||
/* экспортируемые функции */
|
||||
exports.checkExtension = CloudFunc.checkExtension;
|
||||
exports.buildFromJSON = CloudFunc.buildFromJSON;
|
||||
exports.setTitle = CloudFunc.setTitle;
|
||||
exports.getUserUIDsAndNames = CloudFunc.getUserUIDsAndNames;
|
||||
|
||||
/* константы*/
|
||||
exports.Name = CloudFunc.NAME;
|
||||
exports.NOJS = CloudFunc.NOJS;
|
||||
exports.FS = CloudFunc.FS;
|
||||
}
|
||||
})();
|
||||
|
|
@ -1,42 +1,25 @@
|
|||
"strict mode";
|
||||
/**
|
||||
* function do save exec
|
||||
*/
|
||||
exports.exec = function(pCallBackk){
|
||||
if( typeof pCallBackk === 'function')
|
||||
pCallBackk();
|
||||
else console.log('error in ' + pCallBackk);
|
||||
};
|
||||
|
||||
/**
|
||||
* function do safe require of needed module
|
||||
* @param pModule
|
||||
*/
|
||||
exports.require = function(pSrc){
|
||||
var lModule,
|
||||
(function(){
|
||||
"strict mode";
|
||||
|
||||
lError = exports.tryCatch(function(){
|
||||
lModule = require(pSrc);
|
||||
});
|
||||
var DIR = process.cwd() + '/',
|
||||
LIBDIR = DIR + 'lib/',
|
||||
SRVDIR = LIBDIR + 'server/',
|
||||
Util = require(LIBDIR + 'util');
|
||||
|
||||
if(lError)
|
||||
console.log(lError);
|
||||
|
||||
return lModule;
|
||||
};
|
||||
|
||||
/**
|
||||
* function execute param function in
|
||||
* try...catch block
|
||||
*
|
||||
* @param pCallBack
|
||||
*/
|
||||
exports.tryCatch = function(pCallBack){
|
||||
var lRet;
|
||||
try{
|
||||
pCallBack();
|
||||
}
|
||||
catch(pError){lRet = pError;}
|
||||
|
||||
return lRet;
|
||||
};
|
||||
/**
|
||||
* function do safe require of needed module
|
||||
* @param pModule
|
||||
*/
|
||||
exports.require = function srvrequire(pSrc){
|
||||
var lModule,
|
||||
|
||||
lError = Util.tryCatch(function(){
|
||||
lModule = require(pSrc);
|
||||
});
|
||||
|
||||
if(lError)
|
||||
console.log(lError);
|
||||
|
||||
return lModule;
|
||||
};
|
||||
}());
|
||||
115
lib/util.js
Normal file
115
lib/util.js
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
var Util, exports;
|
||||
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
Util = exports || {};
|
||||
|
||||
/* STRINGS */
|
||||
/**
|
||||
* function check is strings are equal
|
||||
* @param pStr1
|
||||
* @param pStr2
|
||||
*/
|
||||
Util.strCmp = function (pStr1, pStr2){
|
||||
return this.isContainStr(pStr1, pStr2) &&
|
||||
pStr1.length == pStr2.length;
|
||||
};
|
||||
|
||||
/**
|
||||
* function returns is pStr1 contains pStr2
|
||||
* @param pStr1
|
||||
* @param pStr2
|
||||
*/
|
||||
|
||||
Util.isContainStr = function(pStr1, pStr2){
|
||||
return pStr1 &&
|
||||
pStr2 &&
|
||||
pStr1.indexOf(pStr2) >= 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* function remove substring from string
|
||||
* @param pStr
|
||||
* @param pSubStr
|
||||
*/
|
||||
Util.removeStr = function(pStr, pSubStr){
|
||||
return pStr.replace(pSubStr,'');
|
||||
};
|
||||
|
||||
/**
|
||||
* functions check is pVarible is array
|
||||
* @param pVarible
|
||||
*/
|
||||
Util.isArray = function(pVarible){
|
||||
return pVarible instanceof Array;
|
||||
};
|
||||
|
||||
/**
|
||||
* functions check is pVarible is boolean
|
||||
* @param pVarible
|
||||
*/
|
||||
Util.isBoolean = function(pVarible){
|
||||
return Util.isType(pVarible, 'boolean');
|
||||
};
|
||||
|
||||
/**
|
||||
* functions check is pVarible is object
|
||||
* @param pVarible
|
||||
*/
|
||||
Util.isObject = function(pVarible){
|
||||
return Util.isType(pVarible, 'object');
|
||||
};
|
||||
/**
|
||||
* functions check is pVarible is string
|
||||
* @param pVarible
|
||||
*/
|
||||
Util.isString = function(pVarible){
|
||||
return Util.isType(pVarible, 'string');
|
||||
};
|
||||
/**
|
||||
* functions check is pVarible is function
|
||||
* @param pVarible
|
||||
*/
|
||||
Util.isFunction = function(pVarible){
|
||||
return Util.isType(pVarible, 'function');
|
||||
};
|
||||
/**
|
||||
* functions check is pVarible is pType
|
||||
* @param pVarible
|
||||
* @param pType
|
||||
*/
|
||||
Util.isType = function(pVarible, pType){
|
||||
return typeof pVarible === pType;
|
||||
};
|
||||
|
||||
/**
|
||||
* function execute param function in
|
||||
* try...catch block
|
||||
*
|
||||
* @param pCallBack
|
||||
*/
|
||||
Util.tryCatch = function(pCallBack){
|
||||
var lRet;
|
||||
try{
|
||||
pCallBack();
|
||||
}
|
||||
catch(pError){lRet = pError;}
|
||||
|
||||
return lRet;
|
||||
};
|
||||
|
||||
/**
|
||||
* function do save exec
|
||||
*/
|
||||
Util.exec = function(pCallBackk){
|
||||
var lRet = false;
|
||||
|
||||
if( typeof pCallBackk === 'function')
|
||||
lRet = pCallBackk();
|
||||
else
|
||||
console.log('error in ' + pCallBackk);
|
||||
|
||||
return lRet;
|
||||
};
|
||||
}());
|
||||
|
|
@ -677,7 +677,9 @@ CloudServer.indexReaded = function(pList){
|
|||
|
||||
pIndex = pIndex.toString();
|
||||
|
||||
pIndex = CloudServer.indexProcessing(pIndex, pList);
|
||||
|
||||
if(typeof CloudServer.indexProcessing === 'function')
|
||||
pIndex = CloudServer.indexProcessing(pIndex, pList);
|
||||
/*
|
||||
* если браузер поддерживает gzip-сжатие
|
||||
* высылаем заголовок в зависимости от типа файла
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue