improved exist check
This commit is contained in:
parent
e1137db946
commit
43fa551a64
@ -13,16 +13,20 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
fileList = document.getElementById('file-list');
|
fileList = document.getElementById('file-list');
|
||||||
toggleHeader();
|
toggleHeader();
|
||||||
// eslint-disable-next-line prefer-const
|
// eslint-disable-next-line prefer-const
|
||||||
for (let file of storage.files) {
|
Promise.all(
|
||||||
const id = file.fileId;
|
storage.files.map(file => {
|
||||||
checkExistence(id).then(exists => {
|
const id = file.fileId;
|
||||||
if (exists) {
|
return checkExistence(id).then(exists => {
|
||||||
addFile(storage.getFileById(id));
|
if (exists) {
|
||||||
} else {
|
addFile(storage.getFileById(id));
|
||||||
storage.remove(id);
|
} else {
|
||||||
}
|
storage.remove(id);
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.catch(err => console.error(err))
|
||||||
|
.then(toggleHeader);
|
||||||
});
|
});
|
||||||
|
|
||||||
function toggleHeader() {
|
function toggleHeader() {
|
||||||
@ -209,11 +213,14 @@ async function checkExistence(id) {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
xhr.onreadystatechange = () => {
|
xhr.onreadystatechange = () => {
|
||||||
if (xhr.readyState === XMLHttpRequest.DONE) {
|
if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
|
||||||
resolve(xhr.status === 200);
|
resolve(xhr.status === 200);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
xhr.onerror = reject;
|
||||||
|
xhr.ontimeout = reject;
|
||||||
xhr.open('get', '/exists/' + id);
|
xhr.open('get', '/exists/' + id);
|
||||||
|
xhr.timeout = 2000;
|
||||||
xhr.send();
|
xhr.send();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user