mirror of
https://github.com/Nezumi-2711/onedrive-vercel-index.git
synced 2026-09-22 20:01:46 +00:00
Standalone raw file redirects (#428)
This commit is contained in:
@@ -10,6 +10,7 @@ import { useAsync } from 'react-async-hook'
|
||||
import { getBaseUrl } from '../../utils/getBaseUrl'
|
||||
import { getExtension } from '../../utils/getFileIcon'
|
||||
import { getReadablePath } from '../../utils/getReadablePath'
|
||||
import { getStoredToken } from '../../utils/protectedRouteHandler'
|
||||
import { DownloadButton } from '../DownloadBtnGtoup'
|
||||
import { DownloadBtnContainer, PreviewContainer } from './Containers'
|
||||
import FourOhFour from '../FourOhFour'
|
||||
@@ -18,16 +19,21 @@ import CustomEmbedLinkMenu from '../CustomEmbedLinkMenu'
|
||||
|
||||
const VideoPreview: React.FC<{ file: OdFileObject }> = ({ file }) => {
|
||||
const { asPath } = useRouter()
|
||||
const hashedToken = getStoredToken(asPath)
|
||||
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`
|
||||
const thumbnail = `/api/thumbnail/?path=${asPath}&size=large${hashedToken ? `&odpt=${hashedToken}` : ''}`
|
||||
|
||||
// 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 vtt = `${asPath.substring(0, asPath.lastIndexOf('.'))}.vtt`
|
||||
const subtitle = `/api/raw/?path=${vtt}${hashedToken ? `&odpt=${hashedToken}` : ''}`
|
||||
|
||||
// We also format the raw video file for the in-browser player as well as all other players
|
||||
const videoUrl = `/api/raw/?path=${asPath}${hashedToken ? `&odpt=${hashedToken}` : ''}`
|
||||
|
||||
const isFlv = getExtension(file.name) === 'flv'
|
||||
const {
|
||||
@@ -42,7 +48,7 @@ const VideoPreview: React.FC<{ file: OdFileObject }> = ({ file }) => {
|
||||
|
||||
return (
|
||||
<>
|
||||
<CustomEmbedLinkMenu path={getReadablePath(asPath)} menuOpen={menuOpen} setMenuOpen={setMenuOpen} />
|
||||
<CustomEmbedLinkMenu path={asPath} menuOpen={menuOpen} setMenuOpen={setMenuOpen} />
|
||||
<PreviewContainer>
|
||||
{error ? (
|
||||
<FourOhFour errorMsg={error.message} />
|
||||
@@ -55,7 +61,7 @@ const VideoPreview: React.FC<{ file: OdFileObject }> = ({ file }) => {
|
||||
volume: 1.0,
|
||||
lang: 'en',
|
||||
video: {
|
||||
url: file['@microsoft.graph.downloadUrl'],
|
||||
url: videoUrl,
|
||||
pic: thumbnail,
|
||||
type: isFlv ? 'customFlv' : 'auto',
|
||||
customType: {
|
||||
@@ -78,14 +84,14 @@ const VideoPreview: React.FC<{ file: OdFileObject }> = ({ file }) => {
|
||||
<DownloadBtnContainer>
|
||||
<div className="flex flex-wrap justify-center gap-2">
|
||||
<DownloadButton
|
||||
onClickCallback={() => window.open(file['@microsoft.graph.downloadUrl'])}
|
||||
onClickCallback={() => window.open(videoUrl)}
|
||||
btnColor="blue"
|
||||
btnText={t('Download')}
|
||||
btnIcon="file-download"
|
||||
/>
|
||||
{/* <DownloadButton
|
||||
onClickCallback={() =>
|
||||
window.open(`/api/proxy?url=${encodeURIComponent(file['@microsoft.graph.downloadUrl'])}`)
|
||||
window.open(`/api/proxy?url=${encodeURIComponent(...)}`)
|
||||
}
|
||||
btnColor="teal"
|
||||
btnText={t('Proxy download')}
|
||||
@@ -93,7 +99,9 @@ const VideoPreview: React.FC<{ file: OdFileObject }> = ({ file }) => {
|
||||
/> */}
|
||||
<DownloadButton
|
||||
onClickCallback={() => {
|
||||
clipboard.copy(`${getBaseUrl()}/api?path=${getReadablePath(asPath)}&raw=true`)
|
||||
clipboard.copy(
|
||||
`${getBaseUrl()}/api/raw/?path=${getReadablePath(asPath)}${hashedToken ? `&odpt=${hashedToken}` : ''}`
|
||||
)
|
||||
toast.success(t('Copied direct link to clipboard.'))
|
||||
}}
|
||||
btnColor="pink"
|
||||
@@ -108,17 +116,17 @@ const VideoPreview: React.FC<{ file: OdFileObject }> = ({ file }) => {
|
||||
/>
|
||||
|
||||
<DownloadButton
|
||||
onClickCallback={() => window.open(`iina://weblink?url=${file['@microsoft.graph.downloadUrl']}`)}
|
||||
onClickCallback={() => window.open(`iina://weblink?url=${getBaseUrl()}${videoUrl}`)}
|
||||
btnText="IINA"
|
||||
btnImage="/players/iina.png"
|
||||
/>
|
||||
<DownloadButton
|
||||
onClickCallback={() => window.open(`vlc://${file['@microsoft.graph.downloadUrl']}`)}
|
||||
onClickCallback={() => window.open(`vlc://${getBaseUrl()}${videoUrl}`)}
|
||||
btnText="VLC"
|
||||
btnImage="/players/vlc.png"
|
||||
/>
|
||||
<DownloadButton
|
||||
onClickCallback={() => window.open(`potplayer://${file['@microsoft.graph.downloadUrl']}`)}
|
||||
onClickCallback={() => window.open(`potplayer://${getBaseUrl()}/${videoUrl}`)}
|
||||
btnText="PotPlayer"
|
||||
btnImage="/players/potplayer.png"
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user