1
0
mirror of https://gitlab.com/timvisee/send.git synced 2024-11-10 05:02:45 +01:00
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;
$(document).ready(function() {
$('#download-progress').hide();
$('#send-file').click(() => {
@ -63,7 +62,7 @@ $(document).ready(function() {
document.body.appendChild(a);
a.click();
})
.catch(err => {
.catch(err => {
Raven.captureException(err);
return Promise.reject(err);
});

View File

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

View File

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

View File

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

View File

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