show error page if upload fails

This commit is contained in:
Daniela Arcese 2017-07-06 17:11:24 -04:00
parent cbd1daca1e
commit 63fe2c7099
3 changed files with 45 additions and 20 deletions

View File

@ -51,6 +51,9 @@ class FileSender extends EventEmitter {
reader.onload = function(event) {
resolve(new Uint8Array(this.result));
};
reader.onerror = function(event) {
reject(event.explicitOriginalTarget.error.name);
};
})
])
.then(([secretKey, plaintext]) => {

View File

@ -12,6 +12,7 @@ $(document).ready(function() {
$('#file-list').show();
$('#upload-progress').hide();
$('#share-link').hide();
$('#upload-error').hide();
if (localStorage.length === 0) {
toggleHeader();
@ -46,6 +47,7 @@ $(document).ready(function() {
$('#file-list').show();
$('#upload-progress').hide();
$('#share-link').hide();
$('#upload-error').hide();
$copyBtn.attr('disabled', false);
$copyBtn.html('Copy');
});
@ -66,6 +68,7 @@ $(document).ready(function() {
$('#page-one').hide();
$('#file-list').hide();
$('#upload-progress').show();
$('#upload-error').hide();
$('#upload-filename').innerHTML += file.name;
// update progress bar
document
@ -73,28 +76,36 @@ $(document).ready(function() {
.style.setProperty('--progress', percentComplete + '%');
$('#progress-text').html(`${percentComplete}%`);
});
fileSender.upload().then(info => {
const url = info.url.trim() + `#${info.secretKey}`.trim();
$('#link').attr('value', url);
const fileData = {
name: file.name,
fileId: info.fileId,
url: info.url,
secretKey: info.secretKey,
deleteToken: info.deleteToken,
creationDate: new Date(),
expiry: expiration
};
localStorage.setItem(info.fileId, JSON.stringify(fileData));
fileSender
.upload()
.then(info => {
const url = info.url.trim() + `#${info.secretKey}`.trim();
$('#link').attr('value', url);
const fileData = {
name: file.name,
fileId: info.fileId,
url: info.url,
secretKey: info.secretKey,
deleteToken: info.deleteToken,
creationDate: new Date(),
expiry: expiration
};
localStorage.setItem(info.fileId, JSON.stringify(fileData));
$('#page-one').hide();
$('#file-list').hide();
$('#upload-progress').hide();
$('#share-link').show();
$('#page-one').hide();
$('#file-list').hide();
$('#upload-progress').hide();
$('#share-link').show();
$('#upload-error').hide();
populateFileList(JSON.stringify(fileData));
notify('Your upload has finished.');
});
populateFileList(JSON.stringify(fileData));
notify('Your upload has finished.');
})
.catch(err => {
console.log('Upload error name: ' + err);
$('#page-one').hide();
$('#upload-error').show();
});
};
window.allowDrop = function(ev) {

View File

@ -89,6 +89,17 @@
Send another file
</div>
</div>
<div id="upload-error">
<div class="title">
Upload error<br>
This file cannot be uploaded!
</div>
<div class="send-new">
Send another file
</div>
</div>
</div>
</body>