Download app/static/js/upload.js from nvikou/Sheetly: direct link, hf CLI and curl.
- Browser
- Download file 4.41 kB
-
https://huggingface.co/spaces/nvikou/Sheetly/resolve/main/app/static/js/upload.js
- Command line
-
hf download hf://spaces/nvikou/Sheetly/app/static/js/upload.js
-
curl -L -o upload.js https://huggingface.co/spaces/nvikou/Sheetly/resolve/main/app/static/js/upload.js
4.41 kB
| (() => { | |
| const dropzone = document.getElementById("dropzone"); | |
| const fileInput = document.getElementById("fileInput"); | |
| const fileList = document.getElementById("fileList"); | |
| const uploadBtn = document.getElementById("uploadBtn"); | |
| const progressWrap = document.getElementById("progressWrap"); | |
| const progressBar = document.getElementById("progressBar"); | |
| const statusText = document.getElementById("statusText"); | |
| const docList = document.getElementById("docList"); | |
| let selected = []; | |
| let pollTimer = null; | |
| const browseBtn = document.getElementById("browseBtn"); | |
| if (browseBtn) { | |
| browseBtn.addEventListener("click", () => fileInput.click()); | |
| } | |
| dropzone.addEventListener("click", () => fileInput.click()); | |
| dropzone.addEventListener("dragover", (e) => { | |
| e.preventDefault(); | |
| dropzone.classList.add("dragover"); | |
| }); | |
| dropzone.addEventListener("dragleave", () => { | |
| dropzone.classList.remove("dragover"); | |
| }); | |
| dropzone.addEventListener("drop", (e) => { | |
| e.preventDefault(); | |
| dropzone.classList.remove("dragover"); | |
| selected = Array.from(e.dataTransfer.files); | |
| renderFiles(); | |
| }); | |
| fileInput.addEventListener("change", () => { | |
| selected = Array.from(fileInput.files || []); | |
| renderFiles(); | |
| }); | |
| function renderFiles() { | |
| fileList.innerHTML = ""; | |
| selected.forEach((f) => { | |
| const li = document.createElement("li"); | |
| li.innerHTML = `<span>${f.name}</span><span>${( | |
| f.size / 1024 | |
| ).toFixed(1)} KB</span>`; | |
| fileList.appendChild(li); | |
| }); | |
| uploadBtn.disabled = selected.length === 0; | |
| } | |
| uploadBtn.addEventListener("click", async () => { | |
| if (!selected.length) return; | |
| uploadBtn.disabled = true; | |
| statusText.textContent = "Uploading…"; | |
| progressWrap.hidden = false; | |
| progressBar.style.width = "5%"; | |
| const form = new FormData(); | |
| selected.forEach((f) => form.append("files", f)); | |
| try { | |
| const res = await fetch("/api/batches", { | |
| method: "POST", | |
| body: form, | |
| }); | |
| if (!res.ok) { | |
| const err = await res.json().catch(() => ({})); | |
| throw new Error(err.detail || res.statusText); | |
| } | |
| const batch = await res.json(); | |
| statusText.textContent = `Batch ${batch.id.slice(0, 8)}… processing`; | |
| pollBatch(batch.id); | |
| } catch (err) { | |
| statusText.textContent = `Error: ${err.message}`; | |
| uploadBtn.disabled = false; | |
| } | |
| }); | |
| function pollBatch(id) { | |
| if (pollTimer) clearInterval(pollTimer); | |
| pollTimer = setInterval(async () => { | |
| const res = await fetch(`/api/batches/${id}`); | |
| const batch = await res.json(); | |
| progressBar.style.width = `${batch.progress}%`; | |
| statusText.textContent = | |
| `${batch.processed}/${batch.total} processed` + | |
| (batch.failed ? ` (${batch.failed} failed)` : ""); | |
| const docsRes = await fetch( | |
| `/api/batches/${id}/documents` | |
| ); | |
| const docs = await docsRes.json(); | |
| renderDocs(docs); | |
| if ( | |
| batch.status === "completed" || | |
| batch.status === "failed" | |
| ) { | |
| clearInterval(pollTimer); | |
| uploadBtn.disabled = false; | |
| statusText.textContent += | |
| " — done. Open Validate to review."; | |
| } | |
| }, 800); | |
| } | |
| function renderDocs(docs) { | |
| docList.innerHTML = ""; | |
| docs.forEach((d) => { | |
| const li = document.createElement("li"); | |
| const link = | |
| d.status === "ready" || d.status === "validated" | |
| ? `<a href="/validate?id=${d.id}">Review</a>` | |
| : d.status; | |
| const type = (d.doc_type || "other").replaceAll( | |
| "_", | |
| " " | |
| ); | |
| li.innerHTML = | |
| `<span>${d.filename} ` + | |
| `<span class="badge type-${d.doc_type}">${type}</span>` + | |
| `</span>` + | |
| `<span>${link}</span>`; | |
| docList.appendChild(li); | |
| }); | |
| } | |
| })(); | |