mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-20 18:18:56 +00:00
feature(join) mv from server
This commit is contained in:
parent
d5c1366e35
commit
0b3b0df132
2 changed files with 90 additions and 67 deletions
|
|
@ -25,6 +25,7 @@
|
|||
Socket = main.socket,
|
||||
Console = main.console,
|
||||
Terminal = main.terminal,
|
||||
join = main.srvrequire('join'),
|
||||
|
||||
zlib = main.zlib,
|
||||
http = main.http,
|
||||
|
|
@ -35,6 +36,8 @@
|
|||
files = main.files,
|
||||
|
||||
Server, Rest, Route;
|
||||
|
||||
join = join && Util.bind(join, beforeJoin, DIR) || Util.exec.bind(Util);
|
||||
|
||||
/* базовая инициализация */
|
||||
function init(pAppCachProcessing) {
|
||||
|
|
@ -238,70 +241,15 @@
|
|||
});
|
||||
}
|
||||
|
||||
function join(request, response, callback) {
|
||||
var names, i, n, name, minName, stream, check,
|
||||
funcs = [],
|
||||
config = main.config,
|
||||
dir = DIR,
|
||||
gzip = zlib.createGzip(),
|
||||
isGzip = main.isGZIP(request),
|
||||
path = main.getPathName(request),
|
||||
|
||||
isJoin = CloudFunc.isJoinURL(path),
|
||||
readPipe = function() {
|
||||
main.mainSetHeader({
|
||||
name : names[0],
|
||||
cache : config.cache,
|
||||
gzip : isGzip,
|
||||
request : request,
|
||||
response : response
|
||||
});
|
||||
|
||||
if (!isGzip)
|
||||
stream = response;
|
||||
else
|
||||
stream = gzip;
|
||||
|
||||
files.readPipe({
|
||||
names : names,
|
||||
dir : dir,
|
||||
write : stream,
|
||||
callback : function(error) {
|
||||
var errorStr;
|
||||
|
||||
if (error)
|
||||
if (!response.headersSent)
|
||||
main.sendError({
|
||||
request : request,
|
||||
response : response,
|
||||
name : path
|
||||
}, error);
|
||||
else {
|
||||
Util.log(error);
|
||||
errorStr = error.toString();
|
||||
stream.end(errorStr);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* pipe should be setted up after
|
||||
* readPipe called with stream param
|
||||
*/
|
||||
if (isGzip)
|
||||
gzip.pipe(response);
|
||||
};
|
||||
|
||||
if (!isJoin)
|
||||
Util.exec(callback);
|
||||
else {
|
||||
names = CloudFunc.getJoinArray(path);
|
||||
function beforeJoin(names, callback) {
|
||||
var i, name, check, minName, dir, funcs,
|
||||
config = main.config,
|
||||
n = names.length;
|
||||
|
||||
if (!config.minify)
|
||||
readPipe();
|
||||
else {
|
||||
for (i = 0; i < n; i++) {
|
||||
if (!config.minify)
|
||||
Util.exec(callback);
|
||||
else {
|
||||
for (i = 0; i < n; i++) {
|
||||
name = Path.join(DIR, names[i]);
|
||||
check = checkExtension(name);
|
||||
|
||||
|
|
@ -314,14 +262,11 @@
|
|||
}
|
||||
}
|
||||
|
||||
funcs.push(minify.bind(null, name));
|
||||
funcs.push(Util.bind(minify, name));
|
||||
}
|
||||
|
||||
Util.asyncCall(funcs, readPipe);
|
||||
}
|
||||
Util.asyncCall(funcs, callback);
|
||||
}
|
||||
|
||||
return isJoin;
|
||||
}
|
||||
|
||||
function checkExtension(name) {
|
||||
|
|
|
|||
78
lib/server/join.js
Normal file
78
lib/server/join.js
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
(function() {
|
||||
|
||||
var main = global.cloudcmd.main,
|
||||
files = main.files,
|
||||
Util = main.util,
|
||||
CloudFunc = main.cloudfunc,
|
||||
minify = main.minify,
|
||||
zlib = require('zlib');
|
||||
|
||||
module.exports = join;
|
||||
|
||||
function join(before, dir, request, response, callback) {
|
||||
var names, i, n, name, minName, stream, check,
|
||||
funcs = [],
|
||||
config = main.config,
|
||||
gzip = zlib.createGzip(),
|
||||
isGzip = main.isGZIP(request),
|
||||
path = main.getPathName(request),
|
||||
|
||||
isJoin = CloudFunc.isJoinURL(path),
|
||||
readPipe = function() {
|
||||
main.mainSetHeader({
|
||||
name : names[0],
|
||||
cache : config.cache,
|
||||
gzip : isGzip,
|
||||
request : request,
|
||||
response : response
|
||||
});
|
||||
|
||||
if (!isGzip)
|
||||
stream = response;
|
||||
else
|
||||
stream = gzip;
|
||||
|
||||
files.readPipe({
|
||||
names : names,
|
||||
dir : dir,
|
||||
write : stream,
|
||||
callback : function(error) {
|
||||
var errorStr;
|
||||
|
||||
if (error)
|
||||
if (!response.headersSent)
|
||||
main.sendError({
|
||||
request : request,
|
||||
response : response,
|
||||
name : path
|
||||
}, error);
|
||||
else {
|
||||
Util.log(error);
|
||||
errorStr = error.toString();
|
||||
stream.end(errorStr);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* pipe should be setted up after
|
||||
* readPipe called with stream param
|
||||
*/
|
||||
if (isGzip)
|
||||
gzip.pipe(response);
|
||||
};
|
||||
|
||||
if (!isJoin)
|
||||
Util.exec(callback);
|
||||
else {
|
||||
names = CloudFunc.getJoinArray(path);
|
||||
|
||||
if (!before)
|
||||
readPipe();
|
||||
else
|
||||
before(names, readPipe);
|
||||
}
|
||||
|
||||
return isJoin;
|
||||
}
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue