Jesse311 commited on
Commit
0730f73
·
verified ·
1 Parent(s): bf81007

Update generation.html

Browse files
Files changed (1) hide show
  1. generation.html +33 -33
generation.html CHANGED
@@ -377,11 +377,7 @@
377
  resultContainer.className = "mt-6 grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-4";
378
  document.body.appendChild(resultContainer);
379
  }
380
- resultContainer.innerHTML = `
381
- <div class="col-span-full flex justify-center items-center">
382
- <img src="https://i.gifer.com/YCZH.gif" alt="loading" class="w-20 h-20"/>
383
- </div>
384
- `;
385
 
386
  // 1. Convert current image to base64
387
  const imageBlob = await fetch(currentImageUrl).then(r => r.blob());
@@ -415,17 +411,30 @@
415
  if (!searchResp.ok) throw new Error("Search failed");
416
  const result = await searchResp.json();
417
 
418
- // 5. Process results
419
- for (const r of result.results) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
420
  try {
421
- const proxyUrl = r.proxyUrl;
422
- const resp = await fetch(proxyUrl);
423
  const blob = await resp.blob();
424
-
425
  // Send to dewatermark API
426
  let formData = new FormData();
427
  formData.append("file", blob, "input.webp");
428
-
429
  const cleanResp = await fetch("https://nowatermark.p.rapidapi.com/dewatermark", {
430
  method: "POST",
431
  headers: {
@@ -434,35 +443,26 @@
434
  },
435
  body: formData
436
  });
437
-
438
  if (!cleanResp.ok) {
439
- console.warn("Skipping image, dewatermark failed:", r);
 
440
  continue;
441
  }
442
-
443
- let finalBlob = await cleanResp.blob();
444
- let imgUrl = URL.createObjectURL(finalBlob);
445
-
446
- // Display
447
- let wrapper = document.createElement("div");
448
- wrapper.className = "m-2 text-center";
449
-
450
- let img = document.createElement("img");
451
  img.src = imgUrl;
452
  img.className = "w-40 h-40 object-cover rounded-md shadow-md";
453
-
454
- // let link = document.createElement("a");
455
- // link.href = r.urlList[0]?.sourceUrl || "#";
456
- // link.textContent = "Source";
457
- // link.target = "_blank";
458
- // link.className = "block mt-1 text-blue-500 underline text-sm";
459
-
460
- wrapper.appendChild(img);
461
- // wrapper.appendChild(link);
462
- resultContainer.appendChild(wrapper);
463
-
464
  } catch (err) {
465
  console.warn("Error processing one result:", err);
 
466
  }
467
  }
468
 
 
377
  resultContainer.className = "mt-6 grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-4";
378
  document.body.appendChild(resultContainer);
379
  }
380
+ resultContainer.innerHTML = "";
 
 
 
 
381
 
382
  // 1. Convert current image to base64
383
  const imageBlob = await fetch(currentImageUrl).then(r => r.blob());
 
411
  if (!searchResp.ok) throw new Error("Search failed");
412
  const result = await searchResp.json();
413
 
414
+ // 4. Create placeholders with spinner for each result
415
+ const placeholders = result.results.map(r => {
416
+ const wrapper = document.createElement("div");
417
+ wrapper.className = "m-2 text-center";
418
+
419
+ const spinner = document.createElement("img");
420
+ spinner.src = "https://i.gifer.com/YCZH.gif";
421
+ spinner.className = "w-20 h-20 mx-auto";
422
+
423
+ wrapper.appendChild(spinner);
424
+ resultContainer.appendChild(wrapper);
425
+ return { wrapper, data: r };
426
+ });
427
+
428
+ // 5. Load images one by one
429
+ for (const item of placeholders) {
430
  try {
431
+ const resp = await fetch(item.data.proxyUrl);
 
432
  const blob = await resp.blob();
433
+
434
  // Send to dewatermark API
435
  let formData = new FormData();
436
  formData.append("file", blob, "input.webp");
437
+
438
  const cleanResp = await fetch("https://nowatermark.p.rapidapi.com/dewatermark", {
439
  method: "POST",
440
  headers: {
 
443
  },
444
  body: formData
445
  });
446
+
447
  if (!cleanResp.ok) {
448
+ console.warn("Skipping image, dewatermark failed:", item.data);
449
+ item.wrapper.innerHTML = ""; // Remove spinner
450
  continue;
451
  }
452
+
453
+ const finalBlob = await cleanResp.blob();
454
+ const imgUrl = URL.createObjectURL(finalBlob);
455
+
456
+ // Replace spinner with final image
457
+ item.wrapper.innerHTML = "";
458
+ const img = document.createElement("img");
 
 
459
  img.src = imgUrl;
460
  img.className = "w-40 h-40 object-cover rounded-md shadow-md";
461
+ item.wrapper.appendChild(img);
462
+
 
 
 
 
 
 
 
 
 
463
  } catch (err) {
464
  console.warn("Error processing one result:", err);
465
+ item.wrapper.innerHTML = ""; // Remove spinner if error
466
  }
467
  }
468