making changes

This commit is contained in:
Daniela Arcese 2017-06-09 09:45:06 -04:00
parent 42be528c90
commit dea589df14
5 changed files with 60 additions and 68 deletions

View File

@ -11,7 +11,7 @@ class FileSender extends EventEmitter {
static delete(fileId, token) { static delete(fileId, token) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!fileId || !token) { if (!fileId || !token) {
return resolve(); return reject();
} }
let xhr = new XMLHttpRequest(); let xhr = new XMLHttpRequest();
xhr.open('post', '/delete/' + fileId, true); xhr.open('post', '/delete/' + fileId, true);
@ -51,55 +51,55 @@ class FileSender extends EventEmitter {
}; };
}) })
]) ])
.then(([secretKey, plaintext]) => { .then(([secretKey, plaintext]) => {
return Promise.all([ return Promise.all([
window.crypto.subtle.encrypt( window.crypto.subtle.encrypt(
{ {
name: 'AES-CBC', name: 'AES-CBC',
iv: this.iv iv: this.iv
}, },
secretKey, secretKey,
plaintext plaintext
), ),
window.crypto.subtle.exportKey('jwk', secretKey) window.crypto.subtle.exportKey('jwk', secretKey)
]); ]);
}) })
.then(([encrypted, keydata]) => { .then(([encrypted, keydata]) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let file = this.file; let file = this.file;
let fileId = ivToStr(this.iv); let fileId = ivToStr(this.iv);
let dataView = new DataView(encrypted); let dataView = new DataView(encrypted);
let blob = new Blob([dataView], { type: file.type }); let blob = new Blob([dataView], { type: file.type });
let fd = new FormData(); let fd = new FormData();
fd.append('fname', file.name); fd.append('fname', file.name);
fd.append('data', blob, file.name); fd.append('data', blob, file.name);
let xhr = new XMLHttpRequest(); let xhr = new XMLHttpRequest();
xhr.upload.addEventListener('progress', e => { xhr.upload.addEventListener('progress', e => {
if (e.lengthComputable) { if (e.lengthComputable) {
let percentComplete = Math.floor(e.loaded / e.total * 100); let percentComplete = Math.floor(e.loaded / e.total * 100);
this.emit('progress', percentComplete); 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.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);
}); });
});
} }
} }

View File

@ -42,7 +42,7 @@ $(document).ready(function() {
} else { } else {
file = event.target.files[0]; file = event.target.files[0];
} }
let fileList = $('#uploaded-files'); let $fileList = $('#uploaded-files');
let row = document.createElement('tr'); let row = document.createElement('tr');
let name = document.createElement('td'); let name = document.createElement('td');
let link = document.createElement('td'); let link = document.createElement('td');
@ -74,7 +74,7 @@ $(document).ready(function() {
$(popupDiv).append($popupText); $(popupDiv).append($popupText);
del.appendChild(popupDiv); del.appendChild(popupDiv);
row.appendChild(del); row.appendChild(del);
fileList.append(row); //add row to table $fileList.append(row); //add row to table
const fileSender = new FileSender(file); const fileSender = new FileSender(file);
fileSender.on('progress', percentComplete => { fileSender.on('progress', percentComplete => {
@ -91,28 +91,32 @@ $(document).ready(function() {
localStorage.setItem(info.fileId, info.deleteToken); localStorage.setItem(info.fileId, info.deleteToken);
// delete file // delete file
console.log($popupText.first());
$popupText.find('.del-file').click(e => { $popupText.find('.del-file').click(e => {
FileSender.delete( FileSender.delete(
info.fileId, info.fileId,
localStorage.getItem(info.fileId) localStorage.getItem(info.fileId)
).then(() => { ).then(() => {
e.target.parentNode.parentNode.parentNode.parentNode.remove(); //
$(e.target).parents('tr').remove();
localStorage.removeItem(info.fileId); localStorage.removeItem(info.fileId);
}); });
}); });
// show popup // show popup
btn.addEventListener('click', e => { btn.addEventListener('click', e => {
$popupText.toggleClass('show'); toggleShow();
}); });
// hide popup // hide popup
$popupText.find('.nvm').click(e => { $popupText.find('.nvm').click(e => {
$popupText.toggleClass('show'); toggleShow();
}); });
$('#upload-progress').hide(); $('#upload-progress').hide();
$('#share-link').show(); $('#share-link').show();
}); });
function toggleShow(){
$popupText.toggleClass('show');
}
}; };
window.allowDrop = function(ev) { window.allowDrop = function(ev) {

View File

@ -143,17 +143,9 @@ td {
border-color: #555 transparent transparent transparent; border-color: #555 transparent transparent transparent;
} }
/* Toggle this class when clicking on the popup container (hide and show the popup) */
.popup .show { .popup .show {
visibility: visible; visibility: visible;
-webkit-animation: fadeIn 1s; animation: fadeIn 1s;
animation: fadeIn 1s
}
/* Add animation (fade in the popup) */
@-webkit-keyframes fadeIn {
from {opacity: 0;}
to {opacity: 1;}
} }
@keyframes fadeIn { @keyframes fadeIn {

View File

@ -13,10 +13,9 @@
<div id="download"> <div id="download">
{{#if filename}} {{#if filename}}
<div class="title"> <div class="title">
Your friend is sending you a file: Your friend is sending you a file: <br>
{{{filename}}} ({{{filesize}}})
</div> </div>
<span> {{{filename}}} ({{{filesize}}})
<div class="share-window"> <div class="share-window">
<button id="download-btn" onclick="download()">Download File</button> <button id="download-btn" onclick="download()">Download File</button>

View File

@ -41,9 +41,6 @@
<th width=18%>Expires in</th> <th width=18%>Expires in</th>
<th width=7%>Delete</th> <th width=7%>Delete</th>
</tr> </tr>
<!-- <div class="popup">
<span class="popuptext" id="myPopup">Popup text...</span>
</div> -->
</table> </table>
</div> </div>