diff --git a/www/common/common-util.js b/www/common/common-util.js index dfc6e12d7..435a72280 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -296,6 +296,12 @@ return void CB(void 0, new Uint8Array(xhr.response)); }; xhr.send(null); + + return { + cancel: function () { + if (xhr.abort) { xhr.abort(); } + } + }; }; Util.dataURIToBlob = function (dataURI) { diff --git a/www/common/drive-ui.js b/www/common/drive-ui.js index 53e496ef4..c01bf0f54 100644 --- a/www/common/drive-ui.js +++ b/www/common/drive-ui.js @@ -4149,6 +4149,17 @@ define([ data.name = Util.fixFileName(folderName); data.folderName = Util.fixFileName(folderName) + '.zip'; + var uo = manager.user.userObject; + if (sfId && manager.folders[sfId]) { + uo = manager.folders[sfId].userObject; + } + if (uo.getFilesRecursively) { + data.list = uo.getFilesRecursively(folderElement).map(function (el) { + var d = uo.getFileData(el); + return d.channel; + }); + } + APP.FM.downloadFolder(data, function (err, obj) { console.log(err, obj); console.log('DONE'); diff --git a/www/common/make-backup.js b/www/common/make-backup.js index b718ae9c1..88602c8bb 100644 --- a/www/common/make-backup.js +++ b/www/common/make-backup.js @@ -53,9 +53,6 @@ define([ var _downloadFile = function (ctx, fData, cb, updateProgress) { var cancelled = false; - var cancel = function () { - cancelled = true; - }; var href = (fData.href && fData.href.indexOf('#') !== -1) ? fData.href : fData.roHref; var parsed = Hash.parsePadUrl(href); var hash = parsed.hash; @@ -63,10 +60,13 @@ define([ var secret = Hash.getSecrets('file', hash, fData.password); var src = (ctx.fileHost || '') + Hash.getBlobPathFromHex(secret.channel); var key = secret.keys && secret.keys.cryptKey; - Util.fetch(src, function (err, u8) { + + var fetchObj, decryptObj; + + fetchObj = Util.fetch(src, function (err, u8) { if (cancelled) { return; } if (err) { return void cb('E404'); } - FileCrypto.decrypt(u8, key, function (err, res) { + decryptObj = FileCrypto.decrypt(u8, key, function (err, res) { if (cancelled) { return; } if (err) { return void cb(err); } if (!res.content) { return void cb('EEMPTY'); } @@ -78,8 +78,25 @@ define([ content: res.content, download: dl }); - }, updateProgress && updateProgress.progress2); - }, updateProgress && updateProgress.progress); + }, function (data) { + if (cancelled) { return; } + if (updateProgress && updateProgress.progress2) { + updateProgress.progress2(data); + } + }); + }, function (data) { + if (cancelled) { return; } + if (updateProgress && updateProgress.progress) { + updateProgress.progress(data); + } + }); + + var cancel = function () { + cancelled = true; + if (fetchObj && fetchObj.cancel) { fetchObj.cancel(); } + if (decryptObj && decryptObj.cancel) { decryptObj.cancel(); } + }; + return { cancel: cancel }; @@ -162,10 +179,10 @@ define([ if (ctx.stop) { return; } if (to) { clearTimeout(to); } //setTimeout(g, 2000); - g(); - w(); ctx.done++; ctx.updateProgress('download', {max: ctx.max, current: ctx.done}); + g(); + w(); }; var error = function (err) { @@ -312,13 +329,14 @@ define([ delete ctx.zip; }; return { - stop: stop + stop: stop, + cancel: stop }; }; var _downloadFolder = function (ctx, data, cb, updateProgress) { - create(data, ctx.get, ctx.fileHost, function (blob, errors) { + return create(data, ctx.get, ctx.fileHost, function (blob, errors) { if (errors && errors.length) { console.error(errors); } // TODO show user errors var dl = function () { saveAs(blob, data.folderName); @@ -332,8 +350,11 @@ define([ if (typeof progress.current !== "number") { return; } updateProgress.folderProgress(progress.current / progress.max); } + else if (state === "compressing") { + updateProgress.folderProgress(2); + } else if (state === "done") { - updateProgress.folderProgress(1); + updateProgress.folderProgress(3); } }); }; diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index c9e2eeacd..8a5be3764 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -47,8 +47,9 @@ define([ return 'cp-fileupload-element-' + String(Math.random()).substring(2); }; + Messages.fileTableHeader = "Downloads and uploads"; // XXX var tableHeader = h('div.cp-fileupload-header', [ - h('div.cp-fileupload-header-title', h('span', Messages.fileuploadHeader || 'Uploaded files')), + h('div.cp-fileupload-header-title', h('span', Messages.fileTableHeader)), h('div.cp-fileupload-header-close', h('span.fa.fa-times')), ]); @@ -262,7 +263,8 @@ define([ // name $('').append($link).appendTo($tr); // size - $('').text(UIElements.prettySize(estimate)).appendTo($tr); + var size = estimate ? UIElements.prettySize(estimate) : ''; + $(h('td.cp-fileupload-size')).text(size).appendTo($tr); // progress $('', {'class': 'cp-fileupload-table-progress'}).append($progressContainer).appendTo($tr); // cancel @@ -590,12 +592,11 @@ define([ queue.next(); }; - /* var cancelled = function () { $row.find('.cp-fileupload-table-cancel').addClass('cancelled').html('').append(h('span.fa.fa-minus')); queue.inProgress = false; queue.next(); - };*/ + }; /** * Update progress in the download panel, for downloading a file @@ -627,8 +628,21 @@ define([ * As updateDLProgress but for folders * @param {number} progressValue Progression of download, between 0 and 1 */ + Messages.download_zip = "Building ZIP file..."; // XXX + Messages.download_zip_file = "File {0}/{1}"; // XXX var updateProgress = function (progressValue) { var text = Math.round(progressValue*100) + '%'; + if (Array.isArray(data.list)) { + text = Messages._getKey('download_zip_file', [Math.round(progressValue * data.list.length), data.list.length]); + } + if (progressValue === 2) { + text = Messages.download_zip; + progressValue = 1; + } + if (progressValue === 3) { + text = "100%"; + progressValue = 1; + } $pv.text(text); $pb.css({ width: (progressValue * 100) + '%' @@ -641,7 +655,8 @@ define([ get: common.getPad, sframeChan: sframeChan, }; - downloadFunction(ctx, data, function (err, obj) { + + var dl = downloadFunction(ctx, data, function (err, obj) { $link.prepend($('', {'class': 'fa fa-external-link'})) .attr('href', '#') .click(function (e) { @@ -657,19 +672,17 @@ define([ folderProgress: updateProgress, }); -/* - var $cancel = $('', {'class': 'cp-fileupload-table-cancel-button fa fa-times'}).click(function () { - dl.cancel(); - $cancel.remove(); - $row.find('.cp-fileupload-table-progress-value').text(Messages.upload_cancelled); - cancelled(); - }); -*/ - - $row.find('.cp-fileupload-table-cancel') - .html('') - .append(h('span.fa.fa-minus')); - //.append($cancel); + var $cancel = $row.find('.cp-fileupload-table-cancel').html(''); + if (dl && dl.cancel) { + $('', { + 'class': 'cp-fileupload-table-cancel-button fa fa-times' + }).click(function () { + dl.cancel(); + $cancel.remove(); + $row.find('.cp-fileupload-table-progress-value').text(Messages.upload_cancelled); + cancelled(); + }).appendTo($cancel); + } }; File.downloadFile = function (fData, cb) { diff --git a/www/file/file-crypto.js b/www/file/file-crypto.js index a74439492..12453bb48 100644 --- a/www/file/file-crypto.js +++ b/www/file/file-crypto.js @@ -128,6 +128,11 @@ define([ metadata: undefined, }; + var cancelled = false; + var cancel = function () { + cancelled = true; + }; + var metaBox = new Uint8Array(u8.subarray(2, 2 + metadataLength)); var metaChunk = Nacl.secretbox.open(metaBox, nonce, key); @@ -168,6 +173,7 @@ define([ var chunks = []; var again = function () { + if (cancelled) { return; } takeChunk(function (e, plaintext) { if (e) { return setTimeout(function () { @@ -188,6 +194,10 @@ define([ }; again(); + + return { + cancel: cancel + }; }; // metadata