const dropArea = document.getElementById('drop-area') const fileInput = document.getElementById('fileElem') // Prevent default drag behaviors ;['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => { dropArea.addEventListener(eventName, preventDefaults, false) }) function preventDefaults(e) { e.preventDefault() e.stopPropagation() } // Highlight drop area on dragover ;['dragenter', 'dragover'].forEach(eventName => { dropArea.addEventListener(eventName, () => dropArea.classList.add('highlight'), false) }) ;['dragleave', 'drop'].forEach(eventName => { dropArea.addEventListener(eventName, () => dropArea.classList.remove('highlight'), false) }) // Handle dropped files dropArea.addEventListener('drop', e => { const dt = e.dataTransfer const files = dt.files handleFiles(files) }) // Handle selected files from input fileInput.addEventListener('change', e => { handleFiles(fileInput.files) }) function handleFiles(files) { if (!files || files.length === 0) return const file = files[0] if (!file.name.endsWith('.zip')) { alert('Please upload a ZIP file.') return } uploadFile(file) } function uploadFile(file) { const url = 'http://localhost:8000/upload' const formData = new FormData() formData.append('file', file) dropArea.innerHTML = `

Uploading ${file.name}...

` fetch(url, { method: 'POST', body: formData }) .then(async response => { const contentType = response.headers.get('Content-Type') // Check if content type includes text/plain (for QC failure report) if (contentType && contentType.includes('text/plain')) { // QC Failed - download report const blob = await response.blob() const link = document.createElement('a') link.href = window.URL.createObjectURL(blob) link.download = 'QC_report.txt' link.click() dropArea.innerHTML = `

QC failed. Report downloaded.

` } else if (contentType && contentType.includes('application/json')) { // QC Passed - show success and VerofyMapID input const data = await response.json() if (data.message === 'success') { showVerofyMapIdInput() } else { dropArea.innerHTML = `

Unexpected response from server.

` } } else { // Unknown response type, try to handle as text const text = await response.text() dropArea.innerHTML = `

Unexpected response: ${text.substring(0, 100)}

` } }) .catch((error) => { console.error('Upload error:', error) dropArea.innerHTML = `

Upload failed. Check console.

` }) } function showVerofyMapIdInput() { dropArea.innerHTML = `

Your files have passed QC!

Please provide VerofyMapID:


` } function submitMapId() { const mapIdInput = document.getElementById('verofyMapId') const mapId = mapIdInput.value if (!mapId || mapId.trim() === '') { alert('Please enter a VerofyMapID') return } // Update the drop area to show success message dropArea.innerHTML = `

Success! VerofyMapID ${mapId} received.

` // Create overlay with celebration image const overlay = document.createElement('div') overlay.id = 'celebrationOverlay' overlay.style.cssText = ` position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0, 0, 0, 0.7); display: flex; justify-content: center; align-items: center; z-index: 10000; cursor: pointer; ` overlay.innerHTML = ` Celebration ` // Remove overlay on click overlay.addEventListener('click', () => { overlay.remove() }) document.body.appendChild(overlay) }