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) {
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);
});
});
}
}

View File

@ -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) {

View File

@ -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 {

View File

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

View File

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