mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-26 00:46:52 +08:00
Web: Fixed the download and preview file not authorized. (#3652)
https://github.com/infiniflow/ragflow/issues/3651 ### What problem does this PR solve? _Briefly describe what this PR aims to solve. Include background context that will help reviewers understand the purpose of the PR._ ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -1,7 +1,14 @@
|
||||
import { Authorization } from '@/constants/authorization';
|
||||
import { getAuthorization } from '@/utils/authorization-util';
|
||||
import { Skeleton } from 'antd';
|
||||
import { PdfHighlighter, PdfLoader } from 'react-pdf-highlighter';
|
||||
import FileError from '../file-error';
|
||||
import { useCatchError } from '../hooks';
|
||||
type PdfLoaderProps = React.ComponentProps<typeof PdfLoader> & {
|
||||
httpHeaders?: Record<string, string>;
|
||||
};
|
||||
|
||||
const Loader = PdfLoader as React.ComponentType<PdfLoaderProps>;
|
||||
|
||||
interface IProps {
|
||||
url: string;
|
||||
@ -10,11 +17,14 @@ interface IProps {
|
||||
const PdfPreviewer = ({ url }: IProps) => {
|
||||
const { error } = useCatchError(url);
|
||||
const resetHash = () => {};
|
||||
|
||||
const httpHeaders = {
|
||||
[Authorization]: getAuthorization(),
|
||||
};
|
||||
return (
|
||||
<div style={{ width: '100%', height: '100%' }}>
|
||||
<PdfLoader
|
||||
<Loader
|
||||
url={url}
|
||||
httpHeaders={httpHeaders}
|
||||
beforeLoad={<Skeleton active />}
|
||||
workerSrc="/pdfjs-dist/pdf.worker.min.js"
|
||||
errorMessage={<FileError>{error}</FileError>}
|
||||
@ -37,7 +47,7 @@ const PdfPreviewer = ({ url }: IProps) => {
|
||||
/>
|
||||
);
|
||||
}}
|
||||
</PdfLoader>
|
||||
</Loader>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user