From 895b0dd00ed849013621950c5de9394858bdafbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Fri, 4 Sep 2026 16:52:29 -0300 Subject: [PATCH] fix: recover failed banner cover previews --- index.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/index.tsx b/index.tsx index 39e1012..0b8fad3 100644 --- a/index.tsx +++ b/index.tsx @@ -2,6 +2,23 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; import App from './App'; +// Covers uploaded to Bunny Storage are normally served directly by its CDN. +// If that CDN URL is unavailable in a browser, retry the safe Academy proxy. +// This also protects previews in administrative screens that render native img +// elements (for example a homepage-banner preview). +document.addEventListener('error', (event) => { + const image = event.target; + if (!(image instanceof HTMLImageElement) || image.dataset.coverFallbackApplied === 'true') return; + try { + const filename = new URL(image.currentSrc || image.src, window.location.origin).pathname.split('/').pop() || ''; + if (!/^[0-9a-f]{8}-[0-9a-f-]{27}\.(?:jpg|png|webp)$/i.test(filename)) return; + image.dataset.coverFallbackApplied = 'true'; + image.src = `${import.meta.env.VITE_API_URL || '/api/v1'}/courses/covers/${filename}`; + } catch { + // Keep the browser's normal failed-image behavior for non-cover assets. + } +}, true); + const rootElement = document.getElementById('root'); if (!rootElement) { throw new Error("Could not find root element to mount to");