mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
fix(rest) change the way params mv
This commit is contained in:
parent
ebefbc7324
commit
e6fcc4632b
1 changed files with 40 additions and 24 deletions
|
|
@ -141,34 +141,50 @@
|
|||
else
|
||||
main.sendError(pParams, pError);
|
||||
});
|
||||
else if(lQuery === 'patch') {
|
||||
else if(lQuery === 'patch')
|
||||
getBody(p.request, function(pPatch) {
|
||||
fs.readFile(p.name, function(pError, pData) {
|
||||
var lRet, lDiff, lStr;
|
||||
fs.readFile(p.name, Util.call(read, pParams));
|
||||
|
||||
function read(pParams) {
|
||||
var lDiff, lStr, p, lData, lName,
|
||||
lRet = main.checkCallBackParams(pParams) &&
|
||||
main.checkParams(pParams.params);
|
||||
|
||||
if (pError)
|
||||
main.sendError(pParams, pError);
|
||||
else {
|
||||
lStr = pData.toString();
|
||||
lRet = Util.tryCatchLog(function(){
|
||||
lDiff = diff.applyPatch(lStr, pPatch);
|
||||
});
|
||||
if (lRet) {
|
||||
p = pParams;
|
||||
lName = p.params.name;
|
||||
|
||||
if (lDiff && !lRet)
|
||||
fs.writeFile(p.name, lDiff, function(){
|
||||
var lName = path.basename(p.name);
|
||||
|
||||
if (pError)
|
||||
main.sendError(pParams, pError);
|
||||
else
|
||||
main.sendResponse(pParams, 'edit: save(' + lName +')');
|
||||
if (p.error)
|
||||
main.sendError(p.params, p.error);
|
||||
else {
|
||||
lStr = p.data.toString();
|
||||
lRet = Util.tryCatchLog(function(){
|
||||
lDiff = diff.applyPatch(lStr, pPatch);
|
||||
});
|
||||
else
|
||||
main.sendError(pParams, lRet || lDiff);
|
||||
|
||||
if (lDiff && !lRet)
|
||||
fs.writeFile(lName, lDiff, Util.call(write, p.params));
|
||||
else
|
||||
main.sendError(pParams, lRet || lDiff);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function write(pParams) {
|
||||
var p, lName,
|
||||
lRet = main.checkCallBackParams(pParams) &&
|
||||
main.checkParams(pParams.params);
|
||||
if(lRet) {
|
||||
p = pParams;
|
||||
if (p.error)
|
||||
main.sendError(p.params, p.error);
|
||||
else {
|
||||
lName = path.basename(p.params.name);
|
||||
main.sendResponse(p.params, 'patch: ok("' + lName +'")');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
else {
|
||||
lWriteStream = fs.createWriteStream(p.name);
|
||||
|
||||
|
|
@ -180,7 +196,7 @@
|
|||
p.request.on('error', lError);
|
||||
p.request.on('end', function(){
|
||||
var lName = path.basename(p.name);
|
||||
main.sendResponse(pParams, 'edit: save(' + lName +')');
|
||||
main.sendResponse(pParams, 'save: ok("' + lName +'")');
|
||||
});
|
||||
|
||||
//p.request.pipe(process.stdout);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue