From 4c2d91229856b480008adb85249a8aaa0800f3bd Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Wed, 7 May 2025 17:49:06 +0200 Subject: [PATCH] formatted file --- public/js/index.js | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/public/js/index.js b/public/js/index.js index 5ca1208..5311801 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1,36 +1,37 @@ // Download logic -document.getElementById('downloadBtn').onclick = () => { - const ds = document.getElementById('datasetSelect').value; - const withCtx = document.getElementById('withContext').checked; - const url = `/datasets/download/${ds}` + (withCtx ? '?withContext=true' : ''); +document.getElementById("downloadBtn").onclick = () => { + const ds = document.getElementById("datasetSelect").value; + const withCtx = document.getElementById("withContext").checked; + const url = + `/datasets/download/${ds}` + (withCtx ? "?withContext=true" : ""); window.location = url; }; // Upload logic -document.getElementById('uploadBtn').onclick = async () => { - const type = document.getElementById('answerType').value; - const fileInput = document.getElementById('fileInput'); +document.getElementById("uploadBtn").onclick = async () => { + const type = document.getElementById("answerType").value; + const fileInput = document.getElementById("fileInput"); if (!fileInput.files.length) { - return alert('Please choose a JSON file first.'); + return alert("Please choose a JSON file first."); } const file = fileInput.files[0]; const form = new FormData(); - form.append('file', file); + form.append("file", file); const res = await fetch(`/answers/submit/${type}`, { - method: 'POST', - body: form + method: "POST", + body: form, }); const json = await res.json(); - console.log(json) - const statusEl = document.getElementById('status'); + console.log(json); + const statusEl = document.getElementById("status"); if (res.ok) { - statusEl.style.color = 'green'; - statusEl.textContent = json.message || 'Upload succeeded!'; + statusEl.style.color = "green"; + statusEl.textContent = json.message || "Upload succeeded!"; } else { - statusEl.style.color = 'red'; - statusEl.textContent = json.error + (json.message ? (': ' + json.message) : ''); + statusEl.style.color = "red"; + statusEl.textContent = + json.error + (json.message ? ": " + json.message : ""); } }; -