mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-18 00:47:01 +00:00
minor changes
This commit is contained in:
parent
625eac0133
commit
1d7d4176c8
3 changed files with 73 additions and 64 deletions
|
|
@ -219,9 +219,10 @@
|
|||
'<ul id=right class=panel>' + lPanel + '</ul>';
|
||||
|
||||
fs.readFile(INDEX, Util.call(readFile, {
|
||||
list : lList,
|
||||
request : lReq,
|
||||
response : lRes
|
||||
name : getCleanPath(lReq),
|
||||
list : lList,
|
||||
request : lReq,
|
||||
response : lRes
|
||||
})
|
||||
);
|
||||
|
||||
|
|
@ -257,7 +258,7 @@
|
|||
if(lRet)
|
||||
lRet = Util.checkObjTrue(pParams.params,
|
||||
[REQUEST, RESPONSE, 'list']);
|
||||
|
||||
|
||||
if(lRet){
|
||||
var p = pParams,
|
||||
c = pParams.params;
|
||||
|
|
@ -303,12 +304,15 @@
|
|||
if(lRet){
|
||||
var p = pParams;
|
||||
|
||||
var lPath = p.name || getCleanPath(p.request),
|
||||
lQuery = main.getQuery(p.request),
|
||||
var lQuery = main.getQuery(p.request),
|
||||
/* download, json */
|
||||
lGzip = isGZIP(p.request),
|
||||
lHead = main.generateHeaders(lPath, lGzip, lQuery);
|
||||
|
||||
lGzip = main.isGZIP(p.request),
|
||||
lHead = main.generateHeaders({
|
||||
name : p.name,
|
||||
gzip : lGzip,
|
||||
query : lQuery
|
||||
});
|
||||
|
||||
/* если браузер поддерживает gzip-сжатие - сжимаем данные*/
|
||||
Util.ifExec(!lGzip,
|
||||
function(pParams){
|
||||
|
|
@ -322,7 +326,7 @@
|
|||
p.response.writeHead(p.status || OK, lHead);
|
||||
p.response.end(p.data);
|
||||
|
||||
Util.log(lPath + ' sended');
|
||||
Util.log( p.name + ' sended');
|
||||
Util.log( p.status === FILE_NOT_FOUND && p.data );
|
||||
},
|
||||
|
||||
|
|
@ -392,15 +396,4 @@
|
|||
return lRet;
|
||||
}
|
||||
|
||||
|
||||
function isGZIP(pReq){
|
||||
var lEnc, lGZIP;
|
||||
if(pReq){
|
||||
lEnc = pReq.headers['accept-encoding'] || '',
|
||||
lGZIP = lEnc.match(/\bgzip\b/);
|
||||
}
|
||||
|
||||
return lGZIP;
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
@ -49,6 +49,7 @@
|
|||
exports.rootrequire = rootrequire,
|
||||
exports.generateHeaders = generateHeaders,
|
||||
exports.getQuery = getQuery,
|
||||
exports.isGZIP = isGZIP,
|
||||
exports.sendFile = sendFile,
|
||||
|
||||
/* compitability with old versions of node */
|
||||
|
|
@ -150,47 +151,49 @@
|
|||
* Функция создаёт заголовки файлов
|
||||
* в зависимости от расширения файла
|
||||
* перед отправкой их клиенту
|
||||
* @param pName - имя файла
|
||||
* @param pGzip - данные сжаты gzip'ом
|
||||
* @param pParams
|
||||
* name - имя файла
|
||||
* gzip - данные сжаты gzip'ом
|
||||
* query
|
||||
* cacheControl
|
||||
* https://developers.google.com/speed/docs/best-practices/caching?hl=ru#LeverageProxyCaching
|
||||
*/
|
||||
function generateHeaders(pName, pGzip, pQuery){
|
||||
var lRet,
|
||||
lType = '',
|
||||
lContentEncoding = '',
|
||||
lCacheControl = 0,
|
||||
function generateHeaders(pParams){
|
||||
var lRet = Util.checkObjTrue(pParams, 'name'),
|
||||
p = pParams;
|
||||
Util.log(pParams);
|
||||
if(lRet){
|
||||
var lExt = Util.getExtension(p.name),
|
||||
lType = ext[lExt] || 'text/plain',
|
||||
lContentEncoding = '';
|
||||
|
||||
lExt = Util.getExtension(pName);
|
||||
|
||||
if( Util.strCmp(lExt, '.appcache') )
|
||||
lCacheControl = 1;
|
||||
|
||||
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';
|
||||
|
||||
if(Util.strCmp(pQuery, 'download') )
|
||||
lType = 'application/octet-stream';
|
||||
|
||||
|
||||
if(!lCacheControl)
|
||||
lCacheControl = 31337 * 21;
|
||||
|
||||
lRet = {
|
||||
'Content-Type': lType + lContentEncoding,
|
||||
'cache-control': 'max-age=' + lCacheControl,
|
||||
'last-modified': new Date().toString(),
|
||||
/* https://developers.google.com/speed/docs/best-practices
|
||||
/caching?hl=ru#LeverageProxyCaching */
|
||||
'Vary': 'Accept-Encoding'
|
||||
};
|
||||
|
||||
if(pGzip)
|
||||
lRet['content-encoding'] = 'gzip';
|
||||
if( !Util.checkObjTrue(pParams, 'cacheControl') )
|
||||
p.cacheControl = 1;
|
||||
|
||||
/* if type of file any, but img - then we shoud specify charset */
|
||||
if( !Util.isContainStr(lType, 'img') )
|
||||
lContentEncoding = '; charset=UTF-8';
|
||||
|
||||
if( Util.strCmp(p.query, 'download') )
|
||||
lType = 'application/octet-stream';
|
||||
|
||||
|
||||
if( !Util.strCmp(lExt, '.appcache') )
|
||||
p.cacheControl = 31337 * 21;
|
||||
|
||||
lRet = {
|
||||
'Content-Type': lType + lContentEncoding,
|
||||
'last-modified': new Date().toString(),
|
||||
'Vary': 'Accept-Encoding'
|
||||
};
|
||||
|
||||
if(p.cacheControl)
|
||||
lRet['cache-control'] = 'max-age=' + p.cacheControl;
|
||||
|
||||
if(p.gzip)
|
||||
lRet['content-encoding'] = 'gzip';
|
||||
}
|
||||
|
||||
return lRet;
|
||||
}
|
||||
|
||||
|
|
@ -203,19 +206,17 @@
|
|||
*/
|
||||
function sendFile(pParams){
|
||||
var lRet,
|
||||
lName, lReq, lRes, lQuery, lGziped;
|
||||
lName, lReq, lRes, lGziped;
|
||||
|
||||
if(pParams){
|
||||
lName = pParams.name,
|
||||
lReq = pParams.request,
|
||||
lRes = pParams.response;
|
||||
lGziped = pParams.gziped;
|
||||
lQuery = getQuery(lReq);
|
||||
}
|
||||
|
||||
if(lName && lRes && lReq){
|
||||
var lEnc = lReq.headers['accept-encoding'] || '',
|
||||
lGzip = lEnc.match(/\bgzip\b/),
|
||||
var lGzip = isGZIP(lReq),
|
||||
|
||||
lReadStream = fs.createReadStream(lName, {
|
||||
'bufferSize': 4 * 1024
|
||||
|
|
@ -226,7 +227,11 @@
|
|||
lRes.end(String(pError));
|
||||
});
|
||||
|
||||
lRes.writeHead(OK, generateHeaders(lName, lGzip, lQuery ) );
|
||||
lRes.writeHead(OK, generateHeaders({
|
||||
name : lName,
|
||||
gzip : lGzip,
|
||||
query : getQuery(lReq)
|
||||
}) );
|
||||
|
||||
if (lGzip && !lGziped)
|
||||
lReadStream = lReadStream.pipe( zlib.createGzip() );
|
||||
|
|
@ -250,6 +255,16 @@
|
|||
return lQuery;
|
||||
}
|
||||
|
||||
function isGZIP(pReq){
|
||||
var lEnc, lGZIP;
|
||||
if(pReq){
|
||||
lEnc = pReq.headers['accept-encoding'] || '';
|
||||
lGZIP = lEnc.match(/\bgzip\b/);
|
||||
}
|
||||
|
||||
return lGZIP;
|
||||
}
|
||||
|
||||
|
||||
function linuxWatch(pFile, pCallBack){
|
||||
fs.watchFile(pFile, function(pCurr, pPrev){
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
cd ..
|
||||
echo 'appfog'
|
||||
af update
|
||||
echo 'http://cloudcmd.aws.af.cm/'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue