Standalone raw file redirects (#428)

This commit is contained in:
Spencer Woo
2022-02-14 19:33:19 +08:00
committed by GitHub
parent 0fda1c93db
commit 9493ce9f3d
30 changed files with 365 additions and 185 deletions
+6 -4
View File
@@ -1,9 +1,10 @@
import { useRouter } from 'next/router'
import { useTranslation } from 'next-i18next'
import FourOhFour from '../FourOhFour'
import Loading from '../Loading'
import { DownloadButton } from '../DownloadBtnGtoup'
import useAxiosGet from '../../utils/fetchOnMount'
import useFileContent from '../../utils/fetchOnMount'
import { DownloadBtnContainer, PreviewContainer } from './Containers'
const parseDotUrl = (content: string): string | undefined => {
@@ -14,9 +15,10 @@ const parseDotUrl = (content: string): string | undefined => {
}
const TextPreview = ({ file }) => {
const { asPath } = useRouter()
const { t } = useTranslation()
const { response: content, error, validating } = useAxiosGet(file['@microsoft.graph.downloadUrl'])
const { response: content, error, validating } = useFileContent(`/api/raw/?path=${asPath}`, asPath)
if (error) {
return (
<PreviewContainer>
@@ -49,11 +51,11 @@ const TextPreview = ({ file }) => {
<DownloadBtnContainer>
<div className="flex justify-center">
<DownloadButton
onClickCallback={() => window.open(parseDotUrl(content) || '')}
onClickCallback={() => window.open(parseDotUrl(content) ?? '')}
btnColor="blue"
btnText={t('Open URL')}
btnIcon="external-link-alt"
btnTitle={t('Open URL{{url}}', { url: ' ' + parseDotUrl(content) || '' })}
btnTitle={t('Open URL{{url}}', { url: ' ' + parseDotUrl(content) ?? '' })}
/>
</div>
</DownloadBtnContainer>