mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-20 18:18:56 +00:00
refactor(console) getOnMessage
This commit is contained in:
parent
195466e0da
commit
5beca6c06d
1 changed files with 65 additions and 67 deletions
|
|
@ -76,7 +76,7 @@
|
|||
|
||||
Clients[ConNum] = true;
|
||||
|
||||
onMessage = getOnMessage(ConNum, callback);
|
||||
onMessage = Util.bind(getOnMessage, ConNum, callback);
|
||||
onDisconnect = function(conNum) {
|
||||
Clients[conNum] =
|
||||
ClientFuncs[conNum] = null;
|
||||
|
|
@ -107,76 +107,74 @@
|
|||
* @param pConnNum
|
||||
* @param callback
|
||||
*/
|
||||
function getOnMessage(pConnNum, callback) {
|
||||
return function(pCommand) {
|
||||
var lWinCommand, lExec_func, firstChar,
|
||||
connName, lRet, lExecSymbols, isContain,
|
||||
dir, options = {};
|
||||
function getOnMessage(connNum, callback, command) {
|
||||
var lWinCommand, lExec_func, firstChar,
|
||||
connName, lRet, lExecSymbols, isContain,
|
||||
dir, options = {};
|
||||
|
||||
dir = ClientDirs[connNum];
|
||||
|
||||
if (!dir)
|
||||
dir = ClientDirs[connNum] = DIR;
|
||||
|
||||
connName = '#' + connNum + ': ';
|
||||
Util.log(connName + command);
|
||||
|
||||
if (equalPart(command, CLOUDCMD))
|
||||
lRet = onCloudCmd(command, callback);
|
||||
else if (equalPart(command, 'cd ')) {
|
||||
lRet = true;
|
||||
|
||||
dir = ClientDirs[pConnNum];
|
||||
|
||||
if (!dir)
|
||||
dir = ClientDirs[pConnNum] = DIR;
|
||||
|
||||
connName = '#' + pConnNum + ': ';
|
||||
Util.log(connName + pCommand);
|
||||
|
||||
if (equalPart(pCommand, CLOUDCMD))
|
||||
lRet = onCloudCmd(pCommand, callback);
|
||||
else if (equalPart(pCommand, 'cd ')) {
|
||||
lRet = true;
|
||||
onCD(command, dir, function(json) {
|
||||
var error = json.stderr,
|
||||
stdout = json.stdout;
|
||||
|
||||
onCD(pCommand, dir, function(json) {
|
||||
var error = json.stderr,
|
||||
stdout = json.stdout;
|
||||
|
||||
if (error)
|
||||
Util.exec(callback, json);
|
||||
else
|
||||
ClientDirs[pConnNum] = stdout;
|
||||
});
|
||||
}
|
||||
|
||||
if (!lRet) {
|
||||
/* if we on windows and command is build in
|
||||
* change code page to unicode becouse
|
||||
* windows use unicode on non English versions
|
||||
*/
|
||||
if (WIN32) {
|
||||
lWinCommand = pCommand.toUpperCase();
|
||||
|
||||
if (Win32Commands.indexOf(lWinCommand) >= 0)
|
||||
pCommand = 'chcp 65001 |' + pCommand;
|
||||
}
|
||||
|
||||
if (!ClientFuncs[pConnNum])
|
||||
ClientFuncs[pConnNum] = getExec(function(json, pError, pStderr) {
|
||||
log(pConnNum, pError, 'error');
|
||||
log(pConnNum, pStderr, 'stderror');
|
||||
|
||||
Util.exec(callback, json);
|
||||
});
|
||||
|
||||
lExec_func = ClientFuncs[pConnNum];
|
||||
lExecSymbols = ['*', '&', '{', '}', '|', '\'', '"'];
|
||||
isContain = Util.isContainStr(pCommand, lExecSymbols);
|
||||
firstChar = pCommand[0];
|
||||
options.cwd = dir;
|
||||
|
||||
if (firstChar === '#') {
|
||||
pCommand = pCommand.slice(1);
|
||||
pCommand = connName + pCommand;
|
||||
pCommand = CloudFunc.addNewLine(pCommand);
|
||||
|
||||
Util.exec(callback, {
|
||||
stdout: pCommand
|
||||
}, true);
|
||||
} else if (WIN32 || firstChar === ' ' || isContain)
|
||||
exec(pCommand, options, lExec_func);
|
||||
if (error)
|
||||
Util.exec(callback, json);
|
||||
else
|
||||
getSpawn(pCommand, options, callback);
|
||||
ClientDirs[connNum] = stdout;
|
||||
});
|
||||
}
|
||||
|
||||
if (!lRet) {
|
||||
/* if we on windows and command is build in
|
||||
* change code page to unicode becouse
|
||||
* windows use unicode on non English versions
|
||||
*/
|
||||
if (WIN32) {
|
||||
lWinCommand = command.toUpperCase();
|
||||
|
||||
if (Win32Commands.indexOf(lWinCommand) >= 0)
|
||||
command = 'chcp 65001 |' + command;
|
||||
}
|
||||
};
|
||||
|
||||
if (!ClientFuncs[connNum])
|
||||
ClientFuncs[connNum] = getExec(function(json, error, stderr) {
|
||||
log(connNum, error, 'error');
|
||||
log(connNum, stderr, 'stderror');
|
||||
|
||||
Util.exec(callback, json);
|
||||
});
|
||||
|
||||
lExec_func = ClientFuncs[connNum];
|
||||
lExecSymbols = ['*', '&', '{', '}', '|', '\'', '"'];
|
||||
isContain = Util.isContainStr(command, lExecSymbols);
|
||||
firstChar = command[0];
|
||||
options.cwd = dir;
|
||||
|
||||
if (firstChar === '#') {
|
||||
command = command.slice(1);
|
||||
command = connName + command;
|
||||
command = CloudFunc.addNewLine(command);
|
||||
|
||||
Util.exec(callback, {
|
||||
stdout: command
|
||||
}, true);
|
||||
} else if (WIN32 || firstChar === ' ' || isContain)
|
||||
exec(command, options, lExec_func);
|
||||
else
|
||||
getSpawn(command, options, callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue