From a0d85c6e34e69b03b67daafb667295ba3e6e8562 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Wed, 14 Aug 2019 17:27:37 +0200 Subject: [PATCH] Export folder is now working in drive --- www/common/make-backup.js | 26 ++++++++++++++++++++-- www/common/sframe-common-file.js | 37 +++++++++++++++++++++++--------- www/drive/inner.js | 29 ++++++++----------------- 3 files changed, 60 insertions(+), 32 deletions(-) diff --git a/www/common/make-backup.js b/www/common/make-backup.js index 3e9426be5..d9fb62d96 100644 --- a/www/common/make-backup.js +++ b/www/common/make-backup.js @@ -282,11 +282,12 @@ define([ max: 0, done: 0 }; + var filesData = data.sharedFolderId && ctx.sf[data.sharedFolderId] ? ctx.sf[data.sharedFolderId].filesData : ctx.data.filesData; progress('reading', -1); nThen(function (waitFor) { ctx.waitFor = waitFor; var zipRoot = ctx.zip.folder('Root'); - makeFolder(ctx, ctx.folder, zipRoot, ctx.data.filesData); + makeFolder(ctx, ctx.folder, zipRoot, filesData); progress('download', {}); }).nThen(function () { console.log(ctx.zip); @@ -308,11 +309,32 @@ define([ }; + var _downloadFolder = function (ctx, data, cb, updateProgress) { + create(data, ctx.get, function (blob, errors) { + console.error(errors); // TODO show user errors + var dl = function () { + saveAs(blob, data.folderName); + }; + cb(null, {download: dl}); + }, function (state, progress) { + if (state === "reading") { + updateProgress.folderProgress(0); + } + if (state === "download") { + if (typeof progress.current !== "number") { return; } + updateProgress.folderProgress(progress.current / progress.max); + } + else if (state === "done") { + updateProgress.folderProgress(1); + } + }); + }; + return { create: create, downloadFile: _downloadFile, downloadPad: _downloadPad, - + downloadFolder: _downloadFolder, }; }); diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index 0836a8553..32f031010 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -471,7 +471,7 @@ define([ width: progressValue * $pc.width() + 'px' }); }; - var updateProgress = function (progressValue) { + var updateDecryptProgress = function (progressValue) { var text = Math.round(progressValue*100) + '%'; text += progressValue === 1 ? '' : ' (' + Messages.download_step2 + '...)'; $pv.text(text); @@ -479,12 +479,19 @@ define([ width: progressValue * $pc.width()+'px' }); }; + var updateProgress = function (progressValue) { + var text = Math.round(progressValue*100) + '%'; + $pv.text(text); + $pb.css({ + width: progressValue * $pc.width()+'px' + }); + }; var ctx = { get: common.getPad, sframeChan: sframeChan, }; - var dl = downloadFunction(ctx, data, function (err, obj) { + downloadFunction(ctx, data, function (err, obj) { $link.prepend($('', {'class': 'fa fa-external-link'})) .attr('href', '#') .click(function (e) { @@ -496,16 +503,18 @@ define([ cb(err, obj); }, { progress: updateDLProgress, - progress2: updateProgress, + progress2: updateDecryptProgress, + 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); - done(); - }); - $row.find('.cp-fileupload-table-cancel').html('').append($cancel); +// 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); +// done(); +// }); +// $row.find('.cp-fileupload-table-cancel').html('').append($cancel); + $row.find('.cp-fileupload-table-cancel').html(''); }; @@ -528,6 +537,14 @@ define([ }); }; + File.downloadFolder = function (data, cb) { + queue.push({ + dl: function (file) { updateProgressbar(file, data, MakeBackup.downloadFolder, cb); }, + size: 0, + name: data.folderName, + }); + }; + return File; }; diff --git a/www/drive/inner.js b/www/drive/inner.js index 1745fa2f7..c75a9a1a6 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -3597,19 +3597,16 @@ define([ }; - var downloadFolder = function (folderElement, folderName) { - console.warn("downloadFolder"); + var downloadFolder = function (folderElement, folderName, sfId) { var todo = function (data) { data.folder = folderElement; - folderName = Util.fixFileName(folderName) + '.zip'; - console.log("data", data); - console.log("folderName", folderName); - - Backup.create(data, common.getPad, function (blob, errors) { - console.log("blob", blob); - window.saveAs(blob, folderName); - console.error(errors); - }, function () {}); + data.sharedFolderId = sfId; + data.folderName = Util.fixFileName(folderName) + '.zip'; + + APP.FM.downloadFolder(data, function (err, obj) { + console.log(err, obj); + console.log('DONE'); + }); }; todo({ uo: proxy, @@ -3711,29 +3708,21 @@ define([ if (paths.length !== 1) { return; } var path = paths[0]; el = manager.find(path.path); - console.log("el", el); - console.log('path', path); // folder if (manager.isFolder(el)) { // folder var name, folderEl; if (!manager.isSharedFolder(el)) { - console.log("--isFolder--"); name = path.path[path.path.length - 1]; - console.log('name', name); folderEl = el; downloadFolder(folderEl, name); } // shared folder else { - console.log("--isSharedFolder--"); data = manager.getSharedFolderData(el); name = data.title; folderEl = manager.find(path.path.concat("root")); - console.log("folderEl", folderEl); - console.log("data:", data); - console.log('name', name); - downloadFolder(folderEl, name); + downloadFolder(folderEl, name, el); } } // file