2017-06-02 03:59:27 +00:00
|
|
|
const FileSender = require('./fileSender');
|
2017-06-01 22:10:00 +00:00
|
|
|
|
2017-06-01 22:12:30 +00:00
|
|
|
let onChange = event => {
|
2017-06-02 03:59:27 +00:00
|
|
|
const file = event.target.files[0];
|
2017-06-01 22:10:00 +00:00
|
|
|
|
2017-06-05 14:25:10 +00:00
|
|
|
let fileList = document.getElementById("uploaded-files");
|
|
|
|
let row = document.createElement("tr");
|
|
|
|
let name = document.createElement("td");
|
|
|
|
let link = document.createElement("td");
|
|
|
|
let expiry = document.createElement("td");
|
2017-06-01 22:12:30 +00:00
|
|
|
|
2017-06-05 14:25:10 +00:00
|
|
|
let cellText = document.createTextNode(file.name);
|
2017-06-01 22:10:00 +00:00
|
|
|
|
2017-06-01 17:54:17 +00:00
|
|
|
name.appendChild(cellText);
|
2017-06-01 22:10:00 +00:00
|
|
|
|
2017-06-05 14:25:10 +00:00
|
|
|
let progress = document.createElement("p");
|
2017-06-01 17:54:17 +00:00
|
|
|
|
|
|
|
row.appendChild(name);
|
|
|
|
row.appendChild(link);
|
|
|
|
row.appendChild(expiry);
|
2017-06-05 14:25:10 +00:00
|
|
|
fileList.appendChild(row);
|
2017-06-01 22:10:00 +00:00
|
|
|
|
2017-06-02 03:59:27 +00:00
|
|
|
const fileSender = new FileSender(file);
|
|
|
|
fileSender.on('progress', percentComplete => {
|
|
|
|
progress.innerText = `Progress: ${percentComplete}%`;
|
|
|
|
});
|
|
|
|
fileSender.upload().then(info => {
|
2017-06-02 19:49:56 +00:00
|
|
|
const url = `${window.location
|
|
|
|
.origin}/download/${info.fileId}/#${info.secretKey}`;
|
2017-06-05 13:48:57 +00:00
|
|
|
link.innerHTML = url;
|
2017-06-02 03:59:27 +00:00
|
|
|
localStorage.setItem(info.fileId, info.deleteToken);
|
2017-06-05 14:25:10 +00:00
|
|
|
let del = document.createElement("td");
|
|
|
|
let btn = document.createElement("button");
|
2017-06-01 17:54:17 +00:00
|
|
|
btn.innerHTML = "x";
|
2017-06-05 14:25:10 +00:00
|
|
|
btn.classList.add('delete-btn');
|
2017-06-02 03:59:27 +00:00
|
|
|
btn.addEventListener('click', () => {
|
|
|
|
FileSender.delete(
|
|
|
|
info.fileId,
|
|
|
|
localStorage.getItem(info.fileId)
|
|
|
|
).then(() => {
|
2017-06-05 14:25:10 +00:00
|
|
|
fileList.removeChild(row);
|
2017-06-02 03:59:27 +00:00
|
|
|
localStorage.removeItem(info.fileId);
|
|
|
|
});
|
|
|
|
});
|
2017-06-01 17:54:17 +00:00
|
|
|
del.appendChild(btn);
|
|
|
|
row.appendChild(del);
|
2017-06-02 03:59:27 +00:00
|
|
|
});
|
2017-06-01 22:12:30 +00:00
|
|
|
};
|
2017-06-01 22:10:00 +00:00
|
|
|
|
2017-06-02 03:59:27 +00:00
|
|
|
window.onChange = onChange;
|