()
| 421 | } |
| 422 | |
| 423 | export function wireJobForm() { |
| 424 | jobCancelBtn.addEventListener("click", cancelCurrentJob); |
| 425 | |
| 426 | form.addEventListener("submit", async (e) => { |
| 427 | e.preventDefault(); |
| 428 | reset(); |
| 429 | setSubmitProcessing(true); |
| 430 | |
| 431 | const fileInput = document.getElementById("fileInput"); |
| 432 | // Prefer _file cache: browsers (WKWebView, Chromium) silently clear |
| 433 | // fileInput.files after a fetch() submission, breaking re-submits. |
| 434 | const file = fileInput?._file ?? fileInput?.files?.[0] ?? null; |
| 435 | const sanitized = file ? sanitizeFilename(file.name) : null; |
| 436 | const sourceUrl = file ? `local:${sanitized}` : urlInput.value; |
| 437 | const displayTitle = sanitized ?? (urlInput.value || "Processing track"); |
| 438 | |
| 439 | const postUrlText = document.getElementById("post-url-text"); |
| 440 | if (postUrlText) postUrlText.textContent = displayTitle; |
| 441 | |
| 442 | // Show overlay immediately for both paths. File uploads show "Uploading…" |
| 443 | // in the overlay phrase until the fetch completes and SSE takes over. |
| 444 | setWaveformLoading(true, file ? "Uploading…" : ""); |
| 445 | if (file) { |
| 446 | lastStatus = "queued"; |
| 447 | } |
| 448 | |
| 449 | let fetchInit; |
| 450 | if (file) { |
| 451 | const fd = new FormData(); |
| 452 | fd.append("file", file); |
| 453 | fd.append("stems", JSON.stringify([...selectedStems])); |
| 454 | fetchInit = { method: "POST", body: fd }; |
| 455 | } else { |
| 456 | fetchInit = { |
| 457 | method: "POST", |
| 458 | headers: { "Content-Type": "application/json" }, |
| 459 | body: JSON.stringify({ |
| 460 | url: urlInput.value, |
| 461 | // Backend uses this to decide whether to ffmpeg-amix a |
| 462 | // "selected stems" track (mix.wav) at the end of the pipeline. |
| 463 | stems: [...selectedStems], |
| 464 | }), |
| 465 | }; |
| 466 | } |
| 467 | |
| 468 | let jobId; |
| 469 | try { |
| 470 | const res = await fetch("/api/jobs", fetchInit); |
| 471 | const data = await res.json(); |
| 472 | if (!res.ok) throw new Error(data.detail || res.statusText); |
| 473 | jobId = data.job_id; |
| 474 | } catch (err) { |
| 475 | if (file) jobBox.classList.add("hidden"); |
| 476 | showError(`Failed to start job: ${err.message}`); |
| 477 | setSubmitProcessing(false); |
| 478 | return; |
| 479 | } |
| 480 |
no test coverage detected