import React, { useEffect, useState } from 'react'; import { api } from '../../config/api'; interface AdminAuthenticatedVideoProps extends React.VideoHTMLAttributes { src: string; fallback?: React.ReactNode; } export const AdminAuthenticatedVideo: React.FC = ({ src, fallback, ...props }) => { const [videoSrc, setVideoSrc] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(false); useEffect(() => { let cancelled = false; let objectUrl: string | null = null; const loadVideo = async () => { try { setLoading(true); setError(false); setVideoSrc(null); const response = await api.get(src, { responseType: 'blob' }); if (!cancelled) { objectUrl = URL.createObjectURL(response.data); setVideoSrc(objectUrl); setLoading(false); } } catch { if (!cancelled) { setError(true); setLoading(false); } } }; if (src) { loadVideo(); } return () => { cancelled = true; if (objectUrl) { URL.revokeObjectURL(objectUrl); } }; }, [src]); if (loading) { return
; } if (error || !videoSrc) { return fallback ? ( <>{fallback} ) : (
Failed to load
); } return (