diff options
Diffstat (limited to 'frontend/main.js')
| -rw-r--r-- | frontend/main.js | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/frontend/main.js b/frontend/main.js index e677c68..6c46b20 100644 --- a/frontend/main.js +++ b/frontend/main.js @@ -25,10 +25,7 @@ async function checkUserStatus() { async function checkMachineStatus() { const response = await fetch(`${API_URL}/status`, { method: "POST", - headers: { - "Content-Type": "application/json" - }, - body: JSON.stringify({block: 1}), + credentials: "include", }); return await response.json(); } @@ -69,17 +66,41 @@ function start() { }); } +// --- information loading + cookie setting (from server) +async function information(urlParam = null) { + const response = fetch(`${API_URL}/info`, { + credentials: "include", + method: "POST", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ "machine_id": urlParam ? urlParam : await browser.cookies.get({name: "auth_block", url: API_URL}) }) + }); + + const block = await response.json()["block"]; + + document.getElementById("logo-id").innerText = block; + + return Promise.resolve(block); +} + // ------ page specific ----- // ---- machine status page +const STATUS_INTERVAL = 30 + // --- machines visual async function startUpdateMachines() { + const urlParams = new URLSearchParams(window.location.search); + + await information(urlParams.get("block")); + updateMachines(); while (true) { - await delay(30 * 1000); + await delay(STATUS_INTERVAL * 1000); await updateMachines(); } |
