From 1e38547f07f7eee2044f5c0db5ca8d000d05e370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Ryb=C3=A1rsky?= Date: Thu, 25 Apr 2024 22:47:06 +0200 Subject: [PATCH] MEME --- assets/script.js | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/assets/script.js b/assets/script.js index 4e92912..d13382d 100644 --- a/assets/script.js +++ b/assets/script.js @@ -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; - } - else { - tmp = false; - } + if (!response.ok) { + throw new Error('Network response was not ok'); } - }; - xhr.send(formData); - until(_ => (tmp === undefined)); - return tmp; + + const resp = await response.json(); + + if (resp.Status === "Success") { + return resp.Files; + } else { + return false; + } + } catch (error) { + return false; + } } async function listFiles() {