onedrive/components/previews/PDFPreview.tsx
2022-02-14 19:33:19 +08:00

29 lines
1 KiB
TypeScript

import { useRouter } from 'next/router'
import { getBaseUrl } from '../../utils/getBaseUrl'
import { getStoredToken } from '../../utils/protectedRouteHandler'
import DownloadButtonGroup from '../DownloadBtnGtoup'
import { DownloadBtnContainer } from './Containers'
const PDFEmbedPreview: React.FC<{ file: any }> = ({ file }) => {
const { asPath } = useRouter()
const hashedToken = getStoredToken(asPath)
// const url = `/api/proxy?url=${encodeURIComponent(...)}&inline=true`
const pdfPath = encodeURIComponent(
`${getBaseUrl()}/api/raw/?path=${asPath}${hashedToken ? `&odpt=${hashedToken}` : ''}`
)
const url = `https://mozilla.github.io/pdf.js/web/viewer.html?file=${pdfPath}`
return (
<div>
<div className="w-full overflow-hidden rounded" style={{ height: '90vh' }}>
<iframe src={url} frameBorder="0" width="100%" height="100%"></iframe>
</div>
<DownloadBtnContainer>
<DownloadButtonGroup />
</DownloadBtnContainer>
</div>
)
}
export default PDFEmbedPreview