fix conflicts

This commit is contained in:
Daniela Arcese 2017-06-23 12:10:53 -04:00
parent e4fafc7472
commit 4dadec5ae9
3 changed files with 128 additions and 74 deletions

View File

@ -11,13 +11,18 @@ $(document).ready(function() {
$copyBtn.html('Copy');
$('#page-one').show();
$('#file-list').hide();
$('#file-list').show();
$('#upload-progress').hide();
$('#share-link').hide();
for(let i=0; i<localStorage.length; i++) {
let id = localStorage.key(i);
checkUploads(id);
}
// copy link to clipboard
$copyBtn.click(() => {
const aux = document.createElement('input');
var aux = document.createElement('input');
aux.setAttribute('value', $('#link').attr('value'));
document.body.appendChild(aux);
aux.select();
@ -52,39 +57,6 @@ $(document).ready(function() {
file = event.target.files[0];
}
const $fileList = $('#uploaded-files');
const row = document.createElement('tr');
const name = document.createElement('td');
const link = document.createElement('td');
const expiry = document.createElement('td');
const del = document.createElement('td');
del.setAttribute('align', 'center');
const btn = document.createElement('button');
const popupDiv = document.createElement('div');
const $popupText = $('<span>', { class: 'popuptext' });
const cellText = document.createTextNode(file.name);
name.appendChild(cellText);
// create delete button
btn.innerHTML = 'x';
btn.classList.add('delete-btn');
// create popup
popupDiv.classList.add('popup');
$popupText.html(
'<span class="del-file">Delete</span><span class="nvm" > Nevermind</span>'
);
// add data cells to table row
row.appendChild(name);
row.appendChild(link);
row.appendChild(expiry);
popupDiv.appendChild(btn);
$(popupDiv).append($popupText);
del.appendChild(popupDiv);
row.appendChild(del);
const fileSender = new FileSender(file);
fileSender.on('progress', percentComplete => {
$('#page-one').hide();
@ -96,53 +68,111 @@ $(document).ready(function() {
.querySelector('#progress-bar')
.style.setProperty('--progress', percentComplete + '%');
$('#progress-text').html(`${percentComplete}%`);
if (percentComplete === 100) {
notify('Your upload has finished.');
}
});
fileSender.upload().then(info => {
const url = info.url.trim() + `#${info.secretKey}`.trim();
$('#link').attr('value', url);
link.innerHTML = url;
localStorage.setItem(info.fileId, info.deleteToken);
$('#page-one').hide();
$('#file-list').hide();
$('#upload-progress').hide();
$('#share-link').show();
checkUploads(info.fileId, url);
});
};
window.allowDrop = function(ev) {
ev.preventDefault();
};
//load previous uploads
function checkUploads(id, url='') {
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) {
reject('error code: ' + xhr.status);
}
};
xhr.onerror = () => {
reject('There was a network error.');
};
xhr.open('get', '/file/' + id, true);
xhr.send();
}).then (response => {
populateFileList(response, url);
}, error => {
console.log(error);
});
}
//update file table with current files in localStorage
function populateFileList(file, url) {
console.log(file);
const $fileList = $('#uploaded-files');
const row = document.createElement('tr');
const name = document.createElement('td');
const link = document.createElement('td');
const expiry = document.createElement('td');
const del = document.createElement('td');
del.setAttribute('align', 'center');
const btn = document.createElement('button');
const popupDiv = document.createElement('div');
const $popupText = $('<span>', { class: 'popuptext' });
const cellText = document.createTextNode(file.name);
const progress = document.createElement('p');
name.appendChild(cellText);
// create delete button
btn.innerHTML = 'x';
btn.classList.add('delete-btn');
link.innerHTML = url;
// create popup
popupDiv.classList.add('popup');
$popupText.html(
'<span class="del-file">Delete</span><span class="nvm" > Nevermind</span>'
);
// delete file
$popupText.find('.del-file').click(e => {
FileSender.delete(
info.fileId,
localStorage.getItem(info.fileId)
file.fileId,
localStorage.getItem(file.fileId)
).then(() => {
$(e.target).parents('tr').remove();
localStorage.removeItem(info.fileId);
})
.catch(err => {
Raven.captureException(err);
return Promise.reject(err);
localStorage.removeItem(file.fileId);
});
});
// add data cells to table row
row.appendChild(name);
row.appendChild(link);
row.appendChild(expiry);
popupDiv.appendChild(btn);
$(popupDiv).append($popupText);
del.appendChild(popupDiv);
row.appendChild(del);
// show popup
del.addEventListener('click', toggleShow);
// hide popup
$popupText.find('.nvm').click(toggleShow);
$fileList.append(row); //add row to table
$('#page-one').hide();
$('#file-list').hide();
$('#upload-progress').hide();
$('#share-link').show();
})
.catch(err => {
Raven.captureException(err);
return Promise.reject(err);
});
$('tbody').append(row); //add row to table
function toggleShow() {
$popupText.toggleClass('show');
}
};
}
window.allowDrop = function(ev) {
ev.preventDefault();
};
});

View File

@ -50,6 +50,23 @@ app.get('/exists/:id', (req, res) => {
}).catch(err => res.sendStatus(404));
});
app.get('/file/:id', (req, res) => {
let id = req.params.id;
storage.filename(id).then(filename => {
storage
.length(id)
.then(contentLength => {
res.json({
name: filename,
filesize: bytes(contentLength),
fileId: id
})
}).catch(() => {
console.log('error retrieving id ' + id);
});
})
});
app.get('/download/:id', (req, res) => {
const id = req.params.id;
storage.filename(id).then(filename => {

View File

@ -38,12 +38,19 @@
<div id="file-list">
<table id="uploaded-files">
<thead>
<tr>
<!-- htmllint attr-bans="false" -->
<th width="30%">File</th>
<th width="45%">Copy URL</th>
<th width="18%">Expires in</th>
<th width="7%">Delete</th>
<!-- htmllint tag-bans="$previous" -->
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>