mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-25 08:54:10 +00:00
refactored
This commit is contained in:
parent
9c728bd749
commit
dd8481f2a4
4 changed files with 64 additions and 72 deletions
|
|
@ -185,28 +185,34 @@
|
|||
*/
|
||||
function sendFile(pParams){
|
||||
var lRet,
|
||||
lName, lReq, lRes;
|
||||
|
||||
if(pParams){
|
||||
lName = pParams.name,
|
||||
lReq = pParams.request,
|
||||
lRes = pParams.response,
|
||||
|
||||
lEnc = lReq.headers['accept-encoding'] || '',
|
||||
lGzip = lEnc.match(/\bgzip\b/),
|
||||
lRes = pParams.response;
|
||||
}
|
||||
|
||||
if(lName && lRes && lReq){
|
||||
var lEnc = lReq.headers['accept-encoding'] || '',
|
||||
lGzip = lEnc.match(/\bgzip\b/),
|
||||
|
||||
lReadStream = fs.createReadStream(lName, {
|
||||
'bufferSize': 4 * 1024
|
||||
});
|
||||
|
||||
lReadStream = fs.createReadStream(lName, {
|
||||
'bufferSize': 4 * 1024
|
||||
});
|
||||
|
||||
lReadStream.on('error', function(pError){
|
||||
lRes.writeHead(ERROR, 'OK');
|
||||
lRes.end(String(pError));
|
||||
});
|
||||
|
||||
lRes.writeHead(OK, generateHeaders(lName, lGzip) );
|
||||
|
||||
if (lGzip)
|
||||
lReadStream = lReadStream.pipe( zlib.createGzip() );
|
||||
|
||||
lReadStream.pipe(lRes);
|
||||
lReadStream.on('error', function(pError){
|
||||
lRes.writeHead(ERROR, 'OK');
|
||||
lRes.end(String(pError));
|
||||
});
|
||||
|
||||
lRes.writeHead(OK, generateHeaders(lName, lGzip) );
|
||||
|
||||
if (lGzip)
|
||||
lReadStream = lReadStream.pipe( zlib.createGzip() );
|
||||
|
||||
lReadStream.pipe(lRes);
|
||||
}
|
||||
|
||||
return lRet;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,22 +54,11 @@
|
|||
|
||||
if(this._allowed.css || this._allowed.js || this._allowed.html){
|
||||
main.srvrequire("ischanged").isFileChanged(pName, false, function(pChanged){
|
||||
if(pChanged){
|
||||
if(pChanged)
|
||||
Minify.optimize(pName, pParams);
|
||||
}else{
|
||||
var lDot = pName.lastIndexOf('.'),
|
||||
lExt = pName.substr(lDot);
|
||||
|
||||
pName = Minify.MinFolder + main.crypto.createHash('sha1')
|
||||
.update(pName)
|
||||
.digest('hex') + lExt;
|
||||
|
||||
console.log(pName);
|
||||
|
||||
pParams.callback = null;
|
||||
pParams.name = pName;
|
||||
if(pParams.request && pParams.response)
|
||||
main.sendFile(pParams);
|
||||
else{
|
||||
pParams.name = Minify.getName(pName);
|
||||
main.sendFile(pParams);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -92,6 +81,8 @@
|
|||
},
|
||||
|
||||
/* minification folder name */
|
||||
MinFolder : ''
|
||||
MinFolder : '',
|
||||
getName : Minify ? Minify.getName : Util.retFalse
|
||||
};
|
||||
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue