balibabu
commited on
Commit
·
d3e0754
1
Parent(s):
7c30742
fix: reference file with 'docx' type can not open #844 (#1635)
Browse files### 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)
- web/src/components/message-item/index.tsx +4 -5
- web/src/components/new-document-link.tsx +23 -3
- web/src/pages/add-knowledge/components/knowledge-testing/testing-result/select-files.tsx +12 -8
- web/src/pages/document-viewer/index.tsx +2 -1
- web/src/pages/file-manager/action-cell/index.tsx +6 -7
- web/src/utils/documentUtils.ts +5 -0
web/src/components/message-item/index.tsx
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import { ReactComponent as AssistantIcon } from '@/assets/svg/assistant.svg';
|
| 2 |
import { MessageType } from '@/constants/chat';
|
| 3 |
import { useTranslate } from '@/hooks/common-hooks';
|
| 4 |
-
import { useGetDocumentUrl } from '@/hooks/document-hooks';
|
| 5 |
import { useSelectFileThumbnails } from '@/hooks/knowledge-hooks';
|
| 6 |
import { IReference, Message } from '@/interfaces/database/chat';
|
| 7 |
import { IChunk } from '@/interfaces/database/knowledge';
|
|
@@ -9,7 +8,7 @@ import classNames from 'classnames';
|
|
| 9 |
import { useMemo } from 'react';
|
| 10 |
|
| 11 |
import MarkdownContent from '@/pages/chat/markdown-content';
|
| 12 |
-
import { getExtension
|
| 13 |
import { Avatar, Flex, List } from 'antd';
|
| 14 |
import NewDocumentLink from '../new-document-link';
|
| 15 |
import SvgIcon from '../svg-icon';
|
|
@@ -35,7 +34,6 @@ const MessageItem = ({
|
|
| 35 |
const isAssistant = item.role === MessageType.Assistant;
|
| 36 |
const { t } = useTranslate('chat');
|
| 37 |
const fileThumbnails = useSelectFileThumbnails();
|
| 38 |
-
const getDocumentUrl = useGetDocumentUrl();
|
| 39 |
|
| 40 |
const referenceDocumentList = useMemo(() => {
|
| 41 |
return reference?.doc_aggs ?? [];
|
|
@@ -114,8 +112,9 @@ const MessageItem = ({
|
|
| 114 |
)}
|
| 115 |
|
| 116 |
<NewDocumentLink
|
| 117 |
-
|
| 118 |
-
|
|
|
|
| 119 |
>
|
| 120 |
{item.doc_name}
|
| 121 |
</NewDocumentLink>
|
|
|
|
| 1 |
import { ReactComponent as AssistantIcon } from '@/assets/svg/assistant.svg';
|
| 2 |
import { MessageType } from '@/constants/chat';
|
| 3 |
import { useTranslate } from '@/hooks/common-hooks';
|
|
|
|
| 4 |
import { useSelectFileThumbnails } from '@/hooks/knowledge-hooks';
|
| 5 |
import { IReference, Message } from '@/interfaces/database/chat';
|
| 6 |
import { IChunk } from '@/interfaces/database/knowledge';
|
|
|
|
| 8 |
import { useMemo } from 'react';
|
| 9 |
|
| 10 |
import MarkdownContent from '@/pages/chat/markdown-content';
|
| 11 |
+
import { getExtension } from '@/utils/documentUtils';
|
| 12 |
import { Avatar, Flex, List } from 'antd';
|
| 13 |
import NewDocumentLink from '../new-document-link';
|
| 14 |
import SvgIcon from '../svg-icon';
|
|
|
|
| 34 |
const isAssistant = item.role === MessageType.Assistant;
|
| 35 |
const { t } = useTranslate('chat');
|
| 36 |
const fileThumbnails = useSelectFileThumbnails();
|
|
|
|
| 37 |
|
| 38 |
const referenceDocumentList = useMemo(() => {
|
| 39 |
return reference?.doc_aggs ?? [];
|
|
|
|
| 112 |
)}
|
| 113 |
|
| 114 |
<NewDocumentLink
|
| 115 |
+
documentId={item.doc_id}
|
| 116 |
+
documentName={item.doc_name}
|
| 117 |
+
prefix="document"
|
| 118 |
>
|
| 119 |
{item.doc_name}
|
| 120 |
</NewDocumentLink>
|
web/src/components/new-document-link.tsx
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import React from 'react';
|
| 2 |
|
| 3 |
interface IProps extends React.PropsWithChildren {
|
| 4 |
-
link
|
| 5 |
preventDefault?: boolean;
|
| 6 |
color?: string;
|
|
|
|
|
|
|
|
|
|
| 7 |
}
|
| 8 |
|
| 9 |
const NewDocumentLink = ({
|
|
@@ -11,12 +18,25 @@ const NewDocumentLink = ({
|
|
| 11 |
link,
|
| 12 |
preventDefault = false,
|
| 13 |
color = 'rgb(15, 79, 170)',
|
|
|
|
|
|
|
|
|
|
| 14 |
}: IProps) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
return (
|
| 16 |
<a
|
| 17 |
target="_blank"
|
| 18 |
-
onClick={
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
rel="noreferrer"
|
| 21 |
style={{ color, wordBreak: 'break-all' }}
|
| 22 |
>
|
|
|
|
| 1 |
+
import {
|
| 2 |
+
getExtension,
|
| 3 |
+
isSupportedPreviewDocumentType,
|
| 4 |
+
} from '@/utils/documentUtils';
|
| 5 |
import React from 'react';
|
| 6 |
|
| 7 |
interface IProps extends React.PropsWithChildren {
|
| 8 |
+
link?: string;
|
| 9 |
preventDefault?: boolean;
|
| 10 |
color?: string;
|
| 11 |
+
documentName: string;
|
| 12 |
+
documentId?: string;
|
| 13 |
+
prefix?: string;
|
| 14 |
}
|
| 15 |
|
| 16 |
const NewDocumentLink = ({
|
|
|
|
| 18 |
link,
|
| 19 |
preventDefault = false,
|
| 20 |
color = 'rgb(15, 79, 170)',
|
| 21 |
+
documentId,
|
| 22 |
+
documentName,
|
| 23 |
+
prefix = 'file',
|
| 24 |
}: IProps) => {
|
| 25 |
+
let nextLink = link;
|
| 26 |
+
const extension = getExtension(documentName);
|
| 27 |
+
if (!link) {
|
| 28 |
+
nextLink = `/document/${documentId}?ext=${extension}&prefix=${prefix}`;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
return (
|
| 32 |
<a
|
| 33 |
target="_blank"
|
| 34 |
+
onClick={
|
| 35 |
+
!preventDefault || isSupportedPreviewDocumentType(extension)
|
| 36 |
+
? undefined
|
| 37 |
+
: (e) => e.preventDefault()
|
| 38 |
+
}
|
| 39 |
+
href={nextLink}
|
| 40 |
rel="noreferrer"
|
| 41 |
style={{ color, wordBreak: 'break-all' }}
|
| 42 |
>
|
web/src/pages/add-knowledge/components/knowledge-testing/testing-result/select-files.tsx
CHANGED
|
@@ -1,9 +1,8 @@
|
|
| 1 |
-
import { ReactComponent as NavigationPointerIcon } from '@/assets/svg/navigation-pointer.svg';
|
| 2 |
import NewDocumentLink from '@/components/new-document-link';
|
| 3 |
-
import {
|
| 4 |
import { ITestingDocument } from '@/interfaces/database/knowledge';
|
| 5 |
-
import {
|
| 6 |
-
import { Table, TableProps } from 'antd';
|
| 7 |
import { useDispatch, useSelector } from 'umi';
|
| 8 |
|
| 9 |
interface IProps {
|
|
@@ -14,9 +13,9 @@ const SelectFiles = ({ handleTesting }: IProps) => {
|
|
| 14 |
const documents: ITestingDocument[] = useSelector(
|
| 15 |
(state: any) => state.testingModel.documents,
|
| 16 |
);
|
|
|
|
| 17 |
|
| 18 |
const dispatch = useDispatch();
|
| 19 |
-
const getDocumentUrl = useGetDocumentUrl();
|
| 20 |
|
| 21 |
const columns: TableProps<ITestingDocument>['columns'] = [
|
| 22 |
{
|
|
@@ -38,10 +37,15 @@ const SelectFiles = ({ handleTesting }: IProps) => {
|
|
| 38 |
width: 50,
|
| 39 |
render: (_, { doc_id, doc_name }) => (
|
| 40 |
<NewDocumentLink
|
| 41 |
-
|
| 42 |
-
|
|
|
|
| 43 |
>
|
| 44 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
</NewDocumentLink>
|
| 46 |
),
|
| 47 |
},
|
|
|
|
|
|
|
| 1 |
import NewDocumentLink from '@/components/new-document-link';
|
| 2 |
+
import { useTranslate } from '@/hooks/common-hooks';
|
| 3 |
import { ITestingDocument } from '@/interfaces/database/knowledge';
|
| 4 |
+
import { EyeOutlined } from '@ant-design/icons';
|
| 5 |
+
import { Button, Table, TableProps, Tooltip } from 'antd';
|
| 6 |
import { useDispatch, useSelector } from 'umi';
|
| 7 |
|
| 8 |
interface IProps {
|
|
|
|
| 13 |
const documents: ITestingDocument[] = useSelector(
|
| 14 |
(state: any) => state.testingModel.documents,
|
| 15 |
);
|
| 16 |
+
const { t } = useTranslate('fileManager');
|
| 17 |
|
| 18 |
const dispatch = useDispatch();
|
|
|
|
| 19 |
|
| 20 |
const columns: TableProps<ITestingDocument>['columns'] = [
|
| 21 |
{
|
|
|
|
| 37 |
width: 50,
|
| 38 |
render: (_, { doc_id, doc_name }) => (
|
| 39 |
<NewDocumentLink
|
| 40 |
+
documentName={doc_name}
|
| 41 |
+
documentId={doc_id}
|
| 42 |
+
prefix="document"
|
| 43 |
>
|
| 44 |
+
<Tooltip title={t('preview')}>
|
| 45 |
+
<Button type="text">
|
| 46 |
+
<EyeOutlined size={20} />
|
| 47 |
+
</Button>
|
| 48 |
+
</Tooltip>
|
| 49 |
</NewDocumentLink>
|
| 50 |
),
|
| 51 |
},
|
web/src/pages/document-viewer/index.tsx
CHANGED
|
@@ -12,9 +12,10 @@ import styles from './index.less';
|
|
| 12 |
|
| 13 |
const DocumentViewer = () => {
|
| 14 |
const { id: documentId } = useParams();
|
| 15 |
-
const api = `${api_host}/file/get/${documentId}`;
|
| 16 |
const [currentQueryParameters] = useSearchParams();
|
| 17 |
const ext = currentQueryParameters.get('ext');
|
|
|
|
|
|
|
| 18 |
|
| 19 |
return (
|
| 20 |
<section className={styles.viewerWrapper}>
|
|
|
|
| 12 |
|
| 13 |
const DocumentViewer = () => {
|
| 14 |
const { id: documentId } = useParams();
|
|
|
|
| 15 |
const [currentQueryParameters] = useSearchParams();
|
| 16 |
const ext = currentQueryParameters.get('ext');
|
| 17 |
+
const prefix = currentQueryParameters.get('prefix');
|
| 18 |
+
const api = `${api_host}/${prefix || 'file'}/get/${documentId}`;
|
| 19 |
|
| 20 |
return (
|
| 21 |
<section className={styles.viewerWrapper}>
|
web/src/pages/file-manager/action-cell/index.tsx
CHANGED
|
@@ -13,14 +13,12 @@ import { Button, Space, Tooltip } from 'antd';
|
|
| 13 |
import { useHandleDeleteFile } from '../hooks';
|
| 14 |
|
| 15 |
import NewDocumentLink from '@/components/new-document-link';
|
| 16 |
-
import {
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
import styles from './index.less';
|
| 19 |
|
| 20 |
-
const isSupportedPreviewDocumentType = (fileExtension: string) => {
|
| 21 |
-
return SupportedPreviewDocumentTypes.includes(fileExtension);
|
| 22 |
-
};
|
| 23 |
-
|
| 24 |
interface IProps {
|
| 25 |
record: IFile;
|
| 26 |
setCurrentRecord: (record: any) => void;
|
|
@@ -118,8 +116,9 @@ const ActionCell = ({
|
|
| 118 |
)}
|
| 119 |
{isSupportedPreviewDocumentType(extension) && (
|
| 120 |
<NewDocumentLink
|
|
|
|
|
|
|
| 121 |
color="black"
|
| 122 |
-
link={`/document/${documentId}?ext=${extension}`}
|
| 123 |
>
|
| 124 |
<Tooltip title={t('preview')}>
|
| 125 |
<Button type="text" className={styles.iconButton}>
|
|
|
|
| 13 |
import { useHandleDeleteFile } from '../hooks';
|
| 14 |
|
| 15 |
import NewDocumentLink from '@/components/new-document-link';
|
| 16 |
+
import {
|
| 17 |
+
getExtension,
|
| 18 |
+
isSupportedPreviewDocumentType,
|
| 19 |
+
} from '@/utils/documentUtils';
|
| 20 |
import styles from './index.less';
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
interface IProps {
|
| 23 |
record: IFile;
|
| 24 |
setCurrentRecord: (record: any) => void;
|
|
|
|
| 116 |
)}
|
| 117 |
{isSupportedPreviewDocumentType(extension) && (
|
| 118 |
<NewDocumentLink
|
| 119 |
+
documentId={documentId}
|
| 120 |
+
documentName={record.name}
|
| 121 |
color="black"
|
|
|
|
| 122 |
>
|
| 123 |
<Tooltip title={t('preview')}>
|
| 124 |
<Button type="text" className={styles.iconButton}>
|
web/src/utils/documentUtils.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import { IChunk } from '@/interfaces/database/knowledge';
|
| 2 |
import { UploadFile } from 'antd';
|
| 3 |
import { v4 as uuid } from 'uuid';
|
|
@@ -46,3 +47,7 @@ export const isPdf = (name: string) => {
|
|
| 46 |
export const getUnSupportedFilesCount = (message: string) => {
|
| 47 |
return message.split('\n').length;
|
| 48 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { SupportedPreviewDocumentTypes } from '@/constants/common';
|
| 2 |
import { IChunk } from '@/interfaces/database/knowledge';
|
| 3 |
import { UploadFile } from 'antd';
|
| 4 |
import { v4 as uuid } from 'uuid';
|
|
|
|
| 47 |
export const getUnSupportedFilesCount = (message: string) => {
|
| 48 |
return message.split('\n').length;
|
| 49 |
};
|
| 50 |
+
|
| 51 |
+
export const isSupportedPreviewDocumentType = (fileExtension: string) => {
|
| 52 |
+
return SupportedPreviewDocumentTypes.includes(fileExtension);
|
| 53 |
+
};
|