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'); $copyBtn.html('Copy');
$('#page-one').show(); $('#page-one').show();
$('#file-list').hide(); $('#file-list').show();
$('#upload-progress').hide(); $('#upload-progress').hide();
$('#share-link').hide(); $('#share-link').hide();
for(let i=0; i<localStorage.length; i++) {
let id = localStorage.key(i);
checkUploads(id);
}
// copy link to clipboard // copy link to clipboard
$copyBtn.click(() => { $copyBtn.click(() => {
const aux = document.createElement('input'); var aux = document.createElement('input');
aux.setAttribute('value', $('#link').attr('value')); aux.setAttribute('value', $('#link').attr('value'));
document.body.appendChild(aux); document.body.appendChild(aux);
aux.select(); aux.select();
@ -52,39 +57,6 @@ $(document).ready(function() {
file = event.target.files[0]; 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); const fileSender = new FileSender(file);
fileSender.on('progress', percentComplete => { fileSender.on('progress', percentComplete => {
$('#page-one').hide(); $('#page-one').hide();
@ -96,53 +68,111 @@ $(document).ready(function() {
.querySelector('#progress-bar') .querySelector('#progress-bar')
.style.setProperty('--progress', percentComplete + '%'); .style.setProperty('--progress', percentComplete + '%');
$('#progress-text').html(`${percentComplete}%`); $('#progress-text').html(`${percentComplete}%`);
if (percentComplete === 100) {
notify('Your upload has finished.');
}
}); });
fileSender.upload().then(info => { fileSender.upload().then(info => {
const url = info.url.trim() + `#${info.secretKey}`.trim(); const url = info.url.trim() + `#${info.secretKey}`.trim();
$('#link').attr('value', url); $('#link').attr('value', url);
link.innerHTML = url;
localStorage.setItem(info.fileId, info.deleteToken); 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 // delete file
$popupText.find('.del-file').click(e => { $popupText.find('.del-file').click(e => {
FileSender.delete( FileSender.delete(
info.fileId, file.fileId,
localStorage.getItem(info.fileId) localStorage.getItem(file.fileId)
).then(() => { ).then(() => {
$(e.target).parents('tr').remove(); $(e.target).parents('tr').remove();
localStorage.removeItem(info.fileId); localStorage.removeItem(file.fileId);
})
.catch(err => {
Raven.captureException(err);
return Promise.reject(err);
}); });
}); });
// 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 // show popup
del.addEventListener('click', toggleShow); del.addEventListener('click', toggleShow);
// hide popup // hide popup
$popupText.find('.nvm').click(toggleShow); $popupText.find('.nvm').click(toggleShow);
$fileList.append(row); //add row to table $('tbody').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);
});
function toggleShow() { function toggleShow() {
$popupText.toggleClass('show'); $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)); }).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) => { app.get('/download/:id', (req, res) => {
const id = req.params.id; const id = req.params.id;
storage.filename(id).then(filename => { storage.filename(id).then(filename => {

View file

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