diff --git a/lib/client/edit.js b/lib/client/edit.js index 5e02810d..08377bf7 100644 --- a/lib/client/edit.js +++ b/lib/client/edit.js @@ -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) diff --git a/lib/client/rest.js b/lib/client/rest.js index e4f86334..efcca8a1 100644 --- a/lib/client/rest.js +++ b/lib/client/rest.js @@ -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); diff --git a/lib/server/rest.js b/lib/server/rest.js index ca74ee78..9a92406e 100644 --- a/lib/server/rest.js +++ b/lib/server/rest.js @@ -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, diff --git a/lib/server/rest/fs/patch.js b/lib/server/rest/fs/patch.js new file mode 100644 index 00000000..cb2957b6 --- /dev/null +++ b/lib/server/rest/fs/patch.js @@ -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); + }); + }); + }; +})(); diff --git a/lib/server/rest/fs/put.js b/lib/server/rest/fs/put.js index cba76505..99bc6d40 100644 --- a/lib/server/rest/fs/put.js +++ b/lib/server/rest/fs/put.js @@ -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; }