mirror of
https://github.com/karma-riuk/crab-webapp.git
synced 2025-07-05 14:18:12 +02:00
formatted file
This commit is contained in:
@ -1,36 +1,37 @@
|
|||||||
// Download logic
|
// Download logic
|
||||||
document.getElementById('downloadBtn').onclick = () => {
|
document.getElementById("downloadBtn").onclick = () => {
|
||||||
const ds = document.getElementById('datasetSelect').value;
|
const ds = document.getElementById("datasetSelect").value;
|
||||||
const withCtx = document.getElementById('withContext').checked;
|
const withCtx = document.getElementById("withContext").checked;
|
||||||
const url = `/datasets/download/${ds}` + (withCtx ? '?withContext=true' : '');
|
const url =
|
||||||
|
`/datasets/download/${ds}` + (withCtx ? "?withContext=true" : "");
|
||||||
window.location = url;
|
window.location = url;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Upload logic
|
// Upload logic
|
||||||
document.getElementById('uploadBtn').onclick = async () => {
|
document.getElementById("uploadBtn").onclick = async () => {
|
||||||
const type = document.getElementById('answerType').value;
|
const type = document.getElementById("answerType").value;
|
||||||
const fileInput = document.getElementById('fileInput');
|
const fileInput = document.getElementById("fileInput");
|
||||||
if (!fileInput.files.length) {
|
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 file = fileInput.files[0];
|
||||||
const form = new FormData();
|
const form = new FormData();
|
||||||
form.append('file', file);
|
form.append("file", file);
|
||||||
|
|
||||||
const res = await fetch(`/answers/submit/${type}`, {
|
const res = await fetch(`/answers/submit/${type}`, {
|
||||||
method: 'POST',
|
method: "POST",
|
||||||
body: form
|
body: form,
|
||||||
});
|
});
|
||||||
|
|
||||||
const json = await res.json();
|
const json = await res.json();
|
||||||
console.log(json)
|
console.log(json);
|
||||||
const statusEl = document.getElementById('status');
|
const statusEl = document.getElementById("status");
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
statusEl.style.color = 'green';
|
statusEl.style.color = "green";
|
||||||
statusEl.textContent = json.message || 'Upload succeeded!';
|
statusEl.textContent = json.message || "Upload succeeded!";
|
||||||
} else {
|
} else {
|
||||||
statusEl.style.color = 'red';
|
statusEl.style.color = "red";
|
||||||
statusEl.textContent = json.error + (json.message ? (': ' + json.message) : '');
|
statusEl.textContent =
|
||||||
|
json.error + (json.message ? ": " + json.message : "");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user