mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? fix: reference file with 'docx' type can not open #844 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
import { ReactComponent as AssistantIcon } from '@/assets/svg/assistant.svg';
|
||||
import { MessageType } from '@/constants/chat';
|
||||
import { useTranslate } from '@/hooks/common-hooks';
|
||||
import { useGetDocumentUrl } from '@/hooks/document-hooks';
|
||||
import { useSelectFileThumbnails } from '@/hooks/knowledge-hooks';
|
||||
import { IReference, Message } from '@/interfaces/database/chat';
|
||||
import { IChunk } from '@/interfaces/database/knowledge';
|
||||
@ -9,7 +8,7 @@ import classNames from 'classnames';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import MarkdownContent from '@/pages/chat/markdown-content';
|
||||
import { getExtension, isPdf } from '@/utils/documentUtils';
|
||||
import { getExtension } from '@/utils/documentUtils';
|
||||
import { Avatar, Flex, List } from 'antd';
|
||||
import NewDocumentLink from '../new-document-link';
|
||||
import SvgIcon from '../svg-icon';
|
||||
@ -35,7 +34,6 @@ const MessageItem = ({
|
||||
const isAssistant = item.role === MessageType.Assistant;
|
||||
const { t } = useTranslate('chat');
|
||||
const fileThumbnails = useSelectFileThumbnails();
|
||||
const getDocumentUrl = useGetDocumentUrl();
|
||||
|
||||
const referenceDocumentList = useMemo(() => {
|
||||
return reference?.doc_aggs ?? [];
|
||||
@ -114,8 +112,9 @@ const MessageItem = ({
|
||||
)}
|
||||
|
||||
<NewDocumentLink
|
||||
link={getDocumentUrl(item.doc_id)}
|
||||
preventDefault={!isPdf(item.doc_name)}
|
||||
documentId={item.doc_id}
|
||||
documentName={item.doc_name}
|
||||
prefix="document"
|
||||
>
|
||||
{item.doc_name}
|
||||
</NewDocumentLink>
|
||||
|
||||
@ -1,9 +1,16 @@
|
||||
import {
|
||||
getExtension,
|
||||
isSupportedPreviewDocumentType,
|
||||
} from '@/utils/documentUtils';
|
||||
import React from 'react';
|
||||
|
||||
interface IProps extends React.PropsWithChildren {
|
||||
link: string;
|
||||
link?: string;
|
||||
preventDefault?: boolean;
|
||||
color?: string;
|
||||
documentName: string;
|
||||
documentId?: string;
|
||||
prefix?: string;
|
||||
}
|
||||
|
||||
const NewDocumentLink = ({
|
||||
@ -11,12 +18,25 @@ const NewDocumentLink = ({
|
||||
link,
|
||||
preventDefault = false,
|
||||
color = 'rgb(15, 79, 170)',
|
||||
documentId,
|
||||
documentName,
|
||||
prefix = 'file',
|
||||
}: IProps) => {
|
||||
let nextLink = link;
|
||||
const extension = getExtension(documentName);
|
||||
if (!link) {
|
||||
nextLink = `/document/${documentId}?ext=${extension}&prefix=${prefix}`;
|
||||
}
|
||||
|
||||
return (
|
||||
<a
|
||||
target="_blank"
|
||||
onClick={!preventDefault ? undefined : (e) => e.preventDefault()}
|
||||
href={link}
|
||||
onClick={
|
||||
!preventDefault || isSupportedPreviewDocumentType(extension)
|
||||
? undefined
|
||||
: (e) => e.preventDefault()
|
||||
}
|
||||
href={nextLink}
|
||||
rel="noreferrer"
|
||||
style={{ color, wordBreak: 'break-all' }}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user