MCPcopy
hub / github.com/stemdeckapp/stemdeck / wireJobForm

Function wireJobForm

static/js/job.js:423–511  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

421}
422
423export 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

Callers 1

main.jsFile · 0.90

Calls 10

setWaveformLoadingFunction · 0.90
setCurrentJobIdFunction · 0.90
addTrackToLibraryFunction · 0.90
setCurrentTrackFunction · 0.90
resetFunction · 0.85
setSubmitProcessingFunction · 0.85
sanitizeFilenameFunction · 0.85
startPhraseRotationFunction · 0.85
connectEventsFunction · 0.85
showErrorFunction · 0.70

Tested by

no test coverage detected