mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-08-04 21:53:14 +00:00
feature(rest) fs: add PATCH
This commit is contained in:
parent
1d71be4d2e
commit
96da0c621b
5 changed files with 73 additions and 22 deletions
|
|
@ -280,20 +280,18 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI
|
|||
length = Value.length,
|
||||
isLessMaxLength = length < MAX_SIZE,
|
||||
isLessLength = isLessMaxLength && patchLength < length,
|
||||
isStr = type.string(patch);
|
||||
isStr = type.string(patch),
|
||||
isPatch = patch && isStr && isLessLength;
|
||||
|
||||
Value = value;
|
||||
|
||||
if (isStr && patch && isLessLength)
|
||||
query = '?patch';
|
||||
else
|
||||
patch = false;
|
||||
|
||||
exec.if(!isZip || query, function(equal, data) {
|
||||
var result = data || patch || Value,
|
||||
url = path + query;
|
||||
exec.if(!isZip || isPatch, function(equal, data) {
|
||||
var result = data || Value;
|
||||
|
||||
RESTful.write(url, result , onSave);
|
||||
if (isPatch)
|
||||
RESTful.patch(path, patch, onSave);
|
||||
else
|
||||
RESTful.write(path + query, result, onSave);
|
||||
}, function(func) {
|
||||
zip(value, function(error, data) {
|
||||
if (error)
|
||||
|
|
|
|||
|
|
@ -30,6 +30,23 @@ var Util, DOM, CloudFunc, CloudCmd;
|
|||
});
|
||||
};
|
||||
|
||||
this.patch = function(url, data, callback) {
|
||||
var isFunc = Util.type.function(data);
|
||||
|
||||
if (!callback && isFunc) {
|
||||
callback = data;
|
||||
data = null;
|
||||
}
|
||||
|
||||
sendRequest({
|
||||
method : 'PATCH',
|
||||
url : CloudFunc.FS + url,
|
||||
data : data,
|
||||
callback : callback,
|
||||
imgPosition : { top: true }
|
||||
});
|
||||
};
|
||||
|
||||
this.write = function(url, data, callback) {
|
||||
var isFunc = Util.type.function(data);
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
[
|
||||
'get',
|
||||
'put',
|
||||
'patch',
|
||||
'delete'
|
||||
].forEach(function(name) {
|
||||
Fs[name] = require(DIR + 'rest/fs/' + name);
|
||||
|
|
@ -143,6 +144,12 @@
|
|||
});
|
||||
break;
|
||||
|
||||
case 'PATCH':
|
||||
Fs.patch(path, p.request, function(error, data) {
|
||||
callback(error, optionsDefauls, data);
|
||||
});
|
||||
break;
|
||||
|
||||
case 'GET':
|
||||
Fs.get(query, path, function(error, data) {
|
||||
var str,
|
||||
|
|
|
|||
35
lib/server/rest/fs/patch.js
Normal file
35
lib/server/rest/fs/patch.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
var DIR = '../../../',
|
||||
DIR_SERVER = DIR + 'server/',
|
||||
|
||||
path = require('path'),
|
||||
|
||||
CloudFunc = require(DIR + 'cloudfunc'),
|
||||
Util = require(DIR + 'util'),
|
||||
|
||||
pipe = require(DIR_SERVER + 'pipe'),
|
||||
patch = require(DIR_SERVER + 'patch');
|
||||
|
||||
module.exports = function(name, readStream, callback) {
|
||||
var baseName = path.basename(name);
|
||||
|
||||
Util.checkArgs(arguments, ['name', 'readStream', 'callback']);
|
||||
|
||||
pipe.getBody(readStream, function(error, data) {
|
||||
var options = {
|
||||
size: CloudFunc.MAX_FILE_SIZE
|
||||
};
|
||||
|
||||
patch(name, data, options, function(error) {
|
||||
var msg;
|
||||
|
||||
if (!error)
|
||||
msg = CloudFunc.formatMsg('patch', baseName);
|
||||
|
||||
callback(error, msg);
|
||||
});
|
||||
});
|
||||
};
|
||||
})();
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
flop = require(DIR_SERVER + 'flop'),
|
||||
pack = require(DIR_SERVER + 'pack'),
|
||||
pipe = require(DIR_SERVER + 'pipe'),
|
||||
patch = require(DIR_SERVER + 'patch');
|
||||
patch = require('./patch');
|
||||
|
||||
module.exports = function(query, name, readStream, callback) {
|
||||
var baseName = path.basename(name),
|
||||
|
|
@ -46,19 +46,13 @@
|
|||
break;
|
||||
|
||||
case 'patch':
|
||||
pipe.getBody(readStream, function(error, data) {
|
||||
var options = {
|
||||
size: CloudFunc.MAX_FILE_SIZE
|
||||
};
|
||||
|
||||
patch(name, data, options, function(error) {
|
||||
var msg;
|
||||
patch(name, readStream, function(error) {
|
||||
var msg;
|
||||
|
||||
if (!error)
|
||||
msg = CloudFunc.formatMsg('patch', baseName);
|
||||
if (!error)
|
||||
msg = CloudFunc.formatMsg('[Deprecated. Clear cache to use new API]patch', baseName);
|
||||
|
||||
callback(error, msg);
|
||||
});
|
||||
callback(error, msg);
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue