Improve download table

pull/1/head
yflory 4 years ago
parent f62f447711
commit a29b98783a

@ -296,6 +296,12 @@
return void CB(void 0, new Uint8Array(xhr.response)); return void CB(void 0, new Uint8Array(xhr.response));
}; };
xhr.send(null); xhr.send(null);
return {
cancel: function () {
if (xhr.abort) { xhr.abort(); }
}
};
}; };
Util.dataURIToBlob = function (dataURI) { Util.dataURIToBlob = function (dataURI) {

@ -4149,6 +4149,17 @@ define([
data.name = Util.fixFileName(folderName); data.name = Util.fixFileName(folderName);
data.folderName = Util.fixFileName(folderName) + '.zip'; 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) { APP.FM.downloadFolder(data, function (err, obj) {
console.log(err, obj); console.log(err, obj);
console.log('DONE'); console.log('DONE');

@ -53,9 +53,6 @@ define([
var _downloadFile = function (ctx, fData, cb, updateProgress) { var _downloadFile = function (ctx, fData, cb, updateProgress) {
var cancelled = false; var cancelled = false;
var cancel = function () {
cancelled = true;
};
var href = (fData.href && fData.href.indexOf('#') !== -1) ? fData.href : fData.roHref; var href = (fData.href && fData.href.indexOf('#') !== -1) ? fData.href : fData.roHref;
var parsed = Hash.parsePadUrl(href); var parsed = Hash.parsePadUrl(href);
var hash = parsed.hash; var hash = parsed.hash;
@ -63,10 +60,13 @@ define([
var secret = Hash.getSecrets('file', hash, fData.password); var secret = Hash.getSecrets('file', hash, fData.password);
var src = (ctx.fileHost || '') + Hash.getBlobPathFromHex(secret.channel); var src = (ctx.fileHost || '') + Hash.getBlobPathFromHex(secret.channel);
var key = secret.keys && secret.keys.cryptKey; 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 (cancelled) { return; }
if (err) { return void cb('E404'); } 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 (cancelled) { return; }
if (err) { return void cb(err); } if (err) { return void cb(err); }
if (!res.content) { return void cb('EEMPTY'); } if (!res.content) { return void cb('EEMPTY'); }
@ -78,8 +78,25 @@ define([
content: res.content, content: res.content,
download: dl download: dl
}); });
}, updateProgress && updateProgress.progress2); }, function (data) {
}, updateProgress && updateProgress.progress); 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 { return {
cancel: cancel cancel: cancel
}; };
@ -162,10 +179,10 @@ define([
if (ctx.stop) { return; } if (ctx.stop) { return; }
if (to) { clearTimeout(to); } if (to) { clearTimeout(to); }
//setTimeout(g, 2000); //setTimeout(g, 2000);
g();
w();
ctx.done++; ctx.done++;
ctx.updateProgress('download', {max: ctx.max, current: ctx.done}); ctx.updateProgress('download', {max: ctx.max, current: ctx.done});
g();
w();
}; };
var error = function (err) { var error = function (err) {
@ -312,13 +329,14 @@ define([
delete ctx.zip; delete ctx.zip;
}; };
return { return {
stop: stop stop: stop,
cancel: stop
}; };
}; };
var _downloadFolder = function (ctx, data, cb, updateProgress) { 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 if (errors && errors.length) { console.error(errors); } // TODO show user errors
var dl = function () { var dl = function () {
saveAs(blob, data.folderName); saveAs(blob, data.folderName);
@ -332,8 +350,11 @@ define([
if (typeof progress.current !== "number") { return; } if (typeof progress.current !== "number") { return; }
updateProgress.folderProgress(progress.current / progress.max); updateProgress.folderProgress(progress.current / progress.max);
} }
else if (state === "compressing") {
updateProgress.folderProgress(2);
}
else if (state === "done") { else if (state === "done") {
updateProgress.folderProgress(1); updateProgress.folderProgress(3);
} }
}); });
}; };

@ -47,8 +47,9 @@ define([
return 'cp-fileupload-element-' + String(Math.random()).substring(2); return 'cp-fileupload-element-' + String(Math.random()).substring(2);
}; };
Messages.fileTableHeader = "Downloads and uploads"; // XXX
var tableHeader = h('div.cp-fileupload-header', [ 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')), h('div.cp-fileupload-header-close', h('span.fa.fa-times')),
]); ]);
@ -262,7 +263,8 @@ define([
// name // name
$('<td>').append($link).appendTo($tr); $('<td>').append($link).appendTo($tr);
// size // size
$('<td>').text(UIElements.prettySize(estimate)).appendTo($tr); var size = estimate ? UIElements.prettySize(estimate) : '';
$(h('td.cp-fileupload-size')).text(size).appendTo($tr);
// progress // progress
$('<td>', {'class': 'cp-fileupload-table-progress'}).append($progressContainer).appendTo($tr); $('<td>', {'class': 'cp-fileupload-table-progress'}).append($progressContainer).appendTo($tr);
// cancel // cancel
@ -590,12 +592,11 @@ define([
queue.next(); queue.next();
}; };
/*
var cancelled = function () { var cancelled = function () {
$row.find('.cp-fileupload-table-cancel').addClass('cancelled').html('').append(h('span.fa.fa-minus')); $row.find('.cp-fileupload-table-cancel').addClass('cancelled').html('').append(h('span.fa.fa-minus'));
queue.inProgress = false; queue.inProgress = false;
queue.next(); queue.next();
};*/ };
/** /**
* Update progress in the download panel, for downloading a file * Update progress in the download panel, for downloading a file
@ -627,8 +628,21 @@ define([
* As updateDLProgress but for folders * As updateDLProgress but for folders
* @param {number} progressValue Progression of download, between 0 and 1 * @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 updateProgress = function (progressValue) {
var text = Math.round(progressValue*100) + '%'; 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); $pv.text(text);
$pb.css({ $pb.css({
width: (progressValue * 100) + '%' width: (progressValue * 100) + '%'
@ -641,7 +655,8 @@ define([
get: common.getPad, get: common.getPad,
sframeChan: sframeChan, sframeChan: sframeChan,
}; };
downloadFunction(ctx, data, function (err, obj) {
var dl = downloadFunction(ctx, data, function (err, obj) {
$link.prepend($('<span>', {'class': 'fa fa-external-link'})) $link.prepend($('<span>', {'class': 'fa fa-external-link'}))
.attr('href', '#') .attr('href', '#')
.click(function (e) { .click(function (e) {
@ -657,19 +672,17 @@ define([
folderProgress: updateProgress, folderProgress: updateProgress,
}); });
/* var $cancel = $row.find('.cp-fileupload-table-cancel').html('');
var $cancel = $('<span>', {'class': 'cp-fileupload-table-cancel-button fa fa-times'}).click(function () { if (dl && dl.cancel) {
dl.cancel(); $('<span>', {
$cancel.remove(); 'class': 'cp-fileupload-table-cancel-button fa fa-times'
$row.find('.cp-fileupload-table-progress-value').text(Messages.upload_cancelled); }).click(function () {
cancelled(); dl.cancel();
}); $cancel.remove();
*/ $row.find('.cp-fileupload-table-progress-value').text(Messages.upload_cancelled);
cancelled();
$row.find('.cp-fileupload-table-cancel') }).appendTo($cancel);
.html('') }
.append(h('span.fa.fa-minus'));
//.append($cancel);
}; };
File.downloadFile = function (fData, cb) { File.downloadFile = function (fData, cb) {

@ -128,6 +128,11 @@ define([
metadata: undefined, metadata: undefined,
}; };
var cancelled = false;
var cancel = function () {
cancelled = true;
};
var metaBox = new Uint8Array(u8.subarray(2, 2 + metadataLength)); var metaBox = new Uint8Array(u8.subarray(2, 2 + metadataLength));
var metaChunk = Nacl.secretbox.open(metaBox, nonce, key); var metaChunk = Nacl.secretbox.open(metaBox, nonce, key);
@ -168,6 +173,7 @@ define([
var chunks = []; var chunks = [];
var again = function () { var again = function () {
if (cancelled) { return; }
takeChunk(function (e, plaintext) { takeChunk(function (e, plaintext) {
if (e) { if (e) {
return setTimeout(function () { return setTimeout(function () {
@ -188,6 +194,10 @@ define([
}; };
again(); again();
return {
cancel: cancel
};
}; };
// metadata // metadata

Loading…
Cancel
Save