### What problem does this PR solve?  the preview botton of image not work for me. request url: `http://127.0.0.1:9222/document/af570920f80e11efb8e967fd67f0d8c7?ext=jpg&prefix=file` response: `{"code":401,"data":null,"message":"<Unauthorized '401: Unauthorized'>"}` ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { Images } from '@/constants/common';
|
|
import { api_host } from '@/utils/api';
|
|
import { Flex } from 'antd';
|
|
import { useParams, useSearchParams } from 'umi';
|
|
import Docx from './docx';
|
|
import Excel from './excel';
|
|
import Image from './image';
|
|
import Pdf from './pdf';
|
|
|
|
import { previewHtmlFile } from '@/utils/file-util';
|
|
import styles from './index.less';
|
|
|
|
// TODO: The interface returns an incorrect content-type for the SVG.
|
|
|
|
const DocumentViewer = () => {
|
|
const { id: documentId } = useParams();
|
|
const [currentQueryParameters] = useSearchParams();
|
|
const ext = currentQueryParameters.get('ext');
|
|
const prefix = currentQueryParameters.get('prefix');
|
|
const api = `${api_host}/${prefix || 'file'}/get/${documentId}`;
|
|
|
|
if (ext === 'html' && documentId) {
|
|
previewHtmlFile(documentId);
|
|
return;
|
|
}
|
|
|
|
return (
|
|
<section className={styles.viewerWrapper}>
|
|
{Images.includes(ext!) && (
|
|
<Flex className={styles.image} align="center" justify="center">
|
|
<Image src={api} preview={false}></Image>
|
|
</Flex>
|
|
)}
|
|
{ext === 'pdf' && <Pdf url={api}></Pdf>}
|
|
{(ext === 'xlsx' || ext === 'xls') && <Excel filePath={api}></Excel>}
|
|
|
|
{ext === 'docx' && <Docx filePath={api}></Docx>}
|
|
</section>
|
|
);
|
|
};
|
|
|
|
export default DocumentViewer;
|