2017-06-02 19:38:05 +00:00
|
|
|
const FileReceiver = require('./fileReceiver');
|
2017-06-01 22:10:00 +00:00
|
|
|
|
2017-06-06 21:24:51 +00:00
|
|
|
$(document).ready(function() {
|
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-06 21:23:10 +00:00
|
|
|
let download = () => {
|
|
|
|
const fileReceiver = new FileReceiver();
|
2017-06-02 19:38:05 +00:00
|
|
|
|
2017-06-06 21:23:10 +00:00
|
|
|
let li = document.createElement('li');
|
|
|
|
let name = document.createElement('p');
|
|
|
|
let progress = document.createElement('p');
|
|
|
|
let btn = $('#download-btn');
|
|
|
|
|
|
|
|
// li.appendChild(name);
|
|
|
|
// li.appendChild(progress);
|
|
|
|
|
|
|
|
//document.getElementById('downloaded_files').appendChild(li);
|
|
|
|
|
|
|
|
fileReceiver.on('progress', percentComplete => {
|
|
|
|
progress.innerText = `Progress: ${percentComplete}%`;
|
|
|
|
|
|
|
|
if (percentComplete === 100) {
|
|
|
|
fileReceiver.removeAllListeners('progress');
|
|
|
|
btn.text('Download complete!');
|
2017-06-06 21:24:51 +00:00
|
|
|
btn.attr('disabled', 'true');
|
2017-06-06 21:23:10 +00:00
|
|
|
// let finished = document.createElement('p');
|
|
|
|
// finished.innerText = 'Your download has finished.';
|
|
|
|
// li.appendChild(finished);
|
|
|
|
|
|
|
|
// let close = document.createElement('button');
|
|
|
|
// close.innerText = 'Ok';
|
|
|
|
// close.addEventListener('click', () => {
|
|
|
|
// document.getElementById('downloaded_files').removeChild(li);
|
|
|
|
// });
|
|
|
|
// li.appendChild(close);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-06-06 21:24:51 +00:00
|
|
|
fileReceiver
|
|
|
|
.download()
|
|
|
|
.catch(err => {
|
|
|
|
$('.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.');
|
|
|
|
// document.getElementById('downloaded_files').removeChild(li);
|
|
|
|
return;
|
|
|
|
})
|
|
|
|
.then(([decrypted, fname]) => {
|
|
|
|
name.innerText = fname;
|
|
|
|
let dataView = new DataView(decrypted);
|
|
|
|
let blob = new Blob([dataView]);
|
|
|
|
let downloadUrl = URL.createObjectURL(blob);
|
2017-06-06 21:23:10 +00:00
|
|
|
|
2017-06-06 21:24:51 +00:00
|
|
|
let a = document.createElement('a');
|
|
|
|
a.href = downloadUrl;
|
|
|
|
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;
|
|
|
|
});
|