mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-19 09:24:51 +00:00
feature(rest) copy: add progress
This commit is contained in:
parent
a62faf3a3f
commit
1392f73ce5
2 changed files with 36 additions and 9 deletions
|
|
@ -29,6 +29,7 @@
|
|||
ponse = require('ponse'),
|
||||
rendy = require('rendy'),
|
||||
copymitter = require('copymitter'),
|
||||
charm = require('charm'),
|
||||
|
||||
Modules = require(DIR_JSON + 'modules'),
|
||||
|
||||
|
|
@ -230,15 +231,7 @@
|
|||
|
||||
msg = formatMsg('copy', files.names);
|
||||
|
||||
emitter = copymitter(files.from, files.to, files.names);
|
||||
|
||||
emitter.on('end', function() {
|
||||
if (!wasError)
|
||||
callback(null, msg);
|
||||
});
|
||||
|
||||
emitter.on('error', function(error) {
|
||||
wasError = true;
|
||||
copy(files.from, files.to, files.names, function(error) {
|
||||
callback(error, msg);
|
||||
});
|
||||
}
|
||||
|
|
@ -293,6 +286,39 @@
|
|||
}
|
||||
}
|
||||
|
||||
function copy(from, to, names, fn) {
|
||||
var error,
|
||||
prev = '',
|
||||
bar = charm(),
|
||||
cp = copymitter(from, to, names);
|
||||
|
||||
bar.pipe(process.stdout);
|
||||
bar.cursor(false);
|
||||
|
||||
cp.on('progress', function(percent) {
|
||||
bar.left(prev.length);
|
||||
|
||||
prev = rendy('copy {{ from }} -> {{ to }} {{ percent }}%', {
|
||||
to: to,
|
||||
from: from,
|
||||
percent: percent
|
||||
});
|
||||
|
||||
bar.write(prev);
|
||||
});
|
||||
|
||||
cp.on('error', function(e) {
|
||||
error = e;
|
||||
cp.abort();
|
||||
});
|
||||
|
||||
cp.on('end', function() {
|
||||
fn(error);
|
||||
bar.write('\n');
|
||||
bar.cursor(true);
|
||||
});
|
||||
}
|
||||
|
||||
function copyFiles(files, processFunc, callback) {
|
||||
var names = files.names,
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
"subdomain": "cloudcmd",
|
||||
"dependencies": {
|
||||
"ashify": "~1.0.0",
|
||||
"charm": "~1.0.0",
|
||||
"console-io": "~2.1.0",
|
||||
"copymitter": "~1.5.0",
|
||||
"edward": "~1.1.0",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue