mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-19 09:24:51 +00:00
feature(rest) copyFiles: add rename
This commit is contained in:
parent
ed5a359327
commit
13cab39c4f
1 changed files with 39 additions and 16 deletions
|
|
@ -261,7 +261,7 @@
|
|||
* @param pParams {command, method, body, requrest, response}
|
||||
*/
|
||||
function onPUT(params) {
|
||||
var p, cmd, files, name, json, config,
|
||||
var p, cmd, files, name, json, config, data,
|
||||
ret = main.checkParams(params, ['body']);
|
||||
|
||||
if (ret) {
|
||||
|
|
@ -283,10 +283,15 @@
|
|||
break;
|
||||
|
||||
case 'mv':
|
||||
if (!Util.checkObjTrue(files, ['from', 'names', 'to']) )
|
||||
if (!Util.checkObjTrue(files, ['from', 'to']) )
|
||||
sendError(params, p.data);
|
||||
else {
|
||||
files.namesAll = Util.slice(files.names);
|
||||
|
||||
if (files.names)
|
||||
data = Util.slice(files.names);
|
||||
else
|
||||
data = files;
|
||||
|
||||
copyFiles(files,
|
||||
function(path, callback) {
|
||||
fse.delete(path, function(error) {
|
||||
|
|
@ -301,7 +306,7 @@
|
|||
if (error)
|
||||
sendError(params, error);
|
||||
else
|
||||
sendMsg(params, 'move', files.namesAll);
|
||||
sendMsg(params, 'move', data);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -396,22 +401,31 @@
|
|||
}
|
||||
|
||||
function copyFiles(files, callbackProcess, callback) {
|
||||
var names = files.names,
|
||||
|
||||
from = files.from,
|
||||
to = files.to,
|
||||
|
||||
isFunc = Util.isFunction(callbackProcess),
|
||||
var names = files.names,
|
||||
isFunc = Util.isFunction(callbackProcess),
|
||||
processFunc = names ? fse.copy : fs.rename,
|
||||
|
||||
copy = function() {
|
||||
var isLast = !names.length,
|
||||
var isLast, name, process,
|
||||
from = files.from,
|
||||
to = files.to;
|
||||
|
||||
if (names) {
|
||||
isLast = !names.length,
|
||||
name = names.shift(),
|
||||
process = Util.retExec(callbackProcess, from + name);
|
||||
from += name;
|
||||
to += name;
|
||||
} else {
|
||||
isLast = false;
|
||||
names = [];
|
||||
}
|
||||
|
||||
process = Util.retExec(callbackProcess, from);
|
||||
|
||||
if (isLast)
|
||||
Util.exec(callback, null);
|
||||
else
|
||||
fse.copy(from + name, to + name, function(error) {
|
||||
processFunc(from, to, function(error) {
|
||||
if (error)
|
||||
Util.exec(callback, error);
|
||||
else
|
||||
|
|
@ -422,9 +436,18 @@
|
|||
copy();
|
||||
}
|
||||
|
||||
function sendMsg(pParams, pMsg, pName, pStatus) {
|
||||
var msg = CloudFunc.formatMsg(pMsg, pName, pStatus);
|
||||
sendResponse(pParams, msg);
|
||||
function sendMsg(sendParam, msgParam, dataParam, status) {
|
||||
var msg, data,
|
||||
isObj = Util.isObject(dataParam);
|
||||
|
||||
if (isObj)
|
||||
data = Util.stringifyJSON(dataParam);
|
||||
else
|
||||
data = dataParam;
|
||||
|
||||
msg = CloudFunc.formatMsg(msgParam, data, status);
|
||||
|
||||
sendResponse(sendParam, msg);
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue