Browse Source

Added download progress.

master
Teknikode 7 years ago
parent
commit
ada2d800cc
  1. 26
      Teknik/Areas/Upload/Scripts/Download.js
  2. 29
      Teknik/Areas/Upload/Scripts/Upload.js

26
Teknik/Areas/Upload/Scripts/Download.js

@ -17,10 +17,12 @@ function downloadFile() { @@ -17,10 +17,12 @@ function downloadFile() {
switch (e.data.cmd) {
case 'progress':
var percentComplete = Math.round(e.data.processed * 100 / e.data.total);
$("#progress").children('.progress-bar').css('width', (percentComplete) + '%');
$("#progress").children('.progress-bar').css('width', (percentComplete / 2) + 50 + '%');
$("#progress").children('.progress-bar').html(percentComplete + '% Decrypted');
break;
case 'finish':
$('#progress').children('.progress-bar').css('width', '100%');
$('#progress').children('.progress-bar').html('Complete');
if (fileType == null || fileType == '')
{
fileType = "application/octet-stream";
@ -56,5 +58,27 @@ function downloadFile() { @@ -56,5 +58,27 @@ function downloadFile() {
}
};
xhr.onprogress = function (e) {
if (e.lengthComputable) {
var percentComplete = Math.round(e.loaded * 100 / e.total);
$('#progress').children('.progress-bar').css('width', (percentComplete / 2) + '%');
$('#progress').children('.progress-bar').html(percentComplete + '% Downloaded');
}
};
xhr.onerror = function (e) {
$('#progress').children('.progress-bar').css('width', '100%');
$('#progress').children('.progress-bar').removeClass('progress-bar-success');
$('#progress').children('.progress-bar').addClass('progress-bar-danger');
$('#progress').children('.progress-bar').html('Download Failed');
};
xhr.onabort = function (e) {
$('#progress').children('.progress-bar').css('width', '100%');
$('#progress').children('.progress-bar').removeClass('progress-bar-success');
$('#progress').children('.progress-bar').addClass('progress-bar-warning');
$('#progress').children('.progress-bar').html('Download Failed');
};
xhr.send(fd);
}

29
Teknik/Areas/Upload/Scripts/Upload.js

@ -135,13 +135,6 @@ function encryptFile(file, callback) { @@ -135,13 +135,6 @@ function encryptFile(file, callback) {
var keyStr = randomString(24, '#aA');
var ivStr = randomString(24, '#aA');
// Let's grab the header and get the file type
var arr = (new Uint8Array(e.target.result)).subarray(0, 4);
var header = "";
for (var i = 0; i < arr.length; i++) {
header += arr[i].toString(16);
}
var worker = new Worker(encScriptSrc);
worker.addEventListener('message', function (e) {
@ -261,26 +254,4 @@ function uploadCanceled(fileID, evt) { @@ -261,26 +254,4 @@ function uploadCanceled(fileID, evt) {
$("#progress-" + fileID).children('.progress-bar').removeClass('progress-bar-success');
$("#progress-" + fileID).children('.progress-bar').addClass('progress-bar-warning');
$('#progress-' + fileID).children('.progress-bar').html('Upload Canceled');
}
function GetMIMEType(header)
{
var type = "";
switch (header) {
case "89504e47":
type = "image/png";
break;
case "47494638":
type = "image/gif";
break;
case "ffd8ffe0":
case "ffd8ffe1":
case "ffd8ffe2":
type = "image/jpeg";
break;
default:
type = "unknown"; // Or you can use the blob.type as fallback
break;
}
return type;
}
Loading…
Cancel
Save