diff --git a/src/app/app/[slug]/page.tsx b/src/app/app/[slug]/page.tsx index 6ee668f..88a60b0 100644 --- a/src/app/app/[slug]/page.tsx +++ b/src/app/app/[slug]/page.tsx @@ -28,22 +28,29 @@ export default function BlobPage({ params }: { params: { slug: string } }) { color: "#000000" } ]); + const [accessed, setAccessed] = useState(false); + const [loading, setLoading] = useState(false); const router = useRouter(); useEffect(() => { - if (encodedBlobUrl) { + if (encodedBlobUrl && !accessed) { + setLoading(true); + try { const decodedBlobUrl = atob(encodedBlobUrl); setFileUrl(decodedBlobUrl); + setAccessed(true); - // Check if the file URL is valid - fetch(decodedBlobUrl, { method: 'HEAD' }) + fetch(decodedBlobUrl) .then(response => { + setLoading(false); if (!response.ok) { + console.error("Blob URL is not accessible."); notFound(); } }) - .catch(() => { + .catch(error => { + console.error("Fetch error:", error); notFound(); }); } catch (error) { @@ -51,7 +58,7 @@ export default function BlobPage({ params }: { params: { slug: string } }) { notFound(); } } - }, [encodedBlobUrl]); + }, [encodedBlobUrl, accessed]); const handleInputChange = (index: number, field: string, value: any) => { setTexts((prevTexts) => @@ -72,13 +79,22 @@ export default function BlobPage({ params }: { params: { slug: string } }) { }; const notFound = () => { - router.push("/") - } + router.push("/"); + }; return (
- {fileUrl ? ( + {loading ? ( +
+ Loading... +
+ ) : fileUrl ? ( <> {fileUrl.endsWith(".mp4") ? ( <> @@ -126,7 +142,7 @@ export default function BlobPage({ params }: { params: { slug: string } }) {