import React from 'react'; import FileSaver from 'file-saver'; import classNames from 'classnames'; import { Box, Chip, Header, IconButton, Text, as } from 'folds'; import { Icon, Icons } from '../icons'; import * as css from './VideoViewer.css'; import { downloadMedia } from '../../utils/matrix'; import { getCurrentAccessToken } from '../../utils/auth'; export type VideoViewerProps = { alt: string; src: string; requestClose: () => void; }; export const VideoViewer = as<'div', VideoViewerProps>( ({ className, alt, src, requestClose, ...props }, ref) => { const handleDownload = async () => { try { const fileContent = await downloadMedia(src, getCurrentAccessToken()); FileSaver.saveAs(fileContent, alt); } catch (error) { console.warn('[VideoViewer] Failed to download media:', error); try { const response = await fetch(src); if (response.ok) { const blob = await response.blob(); FileSaver.saveAs(blob, alt); } } catch { window.open(src, '_blank'); } } }; return (
{alt} } > Download
); } );