Browse Source

Added download progress.

tags/2.0.3
Teknikode 4 years ago
parent
commit
ada2d800cc
2 changed files with 25 additions and 30 deletions
  1. 25
    1
      Teknik/Areas/Upload/Scripts/Download.js
  2. 0
    29
      Teknik/Areas/Upload/Scripts/Upload.js

+ 25
- 1
Teknik/Areas/Upload/Scripts/Download.js View File

@@ -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() {
}
};

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);
}

+ 0
- 29
Teknik/Areas/Upload/Scripts/Upload.js View File

@@ -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) {
$("#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