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-01 17:54:17 +00:00
|
|
|
var row = document.createElement("tr");
|
|
|
|
var name = document.createElement("td");
|
|
|
|
var link = document.createElement("td");
|
|
|
|
var expiry = document.createElement("td");
|
2017-06-01 22:12:30 +00:00
|
|
|
|
2017-06-01 17:54:17 +00:00
|
|
|
var 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-01 17:54:17 +00:00
|
|
|
var progress = document.createElement("p");
|
|
|
|
|
|
|
|
row.appendChild(name);
|
|
|
|
row.appendChild(link);
|
|
|
|
row.appendChild(expiry);
|
|
|
|
document.getElementById("uploaded-files").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-01 17:54:17 +00:00
|
|
|
var del = document.createElement("td");
|
|
|
|
var btn = document.createElement("button");
|
|
|
|
btn.innerHTML = "x";
|
|
|
|
btn.style = "padding: 0; border: none; background: none; cursor: pointer"
|
2017-06-02 03:59:27 +00:00
|
|
|
btn.addEventListener('click', () => {
|
|
|
|
FileSender.delete(
|
|
|
|
info.fileId,
|
|
|
|
localStorage.getItem(info.fileId)
|
|
|
|
).then(() => {
|
2017-06-01 17:54:17 +00:00
|
|
|
document.getElementById('uploaded-files').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;
|