Spaces:
Sleeping
Sleeping
Download app/static/index.html from Rahul4112/BackDropStudio: direct link, hf CLI and curl.
- Browser
- Download file 26.9 kB
-
https://huggingface.co/spaces/Rahul4112/BackDropStudio/resolve/main/app/static/index.html
- Command line
-
hf download hf://spaces/Rahul4112/BackDropStudio/app/static/index.html
-
curl -L -o index.html https://huggingface.co/spaces/Rahul4112/BackDropStudio/resolve/main/app/static/index.html
26.9 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | |
| <title>BackDropStudio</title> | |
| <style> | |
| :root { | |
| --bg: #f6f8fb; | |
| --surface: #ffffff; | |
| --surface-soft: #eef5f5; | |
| --surface-strong: #e6eeee; | |
| --text: #101827; | |
| --muted: #5b6678; | |
| --subtle: #7b8493; | |
| --border: #d8e0e8; | |
| --border-strong: #b8c6d3; | |
| --accent: #007f86; | |
| --accent-dark: #00626a; | |
| --accent-soft: #e1f4f4; | |
| --ink: #0d1628; | |
| --success: #157347; | |
| --danger: #b42318; | |
| --warning: #a15c07; | |
| --focus: rgba(0, 127, 134, 0.18); | |
| --shadow: 0 24px 70px rgba(16, 24, 39, 0.12); | |
| --radius: 8px; | |
| } | |
| * { | |
| box-sizing: border-box; | |
| } | |
| html { | |
| color-scheme: light; | |
| } | |
| body { | |
| margin: 0; | |
| min-height: 100vh; | |
| background: | |
| linear-gradient(145deg, rgba(0, 127, 134, 0.1), rgba(246, 248, 251, 0) 34%), | |
| linear-gradient(320deg, rgba(219, 165, 75, 0.08), rgba(246, 248, 251, 0) 38%), | |
| var(--bg); | |
| color: var(--text); | |
| font-family: | |
| Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", | |
| sans-serif; | |
| line-height: 1.5; | |
| } | |
| button, | |
| input { | |
| font: inherit; | |
| } | |
| button, | |
| label { | |
| -webkit-tap-highlight-color: transparent; | |
| } | |
| .shell { | |
| width: min(1160px, calc(100% - 32px)); | |
| margin: 0 auto; | |
| padding: 30px 0 48px; | |
| } | |
| header { | |
| display: flex; | |
| align-items: center; | |
| justify-content: space-between; | |
| gap: 24px; | |
| margin-bottom: 34px; | |
| } | |
| .brand { | |
| display: inline-flex; | |
| align-items: center; | |
| gap: 12px; | |
| color: var(--text); | |
| font-size: 1.03rem; | |
| font-weight: 820; | |
| letter-spacing: 0; | |
| } | |
| .brand-mark { | |
| display: grid; | |
| width: 38px; | |
| height: 38px; | |
| place-items: center; | |
| border-radius: var(--radius); | |
| background: var(--ink); | |
| color: #ffffff; | |
| } | |
| .brand-mark svg { | |
| width: 21px; | |
| height: 21px; | |
| } | |
| .header-note { | |
| margin: 0; | |
| color: var(--muted); | |
| font-size: 0.92rem; | |
| } | |
| main { | |
| display: grid; | |
| grid-template-columns: minmax(0, 0.92fr) minmax(390px, 1.08fr); | |
| gap: 34px; | |
| align-items: start; | |
| } | |
| .intro { | |
| padding-top: 22px; | |
| } | |
| h1 { | |
| margin: 0; | |
| max-width: 690px; | |
| color: var(--ink); | |
| font-size: clamp(2.45rem, 5vw, 5.25rem); | |
| font-weight: 860; | |
| line-height: 0.96; | |
| letter-spacing: 0; | |
| } | |
| .intro-copy { | |
| max-width: 575px; | |
| margin: 24px 0 0; | |
| color: var(--muted); | |
| font-size: 1.06rem; | |
| } | |
| .proof-strip { | |
| display: grid; | |
| grid-template-columns: repeat(3, minmax(0, 1fr)); | |
| gap: 10px; | |
| max-width: 600px; | |
| margin-top: 30px; | |
| } | |
| .proof-item { | |
| min-height: 92px; | |
| padding: 15px; | |
| border: 1px solid var(--border); | |
| border-radius: var(--radius); | |
| background: rgba(255, 255, 255, 0.62); | |
| } | |
| .proof-item strong { | |
| display: block; | |
| color: var(--ink); | |
| font-size: 0.93rem; | |
| line-height: 1.25; | |
| } | |
| .proof-item span { | |
| display: block; | |
| margin-top: 6px; | |
| color: var(--muted); | |
| font-size: 0.84rem; | |
| line-height: 1.4; | |
| } | |
| .panel { | |
| overflow: hidden; | |
| border: 1px solid var(--border); | |
| border-radius: var(--radius); | |
| background: var(--surface); | |
| box-shadow: var(--shadow); | |
| } | |
| .panel-header { | |
| display: flex; | |
| align-items: center; | |
| justify-content: space-between; | |
| gap: 16px; | |
| padding: 22px 24px; | |
| border-bottom: 1px solid var(--border); | |
| background: #fbfcfd; | |
| } | |
| .panel-header h2 { | |
| margin: 0; | |
| color: var(--ink); | |
| font-size: 1rem; | |
| line-height: 1.25; | |
| } | |
| .status-dot { | |
| display: inline-flex; | |
| align-items: center; | |
| gap: 8px; | |
| min-width: max-content; | |
| color: var(--muted); | |
| font-size: 0.86rem; | |
| font-weight: 720; | |
| } | |
| .status-dot::before { | |
| content: ""; | |
| width: 8px; | |
| height: 8px; | |
| border-radius: 50%; | |
| background: var(--accent); | |
| } | |
| .status-dot[data-state="done"]::before { | |
| background: var(--success); | |
| } | |
| .status-dot[data-state="error"]::before { | |
| background: var(--danger); | |
| } | |
| form { | |
| display: grid; | |
| gap: 20px; | |
| padding: 24px; | |
| } | |
| .field { | |
| display: grid; | |
| gap: 8px; | |
| } | |
| .field-row { | |
| display: grid; | |
| grid-template-columns: repeat(2, minmax(0, 1fr)); | |
| gap: 16px; | |
| } | |
| .field-label { | |
| display: flex; | |
| align-items: baseline; | |
| justify-content: space-between; | |
| gap: 12px; | |
| color: var(--ink); | |
| font-size: 0.9rem; | |
| font-weight: 760; | |
| } | |
| .field-label span { | |
| color: var(--subtle); | |
| font-size: 0.78rem; | |
| font-weight: 650; | |
| } | |
| .field-help { | |
| margin: 0; | |
| color: var(--muted); | |
| font-size: 0.84rem; | |
| } | |
| .drop-zone { | |
| display: grid; | |
| gap: 12px; | |
| min-height: 154px; | |
| padding: 22px; | |
| place-items: center; | |
| border: 1.5px dashed var(--border-strong); | |
| border-radius: var(--radius); | |
| background: | |
| linear-gradient(180deg, rgba(225, 244, 244, 0.5), rgba(255, 255, 255, 0.72)), | |
| var(--surface); | |
| color: var(--text); | |
| cursor: pointer; | |
| text-align: center; | |
| transition: | |
| border-color 160ms ease, | |
| background 160ms ease, | |
| transform 160ms ease; | |
| } | |
| .drop-zone:hover, | |
| .drop-zone.is-dragging { | |
| border-color: var(--accent); | |
| background: var(--accent-soft); | |
| transform: translateY(-1px); | |
| } | |
| .drop-zone:focus-within { | |
| border-color: var(--accent); | |
| box-shadow: 0 0 0 4px var(--focus); | |
| } | |
| .drop-icon { | |
| display: grid; | |
| width: 44px; | |
| height: 44px; | |
| place-items: center; | |
| border-radius: var(--radius); | |
| background: var(--ink); | |
| color: #ffffff; | |
| } | |
| .drop-icon svg { | |
| width: 23px; | |
| height: 23px; | |
| } | |
| .drop-copy strong { | |
| display: block; | |
| font-size: 1rem; | |
| font-weight: 780; | |
| } | |
| .drop-copy span, | |
| .file-name { | |
| display: block; | |
| margin-top: 3px; | |
| color: var(--muted); | |
| font-size: 0.86rem; | |
| } | |
| .file-input { | |
| position: absolute; | |
| width: 1px; | |
| height: 1px; | |
| overflow: hidden; | |
| clip: rect(0, 0, 0, 0); | |
| white-space: nowrap; | |
| } | |
| input[type="text"] { | |
| width: 100%; | |
| height: 46px; | |
| padding: 0 14px; | |
| border: 1px solid var(--border); | |
| border-radius: var(--radius); | |
| background: var(--surface); | |
| color: var(--text); | |
| font-size: 0.96rem; | |
| outline: none; | |
| transition: | |
| border-color 150ms ease, | |
| box-shadow 150ms ease; | |
| } | |
| input[type="color"] { | |
| width: 50px; | |
| height: 46px; | |
| padding: 4px; | |
| border: 1px solid var(--border); | |
| border-radius: var(--radius); | |
| background: var(--surface); | |
| cursor: pointer; | |
| } | |
| input:focus-visible { | |
| border-color: var(--accent); | |
| box-shadow: 0 0 0 4px var(--focus); | |
| } | |
| .color-row { | |
| display: grid; | |
| grid-template-columns: 50px minmax(0, 1fr); | |
| gap: 10px; | |
| align-items: center; | |
| } | |
| .segmented { | |
| display: grid; | |
| grid-template-columns: repeat(3, minmax(0, 1fr)); | |
| gap: 6px; | |
| padding: 5px; | |
| border: 1px solid var(--border); | |
| border-radius: var(--radius); | |
| background: var(--surface-soft); | |
| } | |
| .segmented.two { | |
| grid-template-columns: repeat(2, minmax(0, 1fr)); | |
| } | |
| .segmented input { | |
| position: absolute; | |
| opacity: 0; | |
| pointer-events: none; | |
| } | |
| .segmented label { | |
| display: grid; | |
| min-height: 54px; | |
| place-items: center; | |
| padding: 8px 10px; | |
| border: 1px solid transparent; | |
| border-radius: 7px; | |
| color: var(--muted); | |
| cursor: pointer; | |
| font-size: 0.82rem; | |
| font-weight: 780; | |
| line-height: 1.15; | |
| text-align: center; | |
| transition: | |
| background 150ms ease, | |
| border-color 150ms ease, | |
| color 150ms ease, | |
| box-shadow 150ms ease; | |
| } | |
| .segmented input:checked + label { | |
| border-color: var(--border); | |
| background: var(--surface); | |
| color: var(--ink); | |
| box-shadow: 0 6px 18px rgba(16, 24, 39, 0.08); | |
| } | |
| .segmented input:focus-visible + label { | |
| box-shadow: 0 0 0 4px var(--focus); | |
| } | |
| .submit-button, | |
| .download-button { | |
| display: inline-flex; | |
| align-items: center; | |
| justify-content: center; | |
| gap: 10px; | |
| width: 100%; | |
| min-height: 50px; | |
| border: 0; | |
| border-radius: var(--radius); | |
| background: var(--accent); | |
| color: #ffffff; | |
| cursor: pointer; | |
| font-size: 0.98rem; | |
| font-weight: 820; | |
| text-decoration: none; | |
| transition: | |
| background 150ms ease, | |
| transform 150ms ease, | |
| box-shadow 150ms ease; | |
| } | |
| .submit-button:hover, | |
| .download-button:hover { | |
| background: var(--accent-dark); | |
| box-shadow: 0 12px 28px rgba(0, 127, 134, 0.2); | |
| transform: translateY(-1px); | |
| } | |
| .submit-button:disabled { | |
| cursor: not-allowed; | |
| opacity: 0.62; | |
| box-shadow: none; | |
| transform: none; | |
| } | |
| .submit-button svg, | |
| .download-button svg { | |
| width: 19px; | |
| height: 19px; | |
| } | |
| .progress-area { | |
| display: grid; | |
| gap: 14px; | |
| padding: 0 24px 24px; | |
| } | |
| .progress-shell { | |
| overflow: hidden; | |
| height: 12px; | |
| border-radius: 999px; | |
| background: var(--surface-strong); | |
| } | |
| .progress-fill { | |
| width: 0%; | |
| height: 100%; | |
| border-radius: inherit; | |
| background: linear-gradient(90deg, var(--accent), #0e9f8f); | |
| transition: width 260ms ease; | |
| } | |
| .progress-copy { | |
| margin: 0; | |
| color: var(--muted); | |
| font-size: 0.92rem; | |
| } | |
| .message { | |
| display: none; | |
| margin: 0; | |
| padding: 13px 14px; | |
| border-radius: var(--radius); | |
| font-size: 0.9rem; | |
| } | |
| .message.is-visible { | |
| display: block; | |
| } | |
| .message.error { | |
| border: 1px solid rgba(180, 35, 24, 0.24); | |
| background: #fff1f0; | |
| color: var(--danger); | |
| } | |
| .message.warning { | |
| border: 1px solid rgba(161, 92, 7, 0.24); | |
| background: #fff7ed; | |
| color: var(--warning); | |
| } | |
| .download-slot { | |
| display: none; | |
| } | |
| .download-slot.is-visible { | |
| display: block; | |
| } | |
| @media (max-width: 920px) { | |
| .shell { | |
| width: min(100% - 24px, 720px); | |
| padding-top: 22px; | |
| } | |
| header { | |
| align-items: flex-start; | |
| flex-direction: column; | |
| margin-bottom: 24px; | |
| } | |
| main { | |
| grid-template-columns: 1fr; | |
| gap: 28px; | |
| } | |
| .intro { | |
| padding-top: 0; | |
| } | |
| h1 { | |
| font-size: clamp(2.35rem, 12vw, 4.2rem); | |
| } | |
| } | |
| @media (max-width: 620px) { | |
| .field-row, | |
| .proof-strip { | |
| grid-template-columns: 1fr; | |
| } | |
| .segmented { | |
| grid-template-columns: 1fr; | |
| } | |
| .segmented.two { | |
| grid-template-columns: 1fr; | |
| } | |
| .panel-header, | |
| form, | |
| .progress-area { | |
| padding-left: 18px; | |
| padding-right: 18px; | |
| } | |
| .drop-zone { | |
| min-height: 142px; | |
| padding: 18px; | |
| } | |
| } | |
| @media (prefers-reduced-motion: reduce) { | |
| *, | |
| *::before, | |
| *::after { | |
| scroll-behavior: auto ; | |
| transition: none ; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="shell"> | |
| <header> | |
| <div class="brand" aria-label="BackDropStudio"> | |
| <span class="brand-mark" aria-hidden="true"> | |
| <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> | |
| <path d="M4 7h16" /> | |
| <path d="M4 17h16" /> | |
| <path d="M7 4v16" /> | |
| <path d="M17 4v16" /> | |
| </svg> | |
| </span> | |
| BackDropStudio | |
| </div> | |
| <p class="header-note">Local batch background replacement</p> | |
| </header> | |
| <main> | |
| <section class="intro" aria-labelledby="page-title"> | |
| <h1 id="page-title">Catalog-ready backgrounds without filename drift.</h1> | |
| <p class="intro-copy"> | |
| Upload a ZIP, choose the exact backdrop color, and export a clean batch | |
| with dimensions preserved for SKU-driven imports. | |
| </p> | |
| <div class="proof-strip" aria-label="Processing guarantees"> | |
| <div class="proof-item"> | |
| <strong>Exact canvas color</strong> | |
| <span>PNG mode preserves edited pixels without lossy compression.</span> | |
| </div> | |
| <div class="proof-item"> | |
| <strong>Refined edges</strong> | |
| <span>Pro mode uses alpha matting, feathering, and white-edge cleanup.</span> | |
| </div> | |
| <div class="proof-item"> | |
| <strong>Batch-safe output</strong> | |
| <span>Dimensions stay fixed and filenames remain import-friendly.</span> | |
| </div> | |
| </div> | |
| </section> | |
| <section class="panel" aria-labelledby="upload-title"> | |
| <div class="panel-header"> | |
| <h2 id="upload-title">Batch setup</h2> | |
| <span class="status-dot" id="statusLabel" data-state="ready">Ready</span> | |
| </div> | |
| <form id="processForm"> | |
| <div class="field"> | |
| <label class="field-label" for="zipFile">Product photo ZIP <span>Max 500MB</span></label> | |
| <label class="drop-zone" id="dropZone" for="zipFile"> | |
| <span class="drop-icon" aria-hidden="true"> | |
| <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> | |
| <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" /> | |
| <path d="M17 8 12 3 7 8" /> | |
| <path d="M12 3v12" /> | |
| </svg> | |
| </span> | |
| <span class="drop-copy"> | |
| <strong>Drop your ZIP here or browse</strong> | |
| <span>JPG, PNG, and WebP files are detected automatically.</span> | |
| <span class="file-name" id="fileName">No file selected</span> | |
| </span> | |
| </label> | |
| <input class="file-input" id="zipFile" name="file" type="file" accept=".zip,application/zip" required /> | |
| </div> | |
| <div class="field-row"> | |
| <div class="field"> | |
| <label class="field-label" for="bgColor">Background color</label> | |
| <div class="color-row"> | |
| <input id="colorPicker" type="color" value="#f1f2f2" aria-label="Pick background color" /> | |
| <input id="bgColor" name="bg_color" type="text" value="241,242,242" autocomplete="off" /> | |
| </div> | |
| <p class="field-help">Use RGB like 241,242,242 or hex like #F1F2F2.</p> | |
| </div> | |
| <div class="field"> | |
| <label class="field-label" for="folderName">Output folder</label> | |
| <input id="folderName" name="folder_name" type="text" value="Grey" autocomplete="off" /> | |
| <p class="field-help">This becomes the subfolder inside the ZIP.</p> | |
| </div> | |
| </div> | |
| <div class="field"> | |
| <span class="field-label">Quality profile</span> | |
| <div class="segmented" role="radiogroup" aria-label="Quality profile"> | |
| <input id="qualityPro" name="quality_profile" type="radio" value="pro" checked /> | |
| <label for="qualityPro">Pro quality</label> | |
| <input id="qualityBalanced" name="quality_profile" type="radio" value="balanced" /> | |
| <label for="qualityBalanced">Balanced</label> | |
| <input id="qualityFast" name="quality_profile" type="radio" value="fast" /> | |
| <label for="qualityFast">Fast</label> | |
| </div> | |
| </div> | |
| <div class="field"> | |
| <span class="field-label">Output mode</span> | |
| <div class="segmented two" role="radiogroup" aria-label="Output mode"> | |
| <input id="outputOriginal" name="output_mode" type="radio" value="preserve_original" checked /> | |
| <label for="outputOriginal">Preserve names</label> | |
| <input id="outputPng" name="output_mode" type="radio" value="lossless_png" /> | |
| <label for="outputPng">Lossless PNG</label> | |
| </div> | |
| <p class="field-help">Preserve names keeps extensions. Lossless PNG gives exact edited pixels.</p> | |
| </div> | |
| <button class="submit-button" id="submitButton" type="submit"> | |
| <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> | |
| <path d="M5 12h14" /> | |
| <path d="m12 5 7 7-7 7" /> | |
| </svg> | |
| Start processing | |
| </button> | |
| </form> | |
| <div class="progress-area" aria-live="polite"> | |
| <div class="progress-shell" aria-hidden="true"> | |
| <div class="progress-fill" id="progressFill"></div> | |
| </div> | |
| <p class="progress-copy" id="progressText">No job running.</p> | |
| <p class="message error" id="errorMessage"></p> | |
| <p class="message warning" id="warningMessage"></p> | |
| <div class="download-slot" id="downloadSlot"> | |
| <a class="download-button" id="downloadButton" href="#"> | |
| <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> | |
| <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" /> | |
| <path d="M7 10l5 5 5-5" /> | |
| <path d="M12 15V3" /> | |
| </svg> | |
| Download ZIP | |
| </a> | |
| </div> | |
| </div> | |
| </section> | |
| </main> | |
| </div> | |
| <script> | |
| const form = document.querySelector("#processForm"); | |
| const zipFile = document.querySelector("#zipFile"); | |
| const fileName = document.querySelector("#fileName"); | |
| const dropZone = document.querySelector("#dropZone"); | |
| const submitButton = document.querySelector("#submitButton"); | |
| const statusLabel = document.querySelector("#statusLabel"); | |
| const progressFill = document.querySelector("#progressFill"); | |
| const progressText = document.querySelector("#progressText"); | |
| const errorMessage = document.querySelector("#errorMessage"); | |
| const warningMessage = document.querySelector("#warningMessage"); | |
| const downloadSlot = document.querySelector("#downloadSlot"); | |
| const downloadButton = document.querySelector("#downloadButton"); | |
| const bgColor = document.querySelector("#bgColor"); | |
| const colorPicker = document.querySelector("#colorPicker"); | |
| let pollTimer = null; | |
| function rgbToHex(rgb) { | |
| return `#${rgb.map((channel) => channel.toString(16).padStart(2, "0")).join("")}`; | |
| } | |
| function parseColor(value) { | |
| const trimmed = value.trim(); | |
| if (/^#[0-9a-fA-F]{6}$/.test(trimmed)) { | |
| return { | |
| hex: trimmed.toLowerCase(), | |
| rgb: [1, 3, 5].map((index) => Number.parseInt(trimmed.slice(index, index + 2), 16)), | |
| }; | |
| } | |
| const parts = trimmed.split(",").map((part) => Number.parseInt(part.trim(), 10)); | |
| if (parts.length === 3 && parts.every((part) => Number.isInteger(part) && part >= 0 && part <= 255)) { | |
| return { hex: rgbToHex(parts), rgb: parts }; | |
| } | |
| return null; | |
| } | |
| function setStatus(text, state = "ready") { | |
| statusLabel.textContent = text; | |
| statusLabel.dataset.state = state; | |
| } | |
| function showMessage(element, message) { | |
| element.textContent = message || ""; | |
| element.classList.toggle("is-visible", Boolean(message)); | |
| } | |
| function resetMessages() { | |
| showMessage(errorMessage, ""); | |
| showMessage(warningMessage, ""); | |
| downloadSlot.classList.remove("is-visible"); | |
| downloadButton.removeAttribute("href"); | |
| } | |
| function updateFileName() { | |
| const selectedFile = zipFile.files && zipFile.files[0]; | |
| fileName.textContent = selectedFile ? selectedFile.name : "No file selected"; | |
| } | |
| function syncColorFromText() { | |
| const parsed = parseColor(bgColor.value); | |
| if (parsed) { | |
| colorPicker.value = parsed.hex; | |
| } | |
| } | |
| function syncColorFromPicker() { | |
| const parsed = parseColor(colorPicker.value); | |
| if (parsed) { | |
| bgColor.value = parsed.rgb.join(","); | |
| } | |
| } | |
| function setProgress(status) { | |
| const total = status.total || 0; | |
| const completed = status.completed || 0; | |
| const percent = total > 0 ? Math.round((completed / total) * 100) : 0; | |
| progressFill.style.width = `${Math.min(percent, 100)}%`; | |
| if (status.status === "processing") { | |
| progressText.textContent = total > 0 ? `Processing ${completed} / ${total} files...` : "Preparing the batch..."; | |
| setStatus("Processing", "processing"); | |
| } else if (status.status === "done") { | |
| progressFill.style.width = "100%"; | |
| progressText.textContent = `Done. Exported ${completed} image${completed === 1 ? "" : "s"}.`; | |
| setStatus("Ready to download", "done"); | |
| } else if (status.status === "failed") { | |
| progressText.textContent = "The job failed before a ZIP could be created."; | |
| setStatus("Failed", "error"); | |
| } | |
| } | |
| async function pollStatus(jobId) { | |
| try { | |
| const response = await fetch(`/api/status/${jobId}`); | |
| if (!response.ok) { | |
| throw new Error("Unable to read job status."); | |
| } | |
| const status = await response.json(); | |
| setProgress(status); | |
| if (status.failed_files && status.failed_files.length > 0) { | |
| showMessage( | |
| warningMessage, | |
| `Skipped ${status.failed_files.length} file${status.failed_files.length === 1 ? "" : "s"}: ${status.failed_files.join(", ")}` | |
| ); | |
| } | |
| if (status.status === "done") { | |
| window.clearInterval(pollTimer); | |
| pollTimer = null; | |
| submitButton.disabled = false; | |
| downloadButton.href = `/api/download/${jobId}`; | |
| downloadSlot.classList.add("is-visible"); | |
| } | |
| if (status.status === "failed") { | |
| window.clearInterval(pollTimer); | |
| pollTimer = null; | |
| submitButton.disabled = false; | |
| showMessage(errorMessage, status.error || "Processing failed."); | |
| } | |
| } catch (error) { | |
| window.clearInterval(pollTimer); | |
| pollTimer = null; | |
| submitButton.disabled = false; | |
| setStatus("Error", "error"); | |
| showMessage(errorMessage, error.message || "Unable to check status."); | |
| } | |
| } | |
| zipFile.addEventListener("change", updateFileName); | |
| bgColor.addEventListener("input", syncColorFromText); | |
| colorPicker.addEventListener("input", syncColorFromPicker); | |
| syncColorFromText(); | |
| ["dragenter", "dragover"].forEach((eventName) => { | |
| dropZone.addEventListener(eventName, (event) => { | |
| event.preventDefault(); | |
| dropZone.classList.add("is-dragging"); | |
| }); | |
| }); | |
| ["dragleave", "drop"].forEach((eventName) => { | |
| dropZone.addEventListener(eventName, (event) => { | |
| event.preventDefault(); | |
| dropZone.classList.remove("is-dragging"); | |
| }); | |
| }); | |
| dropZone.addEventListener("drop", (event) => { | |
| const [file] = event.dataTransfer.files; | |
| if (!file) { | |
| return; | |
| } | |
| const dataTransfer = new DataTransfer(); | |
| dataTransfer.items.add(file); | |
| zipFile.files = dataTransfer.files; | |
| updateFileName(); | |
| }); | |
| form.addEventListener("submit", async (event) => { | |
| event.preventDefault(); | |
| resetMessages(); | |
| if (!parseColor(bgColor.value)) { | |
| showMessage(errorMessage, "Use a valid RGB value or #RRGGBB color."); | |
| setStatus("Error", "error"); | |
| return; | |
| } | |
| submitButton.disabled = true; | |
| setStatus("Uploading", "processing"); | |
| progressText.textContent = "Uploading ZIP..."; | |
| progressFill.style.width = "0%"; | |
| if (pollTimer) { | |
| window.clearInterval(pollTimer); | |
| pollTimer = null; | |
| } | |
| try { | |
| const response = await fetch("/api/process", { | |
| method: "POST", | |
| body: new FormData(form), | |
| }); | |
| const payload = await response.json().catch(() => ({})); | |
| if (!response.ok) { | |
| throw new Error(payload.detail || "Upload failed."); | |
| } | |
| const jobId = payload.job_id; | |
| await pollStatus(jobId); | |
| pollTimer = window.setInterval(() => pollStatus(jobId), 1500); | |
| } catch (error) { | |
| submitButton.disabled = false; | |
| setStatus("Error", "error"); | |
| progressText.textContent = "No job running."; | |
| showMessage(errorMessage, error.message || "Upload failed."); | |
| } | |
| }); | |
| </script> | |
| </body> | |
| </html> | |