update
This commit is contained in:
@@ -14,3 +14,35 @@ document.addEventListener("click", async (event) => {
|
||||
button.textContent = "Copy failed";
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("submit", async (event) => {
|
||||
const form = event.target.closest("[data-upload-form]");
|
||||
if (!form) return;
|
||||
event.preventDefault();
|
||||
|
||||
const button = form.querySelector("button[type=submit]");
|
||||
const status = form.querySelector("[data-upload-status]");
|
||||
const csrfToken = form.querySelector('input[name="csrf_token"]').value;
|
||||
button.disabled = true;
|
||||
status.textContent = "Uploading package… keep this page open.";
|
||||
|
||||
try {
|
||||
const response = await fetch(form.action, {
|
||||
method: "POST",
|
||||
body: new FormData(form),
|
||||
headers: {"X-CSRF-Token": csrfToken},
|
||||
credentials: "same-origin",
|
||||
});
|
||||
const result = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
throw new Error(result.error || `Upload failed with HTTP ${response.status}`);
|
||||
}
|
||||
status.textContent = `Uploaded ${result.filename}; SHA-256 ${result.sha256}`;
|
||||
window.setTimeout(() => {
|
||||
window.location.assign("/portal?notice=Package+uploaded+and+registered");
|
||||
}, 900);
|
||||
} catch (error) {
|
||||
status.textContent = error.message;
|
||||
button.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user