Skip to content
This repository has been archived by the owner on May 22, 2021. It is now read-only.

changed to handle 404 during download, also removing progress listene… #42

Merged
merged 1 commit into from
Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion frontend/src/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ let download = () => {
progress.innerText = `Progress: ${percentComplete}%`;

if (percentComplete === 100) {
fileReceiver.removeAllListeners('progress');

let finished = document.createElement('p');
finished.innerText = 'Your download has finished.';
li.appendChild(finished);
Expand All @@ -28,7 +30,13 @@ let download = () => {
}
});

fileReceiver.download().then(([decrypted, fname]) => {
fileReceiver.download()
.catch((err) => {
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]);
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/fileReceiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class FileReceiver extends EventEmitter {
};

xhr.onload = function(e) {

if (xhr.status === 404) {
reject(new Error('The file has expired, or has already been deleted.'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need a return statement to prevent leaking into the code path(s) below?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, good catch @pdehaan

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added the return

}

let blob = new Blob([this.response]);
let fileReader = new FileReader();
fileReader.onload = function() {
Expand Down Expand Up @@ -52,7 +57,8 @@ class FileReceiver extends EventEmitter {
true,
['encrypt', 'decrypt']
)
]).then(([fdata, key]) => {
])
.then(([fdata, key]) => {
let salt = this.salt;
return Promise.all([
window.crypto.subtle.decrypt(
Expand Down