This commit is contained in:
Bruno Rybársky 2024-04-25 22:47:06 +02:00
parent 8fff030655
commit 1e38547f07

@ -12,16 +12,6 @@ function isLoggedIn() {
return UserInfo.Email && 0 < UserInfo.Email.length;
}
function until(conditionFunction) {
const poll = resolve => {
if(conditionFunction()) resolve();
else setTimeout(_ => poll(resolve), 400);
}
return new Promise(poll);
}
async function handleResponse(data, successMessage, failureMessage) {
"use strict";
const statusMessageContainer = document.getElementById("statusMessageContainer");
@ -588,24 +578,26 @@ async function getFileList() {
let formData = new FormData();
formData.append('action', 'getAllFiles');
let xhr = new XMLHttpRequest();
xhr.open('POST', '/upload', true);
try {
const response = await fetch('/upload', {
method: 'POST',
body: formData
});
let tmp;
xhr.onload = function () {
if (xhr.status === 200) {
const resp = JSON.parse(xhr.responseText);
if (resp.Status == "Success") {
tmp = resp.Files;
if (!response.ok) {
throw new Error('Network response was not ok');
}
else {
tmp = false;
const resp = await response.json();
if (resp.Status === "Success") {
return resp.Files;
} else {
return false;
}
} catch (error) {
return false;
}
};
xhr.send(formData);
until(_ => (tmp === undefined));
return tmp;
}
async function listFiles() {