2022-02-02 08:41:30 +00:00
|
|
|
import type { OdFileObject } from '../../types'
|
2021-08-15 20:26:08 +00:00
|
|
|
import { useRouter } from 'next/router'
|
2021-08-23 14:02:06 +00:00
|
|
|
import { useClipboard } from 'use-clipboard-copy'
|
2022-02-02 13:36:12 +00:00
|
|
|
import DPlayer from 'react-dplayer'
|
2021-12-29 09:08:10 +00:00
|
|
|
import toast from 'react-hot-toast'
|
2021-06-24 13:54:59 +00:00
|
|
|
|
2021-12-17 15:16:18 +00:00
|
|
|
import { getBaseUrl } from '../../utils/getBaseUrl'
|
2021-12-29 07:23:47 +00:00
|
|
|
import { DownloadButton } from '../DownloadBtnGtoup'
|
2022-01-06 08:34:16 +00:00
|
|
|
import { DownloadBtnContainer, PreviewContainer } from './Containers'
|
2022-02-02 14:08:14 +00:00
|
|
|
import { getExtension } from '../../utils/getFileIcon'
|
2021-06-25 14:15:00 +00:00
|
|
|
|
2022-01-16 12:19:52 +00:00
|
|
|
const VideoPreview: React.FC<{ file: OdFileObject }> = ({ file }) => {
|
2021-08-15 20:26:08 +00:00
|
|
|
const { asPath } = useRouter()
|
2021-08-23 14:02:06 +00:00
|
|
|
const clipboard = useClipboard()
|
2021-08-15 20:26:08 +00:00
|
|
|
|
2022-02-02 13:36:12 +00:00
|
|
|
// OneDrive generates thumbnails for its video files, we pick the thumbnail with the highest resolution
|
|
|
|
const thumbnail = file.thumbnails && file.thumbnails.length > 0 ? file.thumbnails[0].large.url : ''
|
|
|
|
|
2022-02-02 14:08:14 +00:00
|
|
|
// We assume subtitle files are beside the video with the same name, only webvtt '.vtt' files are supported
|
|
|
|
const subtitle = `/api?path=${asPath.replace(getExtension(file.name), 'vtt')}&raw=true`
|
|
|
|
|
2021-06-24 13:54:59 +00:00
|
|
|
return (
|
2021-06-25 14:15:00 +00:00
|
|
|
<>
|
2022-01-06 08:34:16 +00:00
|
|
|
<PreviewContainer>
|
2022-02-02 13:36:12 +00:00
|
|
|
<DPlayer
|
2021-12-18 01:43:24 +00:00
|
|
|
className="aspect-video"
|
2022-02-02 13:36:12 +00:00
|
|
|
options={{
|
|
|
|
volume: 1.0,
|
|
|
|
lang: 'en',
|
2022-02-04 08:05:28 +00:00
|
|
|
video: {
|
|
|
|
url: file['@microsoft.graph.downloadUrl'],
|
|
|
|
pic: thumbnail,
|
|
|
|
},
|
2022-02-02 14:08:14 +00:00
|
|
|
subtitle: { url: subtitle },
|
2022-02-02 13:36:12 +00:00
|
|
|
}}
|
2021-12-18 01:43:24 +00:00
|
|
|
/>
|
2022-01-06 08:34:16 +00:00
|
|
|
</PreviewContainer>
|
2021-08-15 20:26:08 +00:00
|
|
|
|
2022-01-06 08:34:16 +00:00
|
|
|
<DownloadBtnContainer>
|
|
|
|
<div className="flex flex-wrap justify-center gap-2">
|
|
|
|
<DownloadButton
|
|
|
|
onClickCallback={() => window.open(file['@microsoft.graph.downloadUrl'])}
|
|
|
|
btnColor="blue"
|
|
|
|
btnText="Download"
|
|
|
|
btnIcon="file-download"
|
|
|
|
/>
|
2022-01-15 13:37:06 +00:00
|
|
|
{/* <DownloadButton
|
2022-01-06 08:34:16 +00:00
|
|
|
onClickCallback={() =>
|
|
|
|
window.open(`/api/proxy?url=${encodeURIComponent(file['@microsoft.graph.downloadUrl'])}`)
|
|
|
|
}
|
|
|
|
btnColor="teal"
|
|
|
|
btnText="Proxy download"
|
|
|
|
btnIcon="download"
|
2022-01-15 13:37:06 +00:00
|
|
|
/> */}
|
2022-01-06 08:34:16 +00:00
|
|
|
<DownloadButton
|
|
|
|
onClickCallback={() => {
|
|
|
|
clipboard.copy(`${getBaseUrl()}/api?path=${asPath}&raw=true`)
|
|
|
|
toast.success('Copied direct link to clipboard.')
|
|
|
|
}}
|
|
|
|
btnColor="pink"
|
|
|
|
btnText="Copy direct link"
|
|
|
|
btnIcon="copy"
|
|
|
|
/>
|
2021-08-15 20:26:08 +00:00
|
|
|
|
2022-01-06 08:34:16 +00:00
|
|
|
<DownloadButton
|
|
|
|
onClickCallback={() => window.open(`iina://weblink?url=${file['@microsoft.graph.downloadUrl']}`)}
|
|
|
|
btnText="IINA"
|
|
|
|
btnImage="/players/iina.png"
|
|
|
|
/>
|
|
|
|
<DownloadButton
|
|
|
|
onClickCallback={() => window.open(`vlc://${file['@microsoft.graph.downloadUrl']}`)}
|
|
|
|
btnText="VLC"
|
|
|
|
btnImage="/players/vlc.png"
|
|
|
|
/>
|
|
|
|
<DownloadButton
|
|
|
|
onClickCallback={() => window.open(`potplayer://${file['@microsoft.graph.downloadUrl']}`)}
|
|
|
|
btnText="PotPlayer"
|
|
|
|
btnImage="/players/potplayer.png"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</DownloadBtnContainer>
|
2021-06-25 14:15:00 +00:00
|
|
|
</>
|
2021-06-24 13:54:59 +00:00
|
|
|
)
|
|
|
|
}
|
2021-12-17 15:16:18 +00:00
|
|
|
|
|
|
|
export default VideoPreview
|