@plugable-io/react 0.0.6 → 0.0.7
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/index.js +36 -18
- package/dist/index.mjs +36 -18
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -601,29 +601,47 @@ function FileImage({
|
|
|
601
601
|
return;
|
|
602
602
|
}
|
|
603
603
|
if (file.download_url) {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
604
|
+
let response = null;
|
|
605
|
+
try {
|
|
606
|
+
response = await fetch(file.download_url, {
|
|
607
|
+
headers: {
|
|
608
|
+
"Cache-Control": "private, max-age=31536000",
|
|
609
|
+
"If-None-Match": file.checksum
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
if (!response.ok) {
|
|
613
|
+
const downloadUrlKey = `${file.id}-${file.download_url}`;
|
|
614
|
+
if (response.status === 403 && onRefetchNeeded && refetchAttemptedRef.current !== downloadUrlKey) {
|
|
615
|
+
refetchAttemptedRef.current = downloadUrlKey;
|
|
616
|
+
imageCache.delete(cacheKey);
|
|
617
|
+
await onRefetchNeeded();
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
throw new Error(`Failed to fetch image: ${response.statusText}`);
|
|
608
621
|
}
|
|
609
|
-
|
|
610
|
-
|
|
622
|
+
const blob = await response.blob();
|
|
623
|
+
objectUrl = URL.createObjectURL(blob);
|
|
624
|
+
imageCache.set(cacheKey, objectUrl);
|
|
625
|
+
if (isMounted) {
|
|
626
|
+
setImageSrc(objectUrl);
|
|
627
|
+
setIsLoading(false);
|
|
628
|
+
refetchAttemptedRef.current = null;
|
|
629
|
+
}
|
|
630
|
+
} catch (fetchError) {
|
|
611
631
|
const downloadUrlKey = `${file.id}-${file.download_url}`;
|
|
612
|
-
|
|
632
|
+
const isNetworkError = !response && (fetchError.message?.includes("Failed to fetch") || fetchError.message?.includes("CORS") || fetchError.name === "TypeError" || fetchError.message?.includes("network") || fetchError.message?.includes("ERR_FAILED"));
|
|
633
|
+
const is403Error = response?.status === 403;
|
|
634
|
+
if ((isNetworkError || is403Error) && onRefetchNeeded && refetchAttemptedRef.current !== downloadUrlKey) {
|
|
613
635
|
refetchAttemptedRef.current = downloadUrlKey;
|
|
614
636
|
imageCache.delete(cacheKey);
|
|
615
|
-
|
|
616
|
-
|
|
637
|
+
try {
|
|
638
|
+
await onRefetchNeeded();
|
|
639
|
+
return;
|
|
640
|
+
} catch (refetchError) {
|
|
641
|
+
console.error("Failed to refetch file:", refetchError);
|
|
642
|
+
}
|
|
617
643
|
}
|
|
618
|
-
throw
|
|
619
|
-
}
|
|
620
|
-
const blob = await response.blob();
|
|
621
|
-
objectUrl = URL.createObjectURL(blob);
|
|
622
|
-
imageCache.set(cacheKey, objectUrl);
|
|
623
|
-
if (isMounted) {
|
|
624
|
-
setImageSrc(objectUrl);
|
|
625
|
-
setIsLoading(false);
|
|
626
|
-
refetchAttemptedRef.current = null;
|
|
644
|
+
throw fetchError;
|
|
627
645
|
}
|
|
628
646
|
} else {
|
|
629
647
|
throw new Error("No download URL available for file");
|
package/dist/index.mjs
CHANGED
|
@@ -558,29 +558,47 @@ function FileImage({
|
|
|
558
558
|
return;
|
|
559
559
|
}
|
|
560
560
|
if (file.download_url) {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
561
|
+
let response = null;
|
|
562
|
+
try {
|
|
563
|
+
response = await fetch(file.download_url, {
|
|
564
|
+
headers: {
|
|
565
|
+
"Cache-Control": "private, max-age=31536000",
|
|
566
|
+
"If-None-Match": file.checksum
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
if (!response.ok) {
|
|
570
|
+
const downloadUrlKey = `${file.id}-${file.download_url}`;
|
|
571
|
+
if (response.status === 403 && onRefetchNeeded && refetchAttemptedRef.current !== downloadUrlKey) {
|
|
572
|
+
refetchAttemptedRef.current = downloadUrlKey;
|
|
573
|
+
imageCache.delete(cacheKey);
|
|
574
|
+
await onRefetchNeeded();
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
throw new Error(`Failed to fetch image: ${response.statusText}`);
|
|
565
578
|
}
|
|
566
|
-
|
|
567
|
-
|
|
579
|
+
const blob = await response.blob();
|
|
580
|
+
objectUrl = URL.createObjectURL(blob);
|
|
581
|
+
imageCache.set(cacheKey, objectUrl);
|
|
582
|
+
if (isMounted) {
|
|
583
|
+
setImageSrc(objectUrl);
|
|
584
|
+
setIsLoading(false);
|
|
585
|
+
refetchAttemptedRef.current = null;
|
|
586
|
+
}
|
|
587
|
+
} catch (fetchError) {
|
|
568
588
|
const downloadUrlKey = `${file.id}-${file.download_url}`;
|
|
569
|
-
|
|
589
|
+
const isNetworkError = !response && (fetchError.message?.includes("Failed to fetch") || fetchError.message?.includes("CORS") || fetchError.name === "TypeError" || fetchError.message?.includes("network") || fetchError.message?.includes("ERR_FAILED"));
|
|
590
|
+
const is403Error = response?.status === 403;
|
|
591
|
+
if ((isNetworkError || is403Error) && onRefetchNeeded && refetchAttemptedRef.current !== downloadUrlKey) {
|
|
570
592
|
refetchAttemptedRef.current = downloadUrlKey;
|
|
571
593
|
imageCache.delete(cacheKey);
|
|
572
|
-
|
|
573
|
-
|
|
594
|
+
try {
|
|
595
|
+
await onRefetchNeeded();
|
|
596
|
+
return;
|
|
597
|
+
} catch (refetchError) {
|
|
598
|
+
console.error("Failed to refetch file:", refetchError);
|
|
599
|
+
}
|
|
574
600
|
}
|
|
575
|
-
throw
|
|
576
|
-
}
|
|
577
|
-
const blob = await response.blob();
|
|
578
|
-
objectUrl = URL.createObjectURL(blob);
|
|
579
|
-
imageCache.set(cacheKey, objectUrl);
|
|
580
|
-
if (isMounted) {
|
|
581
|
-
setImageSrc(objectUrl);
|
|
582
|
-
setIsLoading(false);
|
|
583
|
-
refetchAttemptedRef.current = null;
|
|
601
|
+
throw fetchError;
|
|
584
602
|
}
|
|
585
603
|
} else {
|
|
586
604
|
throw new Error("No download URL available for file");
|