Add progress when creating a pad from a file

pull/1/head
yflory 4 years ago
parent 1ac6b84c6d
commit 3f88e29f30

@ -279,7 +279,7 @@ button:not(.btn).primary:hover{
var built = false; var built = false;
var types = ['less', 'drive', 'migrate', 'sf', 'team', 'pad', 'end']; var types = ['less', 'drive', 'migrate', 'sf', 'team', 'pad', 'end'];
var current; var current, progress;
var makeList = function (data) { var makeList = function (data) {
var c = types.indexOf(data.type); var c = types.indexOf(data.type);
current = c; current = c;
@ -295,7 +295,7 @@ button:not(.btn).primary:hover{
}; };
var list = '<ul>'; var list = '<ul>';
types.forEach(function (el, i) { types.forEach(function (el, i) {
if (i >= 6) { return; } if (el === "end") { return; }
list += getLi(i); list += getLi(i);
}); });
list += '</ul>'; list += '</ul>';
@ -303,7 +303,7 @@ button:not(.btn).primary:hover{
}; };
var makeBar = function (data) { var makeBar = function (data) {
var c = types.indexOf(data.type); var c = types.indexOf(data.type);
var l = types.length; var l = types.length - 1; // don't count "end" as a type
var progress = Math.min(data.progress, 100); var progress = Math.min(data.progress, 100);
var p = (progress / l) + (100 * c / l); var p = (progress / l) + (100 * c / l);
var bar = '<div class="cp-loading-progress-bar">'+ var bar = '<div class="cp-loading-progress-bar">'+
@ -315,8 +315,13 @@ button:not(.btn).primary:hover{
var hasErrored = false; var hasErrored = false;
var updateLoadingProgress = function (data) { var updateLoadingProgress = function (data) {
if (!built || !data) { return; } if (!built || !data) { return; }
// Make sure progress doesn't go backward
var c = types.indexOf(data.type); var c = types.indexOf(data.type);
if (c < current) { return console.error(data); } if (c < current) { return console.error(data); }
if (c === current && progress > data.progress) { return console.error(data); }
progress = data.progress;
try { try {
document.querySelector('.cp-loading-spinner-container').style.display = 'none'; document.querySelector('.cp-loading-spinner-container').style.display = 'none';
document.querySelector('.cp-loading-progress-list').innerHTML = makeList(data); document.querySelector('.cp-loading-progress-list').innerHTML = makeList(data);

@ -701,7 +701,7 @@ define([
}); });
}; };
common.useFile = function (Crypt, cb, optsPut) { common.useFile = function (Crypt, cb, optsPut, onProgress) {
var fileHost = Config.fileHost || window.location.origin; var fileHost = Config.fileHost || window.location.origin;
var data = common.fromFileData; var data = common.fromFileData;
var parsed = Hash.parsePadUrl(data.href); var parsed = Hash.parsePadUrl(data.href);
@ -758,7 +758,9 @@ define([
return void cb(err); return void cb(err);
} }
u8 = _u8; u8 = _u8;
})); }), function (progress) {
onProgress(progress * 50);
});
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
require(["/file/file-crypto.js"], waitFor(function (FileCrypto) { require(["/file/file-crypto.js"], waitFor(function (FileCrypto) {
FileCrypto.decrypt(u8, key, waitFor(function (err, _res) { FileCrypto.decrypt(u8, key, waitFor(function (err, _res) {
@ -767,7 +769,9 @@ define([
return void cb(err); return void cb(err);
} }
res = _res; res = _res;
})); }), function (progress) {
onProgress(50 + progress * 50);
});
})); }));
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
var ext = Util.parseFilename(data.title).ext; var ext = Util.parseFilename(data.title).ext;

@ -1802,7 +1802,12 @@ define([
} }
startRealtime(); startRealtime();
cb(); cb();
}, cryptputCfg); }, cryptputCfg, function (progress) {
sframeChan.event('EV_LOADING_INFO', {
type: 'pad',
progress: progress
});
});
return; return;
} }
// Start realtime outside the iframe and callback // Start realtime outside the iframe and callback

Loading…
Cancel
Save