mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
feature(client) directory: add abily to show progress dialog on upload
This commit is contained in:
parent
82f3198bdd
commit
67eef31520
1 changed files with 11 additions and 12 deletions
|
|
@ -1,18 +1,17 @@
|
|||
/* global CloudCmd */
|
||||
|
||||
'use strict';
|
||||
|
||||
/* global CloudCmd */
|
||||
|
||||
const philip = require('philip');
|
||||
|
||||
const Images = require('./images');
|
||||
const {FS} = require('../../common/cloudfunc');
|
||||
const DOM = require('.');
|
||||
const Dialog = require('./dialog');
|
||||
|
||||
const {getCurrentDirPath: getPathWhenRootEmpty} = DOM;
|
||||
|
||||
module.exports = (items) => {
|
||||
const {Dialog} = DOM;
|
||||
|
||||
if (items.length)
|
||||
Images.show('top');
|
||||
|
||||
|
|
@ -24,6 +23,13 @@ module.exports = (items) => {
|
|||
const path = dirPath
|
||||
.replace(/\/$/, '');
|
||||
|
||||
const progress = Dialog.progress('Uploading...');
|
||||
|
||||
progress.catch(() => {
|
||||
Dialog.alert('Upload aborted');
|
||||
uploader.abort();
|
||||
});
|
||||
|
||||
const uploader = philip(entries, (type, name, data, i, n, callback) => {
|
||||
const {prefixURL} = CloudCmd;
|
||||
const full = prefixURL + FS + path + name;
|
||||
|
|
@ -47,7 +53,7 @@ module.exports = (items) => {
|
|||
const max = next - current;
|
||||
const value = current + percent(count, 100, max);
|
||||
|
||||
setProgress(value);
|
||||
progress.setProgress(value);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -56,7 +62,6 @@ module.exports = (items) => {
|
|||
uploader.abort();
|
||||
});
|
||||
|
||||
uploader.on('progress', setProgress);
|
||||
uploader.on('end', CloudCmd.refresh);
|
||||
};
|
||||
|
||||
|
|
@ -64,12 +69,6 @@ function percent(i, n, per = 100) {
|
|||
return Math.round(i * per / n);
|
||||
}
|
||||
|
||||
function setProgress(count) {
|
||||
DOM.Images
|
||||
.setProgress(count)
|
||||
.show('top');
|
||||
}
|
||||
|
||||
function uploadFile(url, data) {
|
||||
return DOM.load.put(url, data);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue