mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-19 01:17:18 +00:00
refactored
This commit is contained in:
parent
a5375d126a
commit
a7c4c5b36f
2 changed files with 52 additions and 58 deletions
|
|
@ -79,64 +79,58 @@
|
|||
* @param pFiles
|
||||
*/
|
||||
function readDir(pParams){
|
||||
var lRet,
|
||||
lError, lFiles, lHTTP, lDirPath,
|
||||
lReq, lRes;
|
||||
|
||||
if(pParams){
|
||||
lError = pParams.error;
|
||||
lFiles = pParams.data;
|
||||
lHTTP = pParams.params;
|
||||
|
||||
if(lHTTP){
|
||||
lReq = lHTTP.request,
|
||||
lRes = lHTTP.response;
|
||||
lRet = true;
|
||||
lDirPath = getDirPath(lReq);
|
||||
}
|
||||
}
|
||||
|
||||
if(lRet && !lError && lFiles){
|
||||
lFiles = lFiles.sort();
|
||||
|
||||
/* Получаем информацию о файлах */
|
||||
var n = lFiles.length,
|
||||
lStats = {},
|
||||
lFilesData = {
|
||||
files : lFiles,
|
||||
stats : lStats,
|
||||
request : lReq,
|
||||
response : lRes
|
||||
},
|
||||
var lRet = Util.checkObj(pParams,
|
||||
['error', 'data', 'params']) &&
|
||||
|
||||
lFill = function(){
|
||||
fillJSON(lFilesData);
|
||||
};
|
||||
|
||||
if(n){
|
||||
for(var i = 0; i < n; i++){
|
||||
var lName = lDirPath + lFiles[i],
|
||||
lParams = {
|
||||
callback : lFill,
|
||||
count : n,
|
||||
name : lFiles[i],
|
||||
stats : lStats,
|
||||
};
|
||||
Util.checkObjTrue(pParams.params,
|
||||
[REQUEST, RESPONSE]);
|
||||
if(lRet){
|
||||
var p = pParams,
|
||||
c = p.params,
|
||||
lDirPath = getDirPath(c.request);
|
||||
|
||||
if(!p.error && p.data){
|
||||
p.data = p.data.sort();
|
||||
|
||||
/* Получаем информацию о файлах */
|
||||
var n = p.data.length,
|
||||
lStats = {},
|
||||
lFilesData = {
|
||||
files : p.data,
|
||||
stats : lStats,
|
||||
request : c.request,
|
||||
response : c.response
|
||||
},
|
||||
|
||||
fs.stat( lName, Util.call(getFilesStat, lParams) );
|
||||
lFill = function(){
|
||||
fillJSON(lFilesData);
|
||||
};
|
||||
|
||||
if(n){
|
||||
for(var i = 0; i < n; i++){
|
||||
var lName = lDirPath + p.data[i],
|
||||
lParams = {
|
||||
callback : lFill,
|
||||
count : n,
|
||||
name : p.data[i],
|
||||
stats : lStats,
|
||||
};
|
||||
|
||||
fs.stat( lName, Util.call(getFilesStat, lParams) );
|
||||
}
|
||||
}
|
||||
else
|
||||
fillJSON(lFilesData);
|
||||
}
|
||||
else
|
||||
fillJSON(lFilesData);
|
||||
sendResponse({
|
||||
data : p.Error.toString(),
|
||||
name : lDirPath,
|
||||
request : c.request,
|
||||
response: c.response,
|
||||
status : FILE_NOT_FOUND
|
||||
});
|
||||
}
|
||||
else
|
||||
sendResponse({
|
||||
data : lError.toString(),
|
||||
name : lDirPath,
|
||||
request : lReq,
|
||||
response: lRes,
|
||||
status : FILE_NOT_FOUND
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -150,6 +150,9 @@
|
|||
|
||||
lType = ext[lExt] || 'text/plain';
|
||||
|
||||
/* if type of file any, but img -
|
||||
* then we shoud specify charset
|
||||
*/
|
||||
if( !Util.isContainStr(lType, 'img') )
|
||||
lContentEncoding = '; charset=UTF-8';
|
||||
|
||||
|
|
@ -159,16 +162,13 @@
|
|||
|
||||
if(!lCacheControl)
|
||||
lCacheControl = 31337 * 21;
|
||||
|
||||
|
||||
lRet = {
|
||||
/* if type of file any, but img -
|
||||
* then we shoud specify charset
|
||||
*/
|
||||
'Content-Type': lType + lContentEncoding,
|
||||
'cache-control': 'max-age=' + lCacheControl,
|
||||
'last-modified': new Date().toString(),
|
||||
'last-modified': new Date().toString(),
|
||||
/* https://developers.google.com/speed/docs/best-practices
|
||||
/caching?hl=ru#LeverageProxyCaching */
|
||||
/caching?hl=ru#LeverageProxyCaching */
|
||||
'Vary': 'Accept-Encoding'
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue