encode url for office previews

This commit is contained in:
spencerwooo 2022-02-15 19:13:37 +08:00 committed by Spencer Woo
parent 049be5d841
commit e24a602d46

View file

@ -16,6 +16,10 @@ const OfficePreview: FC<{ file: OdFileObject }> = ({ file }) => {
const docContainer = useRef<HTMLDivElement>(null) const docContainer = useRef<HTMLDivElement>(null)
const [docContainerWidth, setDocContainerWidth] = useState(600) const [docContainerWidth, setDocContainerWidth] = useState(600)
const docUrl = encodeURIComponent(
`${getBaseUrl()}/api/raw/?path=${asPath}${hashedToken ? `&odpt=${hashedToken}` : ''}`
)
useEffect(() => { useEffect(() => {
setDocContainerWidth(docContainer.current ? docContainer.current.offsetWidth : 600) setDocContainerWidth(docContainer.current ? docContainer.current.offsetWidth : 600)
}, []) }, [])
@ -23,11 +27,7 @@ const OfficePreview: FC<{ file: OdFileObject }> = ({ file }) => {
return ( return (
<div> <div>
<div className="overflow-scroll" ref={docContainer} style={{ maxHeight: '90vh' }}> <div className="overflow-scroll" ref={docContainer} style={{ maxHeight: '90vh' }}>
<Preview <Preview url={docUrl} width={docContainerWidth.toString()} height="600" />
url={`${getBaseUrl()}/api/raw/?path=${asPath}${hashedToken ? `&odpt=${hashedToken}` : ''}`}
width={docContainerWidth.toString()}
height="600"
/>
</div> </div>
<DownloadBtnContainer> <DownloadBtnContainer>
<DownloadButtonGroup /> <DownloadButtonGroup />