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; 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) { async function handleResponse(data, successMessage, failureMessage) {
"use strict"; "use strict";
const statusMessageContainer = document.getElementById("statusMessageContainer"); const statusMessageContainer = document.getElementById("statusMessageContainer");
@ -588,24 +578,26 @@ async function getFileList() {
let formData = new FormData(); let formData = new FormData();
formData.append('action', 'getAllFiles'); formData.append('action', 'getAllFiles');
let xhr = new XMLHttpRequest(); try {
xhr.open('POST', '/upload', true); const response = await fetch('/upload', {
method: 'POST',
body: formData
});
let tmp; if (!response.ok) {
xhr.onload = function () { throw new Error('Network response was not ok');
if (xhr.status === 200) {
const resp = JSON.parse(xhr.responseText);
if (resp.Status == "Success") {
tmp = resp.Files;
} }
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() { async function listFiles() {