diff --git a/app/files/[...path]/route.js b/app/files/[...path]/route.js
index 00d001c..b43796f 100644
--- a/app/files/[...path]/route.js
+++ b/app/files/[...path]/route.js
@@ -40,14 +40,14 @@ export async function GET(req, { params }) {
const data = fs.readFileSync(localPath);
return new NextResponse(data, {
status: 200,
- headers: { 'Content-Type': getContentType(localPath) }
+ headers: { 'Content-Type': getContentType(localPath), 'Cache-Control': 'public, max-age=31536000, immutable' }
});
}
const remoteUrl = `${BACKEND_SERVER_URL}/files/${fileName}`;
const res = await fetch(remoteUrl);
if (!res.ok) {
- return new NextResponse('Not Found', { status: 404 });
+ return new NextResponse('Not Found', { status: 404, headers: { 'Cache-Control': 'no-store' } });
}
const arrayBuffer = await res.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);
@@ -58,10 +58,10 @@ export async function GET(req, { params }) {
return new NextResponse(buffer, {
status: 200,
- headers: { 'Content-Type': getContentType(localPath) }
+ headers: { 'Content-Type': getContentType(localPath), 'Cache-Control': 'public, max-age=31536000, immutable' }
});
} catch (e) {
- return new NextResponse('Server Error', { status: 500 });
+ return new NextResponse('Server Error', { status: 500, headers: { 'Cache-Control': 'no-store' } });
}
}
diff --git a/components/products/ProductImageGallery.jsx b/components/products/ProductImageGallery.jsx
index cb466d7..9115d0e 100644
--- a/components/products/ProductImageGallery.jsx
+++ b/components/products/ProductImageGallery.jsx
@@ -10,6 +10,37 @@ import "swiper/css/pagination";
import "swiper/css/thumbs";
import "swiper/css/free-mode";
+const ImageWithRetry = ({ src, alt, className }) => {
+ const [imageSrc, setImageSrc] = useState(src);
+ const retryCountRef = useRef(0);
+
+ useEffect(() => {
+ setImageSrc(src);
+ retryCountRef.current = 0;
+ }, [src]);
+
+ const handleError = useCallback(() => {
+ if (retryCountRef.current >= 3) return;
+ retryCountRef.current += 1;
+ const delay = 300 * retryCountRef.current;
+ setTimeout(() => {
+ const url = new URL(imageSrc, typeof window !== 'undefined' ? window.location.origin : 'http://localhost');
+ url.searchParams.set('v', String(Date.now()));
+ setImageSrc(url.pathname + url.search);
+ }, delay);
+ }, [imageSrc]);
+
+ return (
+
+ );
+};
+
const ProductImageGallery = ({ data }) => {
const [currentImageIndex, setCurrentImageIndex] = useState(0);
const [thumbsSwiper, setThumbsSwiper] = useState(null);
@@ -136,14 +167,10 @@ const ProductImageGallery = ({ data }) => {
}
}}
>
-
{
- e.target.style.display = 'none';
- }}
/>