2017-06-02 19:38:05 +00:00
|
|
|
const FileReceiver = require('./fileReceiver');
|
2017-06-08 20:45:28 +00:00
|
|
|
const $ = require('jquery');
|
2017-06-01 22:10:00 +00:00
|
|
|
|
2017-06-06 21:24:51 +00:00
|
|
|
$(document).ready(function() {
|
2017-06-20 19:23:12 +00:00
|
|
|
$('#download-progress').hide();
|
2017-06-06 21:31:07 +00:00
|
|
|
$('#send-file').click(() => {
|
2017-06-06 21:23:10 +00:00
|
|
|
window.location.replace(`${window.location.origin}`);
|
2017-06-02 19:38:05 +00:00
|
|
|
});
|
2017-06-09 17:44:12 +00:00
|
|
|
const download = () => {
|
2017-06-06 21:23:10 +00:00
|
|
|
const fileReceiver = new FileReceiver();
|
2017-06-09 17:44:12 +00:00
|
|
|
const name = document.createElement('p');
|
2017-06-20 19:23:12 +00:00
|
|
|
const $btn = $('#download-btn');
|
2017-06-06 21:23:10 +00:00
|
|
|
|
|
|
|
fileReceiver.on('progress', percentComplete => {
|
2017-06-20 19:23:12 +00:00
|
|
|
$('#download-page-one').hide();
|
|
|
|
$('.send-new').hide();
|
|
|
|
$('#download-progress').show();
|
|
|
|
// update progress bar
|
|
|
|
document.querySelector('#progress-bar').style.setProperty('--progress', percentComplete+'%');
|
|
|
|
$('#progress-text').html(`${percentComplete}%`);
|
|
|
|
//on complete
|
2017-06-06 21:23:10 +00:00
|
|
|
if (percentComplete === 100) {
|
|
|
|
fileReceiver.removeAllListeners('progress');
|
2017-06-20 19:23:12 +00:00
|
|
|
$('#download-text').html('Download complete!');
|
|
|
|
$('.send-new').show();
|
|
|
|
$btn.text('Download complete!');
|
|
|
|
$btn.attr('disabled', 'true');
|
2017-06-06 21:23:10 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-06-06 21:24:51 +00:00
|
|
|
fileReceiver
|
2017-06-20 19:23:12 +00:00
|
|
|
.download()
|
|
|
|
.catch(() => {
|
|
|
|
$('.title').text(
|
|
|
|
'This link has expired or never existed in the first place.'
|
|
|
|
);
|
|
|
|
$('#download-btn').hide();
|
|
|
|
$('#expired-img').show();
|
|
|
|
console.log('The file has expired, or has already been deleted.');
|
|
|
|
return;
|
|
|
|
})
|
|
|
|
.then(([decrypted, fname]) => {
|
|
|
|
name.innerText = fname;
|
|
|
|
const dataView = new DataView(decrypted);
|
|
|
|
const blob = new Blob([dataView]);
|
|
|
|
const downloadUrl = URL.createObjectURL(blob);
|
2017-06-06 21:23:10 +00:00
|
|
|
|
2017-06-20 19:23:12 +00:00
|
|
|
const a = document.createElement('a');
|
|
|
|
a.href = downloadUrl;
|
|
|
|
if (window.navigator.msSaveBlob) {
|
|
|
|
// if we are in microsoft edge or IE
|
|
|
|
window.navigator.msSaveBlob(blob, fname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
a.download = fname;
|
|
|
|
document.body.appendChild(a);
|
|
|
|
a.click();
|
|
|
|
});
|
2017-06-06 21:23:10 +00:00
|
|
|
};
|
2017-06-02 19:38:05 +00:00
|
|
|
|
2017-06-06 21:23:10 +00:00
|
|
|
window.download = download;
|
|
|
|
});
|