diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..16d9979 --- /dev/null +++ b/public/index.html @@ -0,0 +1,62 @@ + + + + + + + Dataset Downloader & Answer Uploader + + + + +

Crab Webapp

+ +
+ Download a Dataset + + + +

+ +
+ +
+ Upload Your Answers + + +

+ +

+ +
+ +
+ + + + + diff --git a/public/js/index.js b/public/js/index.js new file mode 100644 index 0000000..5ca1208 --- /dev/null +++ b/public/js/index.js @@ -0,0 +1,36 @@ +// 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' : ''); + window.location = url; +}; + +// Upload logic +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.'); + } + const file = fileInput.files[0]; + const form = new FormData(); + form.append('file', file); + + const res = await fetch(`/answers/submit/${type}`, { + method: 'POST', + body: form + }); + + const json = await res.json(); + console.log(json) + const statusEl = document.getElementById('status'); + if (res.ok) { + statusEl.style.color = 'green'; + statusEl.textContent = json.message || 'Upload succeeded!'; + } else { + statusEl.style.color = 'red'; + statusEl.textContent = json.error + (json.message ? (': ' + json.message) : ''); + } +}; + diff --git a/src/server.js b/src/server.js index 02aea43..6914db0 100644 --- a/src/server.js +++ b/src/server.js @@ -13,6 +13,7 @@ app.use(cors()); app.use(json()); // Use routes +app.use(express.static("public")); app.use('/', routes); // Start server