mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-06-01 17:32:07 +08:00

### What problem does this PR solve? fix: display specific error message when previewing file error #868 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { Skeleton } from 'antd';
|
|
import { PdfHighlighter, PdfLoader } from 'react-pdf-highlighter';
|
|
import FileError from '../file-error';
|
|
import { useCatchError } from '../hooks';
|
|
|
|
interface IProps {
|
|
url: string;
|
|
}
|
|
|
|
const PdfPreviewer = ({ url }: IProps) => {
|
|
const { error } = useCatchError(url);
|
|
const resetHash = () => {};
|
|
|
|
return (
|
|
<div style={{ width: '100%', height: '100%' }}>
|
|
<PdfLoader
|
|
url={url}
|
|
beforeLoad={<Skeleton active />}
|
|
workerSrc="/pdfjs-dist/pdf.worker.min.js"
|
|
errorMessage={<FileError>{error}</FileError>}
|
|
onError={(e) => {
|
|
console.warn(e);
|
|
}}
|
|
>
|
|
{(pdfDocument) => {
|
|
return (
|
|
<PdfHighlighter
|
|
pdfDocument={pdfDocument}
|
|
enableAreaSelection={(event) => event.altKey}
|
|
onScrollChange={resetHash}
|
|
scrollRef={() => {}}
|
|
onSelectionFinished={() => null}
|
|
highlightTransform={() => {
|
|
return <div></div>;
|
|
}}
|
|
highlights={[]}
|
|
/>
|
|
);
|
|
}}
|
|
</PdfLoader>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default PdfPreviewer;
|