File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20797,20 +20797,28 @@ if ($("loopToggle")) {
2079720797}
2079820798
2079920799if ($("downloadBtn")) {
20800- $("downloadBtn").addEventListener("click", () => {
20800+ $("downloadBtn").addEventListener("click", async () => {
2080120801 const path = $("audioPath")?.value;
2080220802 if (!path) return;
2080320803 const href = downloadableOutputUrl(path);
2080420804 if (!href) {
2080520805 setState("Download Blocked", "warn", "The selected sound does not have a trusted download URL.");
2080620806 return;
2080720807 }
20808- const a = document.createElement("a");
20809- a.href = href;
20810- a.download = path.split("/").pop() || "download.wav";
20811- document.body.appendChild(a);
20812- a.click();
20813- document.body.removeChild(a);
20808+ try {
20809+ const response = await fetch(href, { credentials: "same-origin" });
20810+ if (!response.ok) throw new Error(`Download failed (${response.status})`);
20811+ const objectUrl = URL.createObjectURL(await response.blob());
20812+ const a = document.createElement("a");
20813+ a.href = objectUrl;
20814+ a.download = safeOutputName(path.split("/").pop() || "download.wav");
20815+ document.body.appendChild(a);
20816+ a.click();
20817+ document.body.removeChild(a);
20818+ window.setTimeout(() => URL.revokeObjectURL(objectUrl), 0);
20819+ } catch (error) {
20820+ setState("Download Failed", "bad", error.message);
20821+ }
2081420822 });
2081520823}
2081620824
You can’t perform that action at this time.
0 commit comments