import type { OdFileObject } from '../../types' import { useState } from 'react' import { useRouter } from 'next/router' import { useClipboard } from 'use-clipboard-copy' import DPlayer from 'react-dplayer' import toast from 'react-hot-toast' import { useTranslation } from 'next-i18next' import { useAsync } from 'react-async-hook' import { getBaseUrl } from '../../utils/getBaseUrl' import { getExtension } from '../../utils/getFileIcon' import { getReadablePath } from '../../utils/getReadablePath' import { DownloadButton } from '../DownloadBtnGtoup' import { DownloadBtnContainer, PreviewContainer } from './Containers' import FourOhFour from '../FourOhFour' import Loading from '../Loading' import CustomEmbedLinkMenu from '../CustomEmbedLinkMenu' const VideoPreview: React.FC<{ file: OdFileObject }> = ({ file }) => { const { asPath } = useRouter() const clipboard = useClipboard() const [menuOpen, setMenuOpen] = useState(false) const { t } = useTranslation() // OneDrive generates thumbnails for its video files, we pick the thumbnail with the highest resolution const thumbnail = `/api/thumbnail?path=${asPath}&size=large` // We assume subtitle files are beside the video with the same name, only webvtt '.vtt' files are supported const subtitle = `/api?path=${asPath.substring(0, asPath.lastIndexOf('.'))}.vtt&raw=true` const isFlv = getExtension(file.name) === 'flv' const { loading, error, result: mpegts, } = useAsync(async () => { if (isFlv) { return (await import('mpegts.js')).default } }, [isFlv]) return ( <> {error ? ( ) : loading && isFlv ? ( ) : ( { const flvPlayer = mpegts!.createPlayer({ type: 'flv', url: video.src, }) flvPlayer.attachMediaElement(video) flvPlayer.load() }, }, }, subtitle: { url: subtitle }, }} /> )}
window.open(file['@microsoft.graph.downloadUrl'])} btnColor="blue" btnText={t('Download')} btnIcon="file-download" /> {/* window.open(`/api/proxy?url=${encodeURIComponent(file['@microsoft.graph.downloadUrl'])}`) } btnColor="teal" btnText={t('Proxy download')} btnIcon="download" /> */} { clipboard.copy(`${getBaseUrl()}/api?path=${getReadablePath(asPath)}&raw=true`) toast.success(t('Copied direct link to clipboard.')) }} btnColor="pink" btnText={t('Copy direct link')} btnIcon="copy" /> setMenuOpen(true)} btnColor="teal" btnText={t('Customise link')} btnIcon="pen" /> window.open(`iina://weblink?url=${file['@microsoft.graph.downloadUrl']}`)} btnText="IINA" btnImage="/players/iina.png" /> window.open(`vlc://${file['@microsoft.graph.downloadUrl']}`)} btnText="VLC" btnImage="/players/vlc.png" /> window.open(`potplayer://${file['@microsoft.graph.downloadUrl']}`)} btnText="PotPlayer" btnImage="/players/potplayer.png" />
) } export default VideoPreview