This commit is contained in:
Daniela Arcese 2017-06-23 15:17:47 -04:00
parent b673fad703
commit aa8c1afa9d
5 changed files with 44 additions and 47 deletions

View File

@ -4,7 +4,6 @@ const $ = require('jquery');
const Raven = window.Raven; const Raven = window.Raven;
$(document).ready(function() { $(document).ready(function() {
$('#download-progress').hide(); $('#download-progress').hide();
$('#send-file').click(() => { $('#send-file').click(() => {
@ -63,7 +62,7 @@ $(document).ready(function() {
document.body.appendChild(a); document.body.appendChild(a);
a.click(); a.click();
}) })
.catch(err => { .catch(err => {
Raven.captureException(err); Raven.captureException(err);
return Promise.reject(err); return Promise.reject(err);
}); });

View File

@ -64,26 +64,26 @@ class FileReceiver extends EventEmitter {
['encrypt', 'decrypt'] ['encrypt', 'decrypt']
) )
]) ])
.then(([fdata, key]) => { .then(([fdata, key]) => {
const salt = this.salt; const salt = this.salt;
return Promise.all([ return Promise.all([
window.crypto.subtle.decrypt( window.crypto.subtle.decrypt(
{ {
name: 'AES-CBC', name: 'AES-CBC',
iv: salt iv: salt
}, },
key, key,
fdata.data fdata.data
), ),
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
resolve(fdata.fname); resolve(fdata.fname);
}) })
]); ]);
}) })
.catch(err => { .catch(err => {
Raven.captureException(err); Raven.captureException(err);
return Promise.reject(err); return Promise.reject(err);
}); });
} }
} }

View File

@ -66,8 +66,8 @@ class FileSender extends EventEmitter {
window.crypto.subtle.exportKey('jwk', secretKey) window.crypto.subtle.exportKey('jwk', secretKey)
]); ]);
}) })
.catch(err => { .catch(err => {
Raven.captureException(err) Raven.captureException(err);
return Promise.reject(err); return Promise.reject(err);
}) })
.then(([encrypted, keydata]) => { .then(([encrypted, keydata]) => {
@ -106,8 +106,8 @@ class FileSender extends EventEmitter {
xhr.send(fd); xhr.send(fd);
}); });
}) })
.catch(err => { .catch(err => {
Raven.captureException(err) Raven.captureException(err);
return Promise.reject(err); return Promise.reject(err);
}); });
} }

View File

@ -15,7 +15,7 @@ $(document).ready(function() {
$('#upload-progress').hide(); $('#upload-progress').hide();
$('#share-link').hide(); $('#share-link').hide();
for(let i=0; i<localStorage.length; i++) { for (let i = 0; i < localStorage.length; i++) {
let id = localStorage.key(i); let id = localStorage.key(i);
populateFileList(localStorage.getItem(id)); populateFileList(localStorage.getItem(id));
} }
@ -68,7 +68,6 @@ $(document).ready(function() {
.querySelector('#progress-bar') .querySelector('#progress-bar')
.style.setProperty('--progress', percentComplete + '%'); .style.setProperty('--progress', percentComplete + '%');
$('#progress-text').html(`${percentComplete}%`); $('#progress-text').html(`${percentComplete}%`);
}); });
fileSender.upload().then(info => { fileSender.upload().then(info => {
const url = info.url.trim() + `#${info.secretKey}`.trim(); const url = info.url.trim() + `#${info.secretKey}`.trim();
@ -97,14 +96,13 @@ $(document).ready(function() {
//load previous uploads //load previous uploads
function checkUploads(file) { function checkUploads(file) {
return new Promise ((resolve, reject) => { return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.responseType = 'json'; xhr.responseType = 'json';
xhr.onreadystatechange = () => { xhr.onreadystatechange = () => {
if (xhr.readyState == 4 && xhr.status == 200) { if (xhr.readyState == 4 && xhr.status == 200) {
resolve(xhr.response); resolve(xhr.response);
} } else if (xhr.readyState == 4 && xhr.status == 404) {
else if (xhr.readyState == 4 && xhr.status == 404) {
reject('error code: ' + xhr.status); reject('error code: ' + xhr.status);
} }
}; };
@ -113,11 +111,14 @@ $(document).ready(function() {
}; };
xhr.open('get', '/file/' + id, true); xhr.open('get', '/file/' + id, true);
xhr.send(); xhr.send();
}).then (response => { }).then(
populateFileList(response, url); response => {
}, error => { populateFileList(response, url);
console.log(error); },
}); error => {
console.log(error);
}
);
} }
//update file table with current files in localStorage //update file table with current files in localStorage
@ -142,7 +143,7 @@ $(document).ready(function() {
// create delete button // create delete button
btn.innerHTML = 'x'; btn.innerHTML = 'x';
btn.classList.add('delete-btn'); btn.classList.add('delete-btn');
link.innerHTML = file.url.trim() + `#${file.secretKey}`.trim();; link.innerHTML = file.url.trim() + `#${file.secretKey}`.trim();
// create popup // create popup
popupDiv.classList.add('popup'); popupDiv.classList.add('popup');
@ -152,10 +153,7 @@ $(document).ready(function() {
// delete file // delete file
$popupText.find('.del-file').click(e => { $popupText.find('.del-file').click(e => {
FileSender.delete( FileSender.delete(file.fileId, file.deleteToken).then(() => {
file.fileId,
file.deleteToken
).then(() => {
$(e.target).parents('tr').remove(); $(e.target).parents('tr').remove();
localStorage.removeItem(file.fileId); localStorage.removeItem(file.fileId);
}); });
@ -173,11 +171,11 @@ $(document).ready(function() {
// show popup // show popup
del.addEventListener('click', toggleShow); del.addEventListener('click', toggleShow);
// hide popup // hide popup
$popupText.find('.nvm').click(function(e){ $popupText.find('.nvm').click(function(e) {
e.stopPropagation(); e.stopPropagation();
toggleShow(); toggleShow();
}); });
$popupText.click(function(e){ $popupText.click(function(e) {
e.stopPropagation(); e.stopPropagation();
}); });
@ -187,5 +185,4 @@ $(document).ready(function() {
$popupText.toggleClass('show'); $popupText.toggleClass('show');
} }
} }
}); });

View File

@ -60,11 +60,12 @@ app.get('/file/:id', (req, res) => {
name: filename, name: filename,
filesize: bytes(contentLength), filesize: bytes(contentLength),
fileId: id fileId: id
}) });
}).catch(() => { })
.catch(() => {
console.log('error retrieving id ' + id); console.log('error retrieving id ' + id);
}); });
}) });
}); });
app.get('/download/:id', (req, res) => { app.get('/download/:id', (req, res) => {