fix polling function
This commit is contained in:
parent
9026702e7b
commit
1908ce084d
|
@ -55,7 +55,7 @@ $(document).ready(function() {
|
|||
} else {
|
||||
file = event.target.files[0];
|
||||
}
|
||||
const expiration = 24 * 60 * 60 * 1000; //will eventually come from a field
|
||||
const expiration = 2 * 60 * 1000; //will eventually come from a field
|
||||
|
||||
const fileSender = new FileSender(file);
|
||||
fileSender.on('progress', percentComplete => {
|
||||
|
@ -140,7 +140,7 @@ $(document).ready(function() {
|
|||
btn.classList.add('delete-btn');
|
||||
|
||||
link.innerHTML = file.url.trim() + `#${file.secretKey}`.trim();
|
||||
|
||||
|
||||
file.creationDate = new Date(file.creationDate);
|
||||
|
||||
const future = new Date();
|
||||
|
@ -152,30 +152,36 @@ $(document).ready(function() {
|
|||
let hours = Math.floor(minutes / 60);
|
||||
let seconds = Math.floor(countdown / 1000 % 60);
|
||||
|
||||
if (hours > 0) {
|
||||
expiry.innerHTML = hours + 'h';
|
||||
window.setInterval(() => {
|
||||
poll();
|
||||
expiry.innerHTML = hours + 'h';
|
||||
}, 3600000);
|
||||
} else if (hours === 0) {
|
||||
expiry.innerHTML = minutes + 'm' + seconds + 's';
|
||||
window.setInterval(() => {
|
||||
poll();
|
||||
expiry.innerHTML = minutes + 'm' + seconds + 's';
|
||||
}, 1000);
|
||||
}
|
||||
poll();
|
||||
|
||||
function poll() {
|
||||
countdown = future.getTime() - new Date().getTime();
|
||||
minutes = Math.floor(countdown / 1000 / 60);
|
||||
hours = Math.floor(minutes / 60);
|
||||
seconds = Math.floor(countdown / 1000 % 60);
|
||||
let t;
|
||||
|
||||
if (hours > 1) {
|
||||
expiry.innerHTML = hours + 'h';
|
||||
t = window.setTimeout(() => {
|
||||
poll();
|
||||
}, 3600000);
|
||||
} else if (hours === 1) {
|
||||
expiry.innerHTML = hours + 'h';
|
||||
t = window.setTimeout(() => {
|
||||
poll();
|
||||
}, 60000);
|
||||
} else if (hours === 0) {
|
||||
expiry.innerHTML = minutes + 'm' + seconds + 's';
|
||||
t = window.setTimeout(() => {
|
||||
poll();
|
||||
}, 1000);
|
||||
}
|
||||
//remove from list when expired
|
||||
if (hours === 0 && minutes === 0 && seconds === 0) {
|
||||
if (countdown <= 0) {
|
||||
localStorage.removeItem(file.fileId);
|
||||
$(expiry).parents('tr').remove();
|
||||
window.clearTimeout(t);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue