import { Button } from '@heroui/button'; import { Modal, ModalBody, ModalContent, ModalFooter, ModalHeader, } from '@heroui/modal'; import { Spinner } from '@heroui/spinner'; import { useRequest } from 'ahooks'; import path from 'path-browserify'; import { useEffect } from 'react'; import FileManager from '@/controllers/file_manager'; interface FilePreviewModalProps { isOpen: boolean filePath: string onClose: () => void } export const videoExts = ['.mp4', '.webm']; export const audioExts = ['.mp3', '.wav']; export const supportedPreviewExts = [...videoExts, ...audioExts]; export default function FilePreviewModal ({ isOpen, filePath, onClose, }: FilePreviewModalProps) { const ext = path.extname(filePath).toLowerCase(); const { data, loading, error, run } = useRequest( async () => FileManager.downloadToURL(filePath), { refreshDeps: [filePath], manual: true, refreshDepsAction: () => { const ext = path.extname(filePath).toLowerCase(); if (!filePath || !supportedPreviewExts.includes(ext)) { return; } run(); }, } ); useEffect(() => { if (filePath) { run(); } }, [filePath]); let contentElement = null; if (!supportedPreviewExts.includes(ext)) { contentElement =