feature(rest) cp: add ability to copy couple files

This commit is contained in:
coderaiser 2014-04-16 10:28:55 -04:00
parent 6cb7252145
commit 217b53218c
2 changed files with 59 additions and 17 deletions

View file

@ -1748,22 +1748,42 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
* @param current
*/
this.copyCurrent = function(current) {
var name, from, to, files, cmp,
path = DOM.CurrentInfo.dirPath,
RESTful = DOM.RESTful;
var n, name, from, to, files, cmp, msg,
path = CurrentInfo.dirPath,
RESTful = DOM.RESTful,
names = Cmd.getSelectedNames(),
length = names && names.length;
if (!Cmd.isCurrentFile(current))
current = Cmd.getCurrentFile();
name = Cmd.getCurrentName(current),
from = Cmd.getCurrentPath(),
to = Cmd.getNotCurrentDirPath() + name;
to = Dialog.prompt('Copy file "' + name + '" to', to);
cmp = Util.strCmp(from, to);
if (!length) {
name = Cmd.getCurrentName(current);
names.push(name);
} else if (length === 1) {
name = names[0];
}
n = names.length;
msg = 'Copy ';
if (n > 1)
msg += n + ' file(s)';
else
msg += '"' + name + '"';
msg += ' to';
from = path;
to = DOM.getNotCurrentDirPath();
to = Dialog.prompt(msg, to);
cmp = Util.strCmp(from, to);
if (!cmp) {
files = {
from : from,
names : names,
to : to
};

View file

@ -242,7 +242,7 @@
* @param pParams {command, method, body, requrest, response}
*/
function onPUT(pParams) {
var name, json, config,
var name, json, config, names, to, from, copyFiles,
ret = main.checkParams(pParams, ['body']);
if (ret) {
@ -276,15 +276,37 @@
break;
case 'cp':
if (!Util.checkObjTrue(lFiles, ['from', 'to']))
if (!Util.checkObjTrue(lFiles, ['from', 'names', 'to']))
sendError(pParams, p.data);
else
fse.copy(lFiles.from, lFiles.to, function(error) {
if (error)
sendError(pParams, error);
else
sendMsg(pParams, 'copy', lFiles.to);
});
else {
lFiles.namesAll = Util.slice(lFiles.names);
copyFiles = function(files) {
var names = files.names,
namesAll = files.namesAll,
name = names.shift();
from = files.from,
to = files.to,
fse.copy(from + name, to + name, function(error) {
var length = names.length;
if (error)
sendError(pParams, error);
else if (!length)
sendMsg(pParams, 'copy', namesAll);
else
copyFiles({
from : from,
to : to,
names : names,
namesAll: namesAll
});
});
};
copyFiles(lFiles);
}
break;
case 'zip':