mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-21 10:38:26 +00:00
feature(rest) add put patch
This commit is contained in:
parent
d2ba63e050
commit
ee5d3bc7e9
5 changed files with 57 additions and 21 deletions
|
|
@ -77,7 +77,7 @@
|
|||
|
||||
/* we can not use librequare here */
|
||||
exports.util = Util = require(LIBDIR + UTIL),
|
||||
exports.diff = mrequire(LIBDIR + UTIL + '/jsdiff/diff').JsDiff,
|
||||
exports.diff = mrequire(LIBDIR + UTIL + '/jsdiff/diff'),
|
||||
|
||||
exports.zlib = zlib = mrequire('zlib'),
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
Util = main.util,
|
||||
CloudFunc = main.cloudfunc,
|
||||
dir = main.dir,
|
||||
diff = main.diff,
|
||||
OK = 200,
|
||||
Header = main.generateHeaders({
|
||||
name:'api.json'
|
||||
|
|
@ -62,14 +63,14 @@
|
|||
* @param pParams {command, method, body, requrest, response}
|
||||
*/
|
||||
function sendData(pParams){
|
||||
var lRet = main.checkParams(pParams);
|
||||
var p, lRet = main.checkParams(pParams);
|
||||
if(lRet){
|
||||
var p = pParams;
|
||||
p = pParams;
|
||||
|
||||
lRet = Util.isContainStrAtBegin(p.name, CloudFunc.FS);
|
||||
if( lRet)
|
||||
if (lRet)
|
||||
onFS(pParams);
|
||||
else{
|
||||
else {
|
||||
if(p.name[0] === '/')
|
||||
p.command = Util.removeStrOneTime(p.name, '/');
|
||||
|
||||
|
|
@ -79,9 +80,9 @@
|
|||
break;
|
||||
|
||||
case 'PUT':
|
||||
getBody(pParams.request, function(pBody){
|
||||
pParams.body = pBody;
|
||||
onPUT(pParams);
|
||||
getBody(p.request, function(pBody){
|
||||
p.body = pBody;
|
||||
onPUT(p);
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
|
@ -132,13 +133,33 @@
|
|||
break;
|
||||
|
||||
case 'PUT':
|
||||
if(lQuery === 'dir')
|
||||
if (lQuery === 'dir')
|
||||
fs.mkdir(p.name, function(pError){
|
||||
if(!pError)
|
||||
main.sendResponse(pParams, 'Folder ' + p.name + ' created.');
|
||||
else
|
||||
main.sendError(pParams, pError);
|
||||
});
|
||||
else if(lQuery === 'patch') {
|
||||
getBody(p.request, function(pPatch) {
|
||||
fs.readFile(p.name, function(pError, pData) {
|
||||
var lDiff, lStr = pData.toString();
|
||||
|
||||
if (pError)
|
||||
main.sendError(pParams, pError);
|
||||
else {
|
||||
lDiff = diff.applyPatch(lStr, pPatch);
|
||||
|
||||
fs.writeFile(p.name, lDiff, function(){
|
||||
if (pError)
|
||||
main.sendError(pParams, pError);
|
||||
else
|
||||
main.sendResponse(pParams, 'writed: ' + p.name);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
else {
|
||||
lWriteStream = fs.createWriteStream(p.name);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue