feature(upload-file) add wraptile

This commit is contained in:
coderaiser 2017-04-12 15:58:11 +03:00
parent d59c998b71
commit 1cabb14bcc
2 changed files with 40 additions and 37 deletions

View file

@ -2,7 +2,8 @@
/* global CloudCmd */
const exec = require('execon');
const {eachSeries} = require('execon');
const wraptile = require('wraptile/legacy');
const DOM = require('.');
const load = require('./load');
@ -11,9 +12,10 @@ const Images = require('./images');
const {FS} = require('../../common/cloudfunc');
const {CurrentInfo} = DOM;
const onEnd = wraptile(_onEnd);
const loadFile = wraptile(_loadFile);
module.exports = (dir, files) => {
let i = 0;
if (!files) {
files = dir;
dir = CurrentInfo.dirPath;
@ -27,39 +29,39 @@ module.exports = (dir, files) => {
const array = [...files];
const {name} = files[0];
exec.eachSeries(array, loadFile, func(name));
function func(name) {
return () => {
CloudCmd.refresh(null, () => {
DOM.setCurrentByName(name);
});
};
}
function loadFile(file, callback) {
const name = file.name;
const path = dir + name;
const {PREFIX_URL} = CloudCmd;
const api = PREFIX_URL + FS;
const percent = (i, n, per = 100) => {
return Math.round(i * per / n);
};
const step = (n) => 100 / n;
++i;
load.put(api + path, file)
.on('end', callback)
.on('progress', (count) => {
const max = step(n);
const value = (i - 1) * max + percent(count, 100, max);
Images.show.load('top');
Images.setProgress(Math.round(value));
});
}
eachSeries(array, loadFile(dir, n), onEnd(name));
};
function _onEnd(name) {
CloudCmd.refresh(null, () => {
DOM.setCurrentByName(name);
});
}
function _loadFile(dir, n, file, callback) {
let i = 0;
const name = file.name;
const path = dir + name;
const {PREFIX_URL} = CloudCmd;
const api = PREFIX_URL + FS;
const percent = (i, n, per = 100) => {
return Math.round(i * per / n);
};
const step = (n) => 100 / n;
++i;
load.put(api + path, file)
.on('end', callback)
.on('progress', (count) => {
const max = step(n);
const value = (i - 1) * max + percent(count, 100, max);
Images.show.load('top');
Images.setProgress(Math.round(value));
});
}

View file

@ -189,6 +189,7 @@
"tar-stream": "^1.5.2",
"version-io": "^1.2.5",
"webpack": "^2.2.1",
"wraptile": "^1.0.0",
"yaspeller": "^3.0.0"
},
"engines": {