From dea589df1417c8b280df5a64759e7676c806c8a2 Mon Sep 17 00:00:00 2001 From: Daniela Arcese Date: Fri, 9 Jun 2017 09:45:06 -0400 Subject: [PATCH] making changes --- frontend/src/fileSender.js | 92 +++++++++++++++++++------------------- frontend/src/upload.js | 18 +++++--- public/main.css | 10 +---- views/download.handlebars | 5 +-- views/index.handlebars | 3 -- 5 files changed, 60 insertions(+), 68 deletions(-) diff --git a/frontend/src/fileSender.js b/frontend/src/fileSender.js index 69fe597a..5b50b0da 100644 --- a/frontend/src/fileSender.js +++ b/frontend/src/fileSender.js @@ -11,7 +11,7 @@ class FileSender extends EventEmitter { static delete(fileId, token) { return new Promise((resolve, reject) => { if (!fileId || !token) { - return resolve(); + return reject(); } let xhr = new XMLHttpRequest(); xhr.open('post', '/delete/' + fileId, true); @@ -51,55 +51,55 @@ class FileSender extends EventEmitter { }; }) ]) - .then(([secretKey, plaintext]) => { - return Promise.all([ - window.crypto.subtle.encrypt( - { - name: 'AES-CBC', - iv: this.iv - }, - secretKey, - plaintext - ), - window.crypto.subtle.exportKey('jwk', secretKey) - ]); - }) - .then(([encrypted, keydata]) => { - return new Promise((resolve, reject) => { - let file = this.file; - let fileId = ivToStr(this.iv); - let dataView = new DataView(encrypted); - let blob = new Blob([dataView], { type: file.type }); - let fd = new FormData(); - fd.append('fname', file.name); - fd.append('data', blob, file.name); + .then(([secretKey, plaintext]) => { + return Promise.all([ + window.crypto.subtle.encrypt( + { + name: 'AES-CBC', + iv: this.iv + }, + secretKey, + plaintext + ), + window.crypto.subtle.exportKey('jwk', secretKey) + ]); + }) + .then(([encrypted, keydata]) => { + return new Promise((resolve, reject) => { + let file = this.file; + let fileId = ivToStr(this.iv); + let dataView = new DataView(encrypted); + let blob = new Blob([dataView], { type: file.type }); + let fd = new FormData(); + fd.append('fname', file.name); + fd.append('data', blob, file.name); - let xhr = new XMLHttpRequest(); + let xhr = new XMLHttpRequest(); - xhr.upload.addEventListener('progress', e => { - if (e.lengthComputable) { - let percentComplete = Math.floor(e.loaded / e.total * 100); - this.emit('progress', percentComplete); - } - }); - - xhr.onreadystatechange = () => { - if (xhr.readyState == XMLHttpRequest.DONE) { - // uuid field and url field - let responseObj = JSON.parse(xhr.responseText); - resolve({ - url: responseObj.url, - fileId: fileId, - secretKey: keydata.k, - deleteToken: responseObj.uuid - }); - } - }; - - xhr.open('post', '/upload/' + fileId, true); - xhr.send(fd); + xhr.upload.addEventListener('progress', e => { + if (e.lengthComputable) { + let percentComplete = Math.floor(e.loaded / e.total * 100); + this.emit('progress', percentComplete); + } }); + + xhr.onreadystatechange = () => { + if (xhr.readyState == XMLHttpRequest.DONE) { + // uuid field and url field + let responseObj = JSON.parse(xhr.responseText); + resolve({ + url: responseObj.url, + fileId: fileId, + secretKey: keydata.k, + deleteToken: responseObj.uuid + }); + } + }; + + xhr.open('post', '/upload/' + fileId, true); + xhr.send(fd); }); + }); } } diff --git a/frontend/src/upload.js b/frontend/src/upload.js index 74fb33e1..37b8740e 100644 --- a/frontend/src/upload.js +++ b/frontend/src/upload.js @@ -42,7 +42,7 @@ $(document).ready(function() { } else { file = event.target.files[0]; } - let fileList = $('#uploaded-files'); + let $fileList = $('#uploaded-files'); let row = document.createElement('tr'); let name = document.createElement('td'); let link = document.createElement('td'); @@ -74,7 +74,7 @@ $(document).ready(function() { $(popupDiv).append($popupText); del.appendChild(popupDiv); row.appendChild(del); - fileList.append(row); //add row to table + $fileList.append(row); //add row to table const fileSender = new FileSender(file); fileSender.on('progress', percentComplete => { @@ -91,28 +91,32 @@ $(document).ready(function() { localStorage.setItem(info.fileId, info.deleteToken); // delete file - console.log($popupText.first()); $popupText.find('.del-file').click(e => { FileSender.delete( info.fileId, localStorage.getItem(info.fileId) - ).then(() => { - e.target.parentNode.parentNode.parentNode.parentNode.remove(); + ).then(() => { + // + $(e.target).parents('tr').remove(); localStorage.removeItem(info.fileId); }); }); // show popup btn.addEventListener('click', e => { - $popupText.toggleClass('show'); + toggleShow(); }); // hide popup $popupText.find('.nvm').click(e => { - $popupText.toggleClass('show'); + toggleShow(); }); $('#upload-progress').hide(); $('#share-link').show(); }); + + function toggleShow(){ + $popupText.toggleClass('show'); + } }; window.allowDrop = function(ev) { diff --git a/public/main.css b/public/main.css index 20fb6242..9a7d4504 100644 --- a/public/main.css +++ b/public/main.css @@ -143,17 +143,9 @@ td { border-color: #555 transparent transparent transparent; } -/* Toggle this class when clicking on the popup container (hide and show the popup) */ .popup .show { visibility: visible; - -webkit-animation: fadeIn 1s; - animation: fadeIn 1s -} - -/* Add animation (fade in the popup) */ -@-webkit-keyframes fadeIn { - from {opacity: 0;} - to {opacity: 1;} + animation: fadeIn 1s; } @keyframes fadeIn { diff --git a/views/download.handlebars b/views/download.handlebars index 516172c3..5aee5344 100644 --- a/views/download.handlebars +++ b/views/download.handlebars @@ -13,10 +13,9 @@
{{#if filename}}
- Your friend is sending you a file: + Your friend is sending you a file:
+ {{{filename}}} ({{{filesize}}})
- - {{{filename}}} ({{{filesize}}})