onedrive/components/previews/PDFPreview.tsx

30 lines
1 KiB
TypeScript
Raw Normal View History

2022-02-14 11:33:19 +00:00
import { useRouter } from 'next/router'
import { getBaseUrl } from '../../utils/getBaseUrl'
import { getStoredToken } from '../../utils/protectedRouteHandler'
import DownloadButtonGroup from '../DownloadBtnGtoup'
import { DownloadBtnContainer } from './Containers'
2021-12-28 18:13:17 +00:00
2022-01-06 11:25:10 +00:00
const PDFEmbedPreview: React.FC<{ file: any }> = ({ file }) => {
2022-02-14 11:33:19 +00:00
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}`
2021-12-28 18:13:17 +00:00
return (
<div>
<div className="w-full overflow-hidden rounded" style={{ height: '90vh' }}>
2021-12-28 18:13:17 +00:00
<iframe src={url} frameBorder="0" width="100%" height="100%"></iframe>
</div>
<DownloadBtnContainer>
2022-02-14 11:33:19 +00:00
<DownloadButtonGroup />
</DownloadBtnContainer>
</div>
2021-12-28 18:13:17 +00:00
)
}
export default PDFEmbedPreview