Spaces:
Sleeping
Sleeping
File size: 26,855 Bytes
0d7bef5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 | <!doctype html>
<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 !important;
transition: none !important;
}
}
</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>
|