2022-02-05 12:36:38 +00:00
|
|
|
import type { OdFileObject } from '../../types'
|
|
|
|
|
|
|
|
import { FC } from 'react'
|
2022-02-14 11:33:19 +00:00
|
|
|
import { useRouter } from 'next/router'
|
2022-02-05 12:36:38 +00:00
|
|
|
|
|
|
|
import { PreviewContainer, DownloadBtnContainer } from './Containers'
|
|
|
|
import DownloadButtonGroup from '../DownloadBtnGtoup'
|
2022-02-14 11:33:19 +00:00
|
|
|
import { getStoredToken } from '../../utils/protectedRouteHandler'
|
2022-02-05 12:36:38 +00:00
|
|
|
|
|
|
|
const ImagePreview: FC<{ file: OdFileObject }> = ({ file }) => {
|
2022-02-14 11:33:19 +00:00
|
|
|
const { asPath } = useRouter()
|
|
|
|
const hashedToken = getStoredToken(asPath)
|
|
|
|
|
2022-02-05 12:36:38 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<PreviewContainer>
|
|
|
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
|
|
|
<img
|
|
|
|
className="mx-auto"
|
2022-02-14 11:33:19 +00:00
|
|
|
src={`/api/raw/?path=${asPath}${hashedToken ? `&odpt=${hashedToken}` : ''}`}
|
2022-02-05 12:36:38 +00:00
|
|
|
alt={file.name}
|
|
|
|
width={file.image?.width}
|
|
|
|
height={file.image?.height}
|
|
|
|
/>
|
|
|
|
</PreviewContainer>
|
|
|
|
<DownloadBtnContainer>
|
2022-02-14 11:33:19 +00:00
|
|
|
<DownloadButtonGroup />
|
2022-02-05 12:36:38 +00:00
|
|
|
</DownloadBtnContainer>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ImagePreview
|