diff --git a/client/dom/index.js b/client/dom/index.js index 20644e8a..91862b7d 100644 --- a/client/dom/index.js +++ b/client/dom/index.js @@ -258,58 +258,6 @@ function CmdProto() { return DOM.loadRemote('menu', callback); }; - this.uploadFiles = (dir, files) => { - let i = 0; - const slice = [].slice; - - if (!files) { - files = dir; - dir = CurrentInfo.dirPath; - } - - const n = files.length; - - if (!n) - return; - - const array = slice.call(files); - - exec.eachSeries(array, loadFile, func(files[0].name)); - - function func(name) { - return () => { - CloudCmd.refresh(null, () => { - DOM.setCurrentByName(name); - }); - }; - } - - function loadFile(file, callback) { - const name = file.name; - const path = dir + name; - const prefixURL = CloudCmd.PREFIX_URL; - const api = prefixURL + 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)); - }); - } - }; - /** * create new folder * diff --git a/client/dom/upload-files.js b/client/dom/upload-files.js new file mode 100644 index 00000000..c4113191 --- /dev/null +++ b/client/dom/upload-files.js @@ -0,0 +1,68 @@ +'use strict'; + +const exec = require('execon'); + +const DOM = require('.'); +const load = require('./load'); +const Images = require('./images'); + +const {FS} = require('../../common/cloudfunc'); +const {CurrentInfo} = DOM; + +const CloudCmd = require('../client'); + +const { + PREFIX_URL, +} = CloudCmd; + +module.exports = (dir, files) => { + let i = 0; + const slice = [].slice; + + if (!files) { + files = dir; + dir = CurrentInfo.dirPath; + } + + const n = files.length; + + if (!n) + return; + + const array = slice.call(files); + + exec.eachSeries(array, loadFile, func(files[0].name)); + + function func(name) { + return () => { + CloudCmd.refresh(null, () => { + DOM.setCurrentByName(name); + }); + }; + } + + function loadFile(file, callback) { + const name = file.name; + const path = dir + name; + 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)); + }); + } +}; + diff --git a/client/listeners.js b/client/listeners.js index a5f235ff..db1cdb6b 100644 --- a/client/listeners.js +++ b/client/listeners.js @@ -5,6 +5,8 @@ const exec = require('execon'); const itype = require('itype/legacy'); +const uploadFiles = require('./dom/upload-files'); + const { FS, apiURL @@ -398,7 +400,7 @@ function dragndrop() { event.preventDefault(); if (!items || !items.length || !items[0].webkitGetAsEntry) - return DOM.uploadFiles(files); + return uploadFiles(files); const dirFiles = [...items].filter((item) => { return item.kind === 'file'; diff --git a/client/modules/upload.js b/client/modules/upload.js index 80b9c9aa..0337e47f 100644 --- a/client/modules/upload.js +++ b/client/modules/upload.js @@ -7,6 +7,7 @@ const exec = require('execon'); const load = require('../dom/load'); const Files = require('../dom/files'); const Images = require('../dom/images'); +const uploadFiles = require('../dom/upload-files'); CloudCmd.Upload = UploadProto; @@ -67,7 +68,7 @@ function afterShow() { hide(); - DOM.uploadFiles(files); + uploadFiles(files); }); }