mirror of
https://github.com/Nezumi-2711/onedrive-vercel-index.git
synced 2026-09-22 13:38:45 +00:00
add dot url file preview support, close #221
This commit is contained in:
@@ -32,6 +32,7 @@ import AudioPreview from './previews/AudioPreview'
|
|||||||
import VideoPreview from './previews/VideoPreview'
|
import VideoPreview from './previews/VideoPreview'
|
||||||
import DownloadButtonGroup from './DownloadBtnGtoup'
|
import DownloadButtonGroup from './DownloadBtnGtoup'
|
||||||
import PDFPreview from './previews/PDFPreview'
|
import PDFPreview from './previews/PDFPreview'
|
||||||
|
import URLPreview from './previews/URLPreview'
|
||||||
import { DownloadBtnContainer, PreviewContainer } from './previews/Containers'
|
import { DownloadBtnContainer, PreviewContainer } from './previews/Containers'
|
||||||
|
|
||||||
// Disabling SSR for some previews (image gallery view, and PDF view)
|
// Disabling SSR for some previews (image gallery view, and PDF view)
|
||||||
@@ -595,6 +596,9 @@ const FileListing: FC<{ query?: ParsedUrlQuery }> = ({ query }) => {
|
|||||||
case preview.epub:
|
case preview.epub:
|
||||||
return <EPUBPreview file={file} />
|
return <EPUBPreview file={file} />
|
||||||
|
|
||||||
|
case preview.url:
|
||||||
|
return <URLPreview file={file} />
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return <PreviewContainer>{fileName}</PreviewContainer>
|
return <PreviewContainer>{fileName}</PreviewContainer>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import FourOhFour from '../FourOhFour'
|
||||||
|
import Loading from '../Loading'
|
||||||
|
import { DownloadButton } from '../DownloadBtnGtoup'
|
||||||
|
import useFileContent from '../../utils/fetchOnMount'
|
||||||
|
import { DownloadBtnContainer, PreviewContainer } from './Containers'
|
||||||
|
|
||||||
|
const parseDotUrl = (content: string): string | undefined => {
|
||||||
|
return content
|
||||||
|
.split('\n')
|
||||||
|
.find(line => line.startsWith('URL='))
|
||||||
|
?.split('=')[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
const TextPreview = ({ file }) => {
|
||||||
|
const { content, error, validating } = useFileContent(file['@microsoft.graph.downloadUrl'])
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<PreviewContainer>
|
||||||
|
<FourOhFour errorMsg={error} />
|
||||||
|
</PreviewContainer>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (validating) {
|
||||||
|
return (
|
||||||
|
<PreviewContainer>
|
||||||
|
<Loading loadingText="Loading file content..." />
|
||||||
|
</PreviewContainer>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!content) {
|
||||||
|
return (
|
||||||
|
<PreviewContainer>
|
||||||
|
<FourOhFour errorMsg="File is empty." />
|
||||||
|
</PreviewContainer>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<PreviewContainer>
|
||||||
|
<pre className="md:p-3 p-0 overflow-x-scroll text-sm">{content}</pre>
|
||||||
|
</PreviewContainer>
|
||||||
|
<DownloadBtnContainer>
|
||||||
|
<div className="flex justify-center">
|
||||||
|
<DownloadButton
|
||||||
|
onClickCallback={() => window.open(parseDotUrl(content) || '')}
|
||||||
|
btnColor="blue"
|
||||||
|
btnText="Open URL"
|
||||||
|
btnIcon="external-link-alt"
|
||||||
|
btnTitle={`Open URL ${parseDotUrl(content) || ''}`}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</DownloadBtnContainer>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TextPreview
|
||||||
@@ -8,6 +8,7 @@ const preview = {
|
|||||||
audio: 'audio',
|
audio: 'audio',
|
||||||
office: 'ms-office',
|
office: 'ms-office',
|
||||||
epub: 'epub',
|
epub: 'epub',
|
||||||
|
url: 'url',
|
||||||
}
|
}
|
||||||
|
|
||||||
const extensions = {
|
const extensions = {
|
||||||
@@ -64,6 +65,8 @@ const extensions = {
|
|||||||
flac: preview.audio,
|
flac: preview.audio,
|
||||||
|
|
||||||
epub: preview.epub,
|
epub: preview.epub,
|
||||||
|
|
||||||
|
url: preview.url,
|
||||||
}
|
}
|
||||||
|
|
||||||
export { extensions, preview }
|
export { extensions, preview }
|
||||||
|
|||||||
Reference in New Issue
Block a user