@windrun-huaiin/third-ui 5.12.0 → 5.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main/index.js +32 -39
- package/dist/main/index.js.map +1 -1
- package/dist/main/index.mjs +32 -39
- package/dist/main/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/main/gallery.tsx +56 -46
package/dist/main/index.js
CHANGED
|
@@ -2771,59 +2771,48 @@ function Gallery({ sectionClassName, button }) {
|
|
|
2771
2771
|
const galleryItems = t.raw("prompts");
|
|
2772
2772
|
const defaultImgUrl = t.raw("defaultImgUrl");
|
|
2773
2773
|
const [imageErrors, setImageErrors] = (0, import_react35.useState)(/* @__PURE__ */ new Set());
|
|
2774
|
+
const [downloadingItems, setDownloadingItems] = (0, import_react35.useState)(/* @__PURE__ */ new Set());
|
|
2775
|
+
const cdnProxyUrl = process.env.NEXT_PUBLIC_STYLE_CDN_PROXY_URL;
|
|
2774
2776
|
const handleDownload = (item, index) => __async(null, null, function* () {
|
|
2775
2777
|
var _a;
|
|
2778
|
+
if (downloadingItems.has(index)) {
|
|
2779
|
+
return;
|
|
2780
|
+
}
|
|
2781
|
+
setDownloadingItems((prev) => new Set(prev).add(index));
|
|
2776
2782
|
try {
|
|
2777
|
-
const
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
});
|
|
2782
|
-
if (!response.ok) {
|
|
2783
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
|
2784
|
-
}
|
|
2785
|
-
const blob = yield response.blob();
|
|
2786
|
-
const url = window.URL.createObjectURL(blob);
|
|
2787
|
-
const contentType = response.headers.get("content-type");
|
|
2783
|
+
const originalUrl = new URL(item.url);
|
|
2784
|
+
const filename = originalUrl.pathname.substring(1);
|
|
2785
|
+
const proxyUrl = `${cdnProxyUrl}/${encodeURIComponent(filename)}`;
|
|
2786
|
+
const urlExtension = (_a = item.url.split(".").pop()) == null ? void 0 : _a.toLowerCase();
|
|
2788
2787
|
let extension = ".webp";
|
|
2789
|
-
if (
|
|
2790
|
-
|
|
2791
|
-
case "image/jpeg":
|
|
2792
|
-
case "image/jpg":
|
|
2793
|
-
extension = ".jpg";
|
|
2794
|
-
break;
|
|
2795
|
-
case "image/png":
|
|
2796
|
-
extension = ".png";
|
|
2797
|
-
break;
|
|
2798
|
-
case "image/gif":
|
|
2799
|
-
extension = ".gif";
|
|
2800
|
-
break;
|
|
2801
|
-
case "image/webp":
|
|
2802
|
-
extension = ".webp";
|
|
2803
|
-
break;
|
|
2804
|
-
case "image/svg+xml":
|
|
2805
|
-
extension = ".svg";
|
|
2806
|
-
break;
|
|
2807
|
-
default:
|
|
2808
|
-
const urlExtension = (_a = item.url.split(".").pop()) == null ? void 0 : _a.toLowerCase();
|
|
2809
|
-
if (urlExtension && ["jpg", "jpeg", "png", "gif", "webp", "svg"].includes(urlExtension)) {
|
|
2810
|
-
extension = `.${urlExtension}`;
|
|
2811
|
-
}
|
|
2812
|
-
}
|
|
2788
|
+
if (urlExtension && ["jpg", "jpeg", "png", "gif", "webp", "svg"].includes(urlExtension)) {
|
|
2789
|
+
extension = `.${urlExtension}`;
|
|
2813
2790
|
}
|
|
2814
2791
|
const downloadPrefix = t("downloadPrefix");
|
|
2792
|
+
const response = yield fetch(proxyUrl);
|
|
2793
|
+
if (!response.ok) {
|
|
2794
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
2795
|
+
}
|
|
2796
|
+
const blob = yield response.blob();
|
|
2797
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
2815
2798
|
const a = document.createElement("a");
|
|
2816
|
-
a.href =
|
|
2799
|
+
a.href = blobUrl;
|
|
2817
2800
|
a.download = `${downloadPrefix}-${index + 1}${extension}`;
|
|
2818
2801
|
a.style.display = "none";
|
|
2819
2802
|
document.body.appendChild(a);
|
|
2820
2803
|
a.click();
|
|
2821
2804
|
setTimeout(() => {
|
|
2822
|
-
window.URL.revokeObjectURL(url);
|
|
2823
2805
|
document.body.removeChild(a);
|
|
2806
|
+
URL.revokeObjectURL(blobUrl);
|
|
2824
2807
|
}, 100);
|
|
2825
2808
|
} catch (error) {
|
|
2826
2809
|
console.error("Download failed:", error);
|
|
2810
|
+
} finally {
|
|
2811
|
+
setDownloadingItems((prev) => {
|
|
2812
|
+
const newSet = new Set(prev);
|
|
2813
|
+
newSet.delete(index);
|
|
2814
|
+
return newSet;
|
|
2815
|
+
});
|
|
2827
2816
|
}
|
|
2828
2817
|
});
|
|
2829
2818
|
const handleImageError = (index) => {
|
|
@@ -2857,8 +2846,12 @@ function Gallery({ sectionClassName, button }) {
|
|
|
2857
2846
|
"button",
|
|
2858
2847
|
{
|
|
2859
2848
|
onClick: () => handleDownload(item, index),
|
|
2860
|
-
|
|
2861
|
-
|
|
2849
|
+
disabled: downloadingItems.has(index),
|
|
2850
|
+
className: cn(
|
|
2851
|
+
"p-2 rounded-full transition-all duration-300",
|
|
2852
|
+
downloadingItems.has(index) ? "bg-black/30 text-white/50" : "bg-black/50 hover:bg-black/70 text-white/80 hover:text-white"
|
|
2853
|
+
),
|
|
2854
|
+
children: downloadingItems.has(index) ? /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(globalLucideIcons.Loader2, { className: "h-5 w-5 text-white animate-spin" }) : /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(globalLucideIcons.Download, { className: "h-5 w-5 text-white" })
|
|
2862
2855
|
}
|
|
2863
2856
|
) })
|
|
2864
2857
|
] }, index)) }),
|