diff --git a/Dockerfile b/Dockerfile index 1825bd7..c108693 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,7 @@ RUN go mod download COPY src/ . ENV CGO_ENABLED=1 +ENV GIN_MODE=release RUN go build -o server . FROM alpine:latest diff --git a/templates/index.html b/templates/index.html index 7fb941e..11ff149 100644 --- a/templates/index.html +++ b/templates/index.html @@ -289,21 +289,28 @@ }; xhr.onload = () => { - try { - const data = JSON.parse(xhr.responseText); - if (data.error) throw new Error(data.error); + // Check if the server actually returned a success status (200-299) + if (xhr.status >= 200 && xhr.status < 300) { + try { + const data = JSON.parse(xhr.responseText); + if (data.error) throw new Error(data.error); - document.getElementById('upload-ui').classList.add('hidden'); - document.getElementById('success-ui').classList.remove('hidden'); + document.getElementById('upload-ui').classList.add('hidden'); + document.getElementById('success-ui').classList.remove('hidden'); - const dlUrl = window.location.origin + data.download_url; - const delUrl = `${window.location.origin}${data.delete_url}`; + const dlUrl = window.location.origin + data.download_url; + const delUrl = `${window.location.origin}${data.delete_url}`; - document.getElementById('res-url').value = dlUrl; - document.getElementById('res-del').value = delUrl; - } catch (err) { - alert(err.message || "An error occurred"); - location.reload(); + document.getElementById('res-url').value = dlUrl; + document.getElementById('res-del').value = delUrl; + } catch (err) { + console.error("JSON Parse Error. Server sent:", xhr.responseText); + alert("Server returned an invalid response. Check console (F12) for details."); + } + } else { + // If the server sent a 404, 413 (File too large), or 500 error + console.error("Server Error:", xhr.status, xhr.responseText); + alert(`Upload failed with status ${xhr.status}. Check console.`); } };