mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
feat: support DeepSeek (#667)
### What problem does this PR solve? #666 feat: support DeepSeek feat: preview word and excel ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
35
web/src/pages/document-viewer/excel/index.tsx
Normal file
35
web/src/pages/document-viewer/excel/index.tsx
Normal file
@ -0,0 +1,35 @@
|
||||
import jsPreviewExcel from '@js-preview/excel';
|
||||
import '@js-preview/excel/lib/index.css';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
const Excel = ({ filePath }: { filePath: string }) => {
|
||||
const fetchDocument = async () => {
|
||||
const myExcelPreviewer = jsPreviewExcel.init(
|
||||
document.getElementById('excel'),
|
||||
);
|
||||
const jsonFile = new XMLHttpRequest();
|
||||
jsonFile.open('GET', filePath, true);
|
||||
jsonFile.send();
|
||||
jsonFile.responseType = 'arraybuffer';
|
||||
jsonFile.onreadystatechange = () => {
|
||||
if (jsonFile.readyState === 4 && jsonFile.status === 200) {
|
||||
myExcelPreviewer
|
||||
.preview(jsonFile.response)
|
||||
.then((res: any) => {
|
||||
console.log('succeed');
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log('failed', e);
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchDocument();
|
||||
}, []);
|
||||
|
||||
return <div id="excel" style={{ height: '100%' }}></div>;
|
||||
};
|
||||
|
||||
export default Excel;
|
||||
8
web/src/pages/document-viewer/index.less
Normal file
8
web/src/pages/document-viewer/index.less
Normal file
@ -0,0 +1,8 @@
|
||||
.viewerWrapper {
|
||||
width: 100%;
|
||||
:global {
|
||||
.pdf-canvas {
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
web/src/pages/document-viewer/index.tsx
Normal file
28
web/src/pages/document-viewer/index.tsx
Normal file
@ -0,0 +1,28 @@
|
||||
import { api_host } from '@/utils/api';
|
||||
import FileViewer from 'react-file-viewer';
|
||||
import { useParams, useSearchParams } from 'umi';
|
||||
import Excel from './excel';
|
||||
|
||||
import styles from './index.less';
|
||||
|
||||
const DocumentViewer = () => {
|
||||
const { id: documentId } = useParams();
|
||||
const api = `${api_host}/file/get/${documentId}`;
|
||||
const [currentQueryParameters] = useSearchParams();
|
||||
const ext = currentQueryParameters.get('ext');
|
||||
|
||||
const onError = (e: any) => {
|
||||
console.error(e, 'error in file-viewer');
|
||||
};
|
||||
|
||||
return (
|
||||
<section className={styles.viewerWrapper}>
|
||||
{ext === 'xlsx' && <Excel filePath={api}></Excel>}
|
||||
{ext !== 'xlsx' && (
|
||||
<FileViewer fileType={ext} filePath={api} onError={onError} />
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
};
|
||||
|
||||
export default DocumentViewer;
|
||||
@ -9,7 +9,7 @@ import {
|
||||
LinkOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { Button, Space, Tooltip } from 'antd';
|
||||
import { useHandleDeleteFile } from '../hooks';
|
||||
import { useHandleDeleteFile, useNavigateToDocument } from '../hooks';
|
||||
|
||||
import styles from './index.less';
|
||||
|
||||
@ -35,6 +35,7 @@ const ActionCell = ({
|
||||
[documentId],
|
||||
setSelectedRowKeys,
|
||||
);
|
||||
const navigateToDocument = useNavigateToDocument(record.id, record.name);
|
||||
|
||||
const onDownloadDocument = () => {
|
||||
downloadFile({
|
||||
@ -58,6 +59,15 @@ const ActionCell = ({
|
||||
|
||||
return (
|
||||
<Space size={0}>
|
||||
{/* <Tooltip title={t('addToKnowledge')}>
|
||||
<Button
|
||||
type="text"
|
||||
className={styles.iconButton}
|
||||
onClick={navigateToDocument}
|
||||
>
|
||||
<EyeOutlined size={20} />
|
||||
</Button>
|
||||
</Tooltip> */}
|
||||
<Tooltip title={t('addToKnowledge')}>
|
||||
<Button
|
||||
type="text"
|
||||
|
||||
@ -13,6 +13,7 @@ import {
|
||||
import { useGetPagination, useSetPagination } from '@/hooks/logicHooks';
|
||||
import { useOneNamespaceEffectsLoading } from '@/hooks/storeHooks';
|
||||
import { IFile } from '@/interfaces/database/file-manager';
|
||||
import { getExtension } from '@/utils/documentUtils';
|
||||
import { PaginationProps } from 'antd';
|
||||
import { UploadFile } from 'antd/lib';
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
@ -338,3 +339,12 @@ export const useHandleBreadcrumbClick = () => {
|
||||
|
||||
return { handleBreadcrumbClick };
|
||||
};
|
||||
|
||||
export const useNavigateToDocument = (documentId: string, name: string) => {
|
||||
const navigate = useNavigate();
|
||||
const navigateToDocument = () => {
|
||||
navigate(`/document/${documentId}?ext=${getExtension(name)}`);
|
||||
};
|
||||
|
||||
return navigateToDocument;
|
||||
};
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { useSelectFileList } from '@/hooks/fileManagerHooks';
|
||||
import { IFile } from '@/interfaces/database/file-manager';
|
||||
import { formatDate } from '@/utils/date';
|
||||
import { Button, Flex, Space, Table, Tag } from 'antd';
|
||||
import { Button, Flex, Space, Table, Tag, Typography } from 'antd';
|
||||
import { ColumnsType } from 'antd/es/table';
|
||||
import ActionCell from './action-cell';
|
||||
import FileToolbar from './file-toolbar';
|
||||
@ -26,6 +26,8 @@ import ConnectToKnowledgeModal from './connect-to-knowledge-modal';
|
||||
import FolderCreateModal from './folder-create-modal';
|
||||
import styles from './index.less';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
const FileManager = () => {
|
||||
const { t } = useTranslate('fileManager');
|
||||
const fileList = useSelectFileList();
|
||||
@ -69,6 +71,7 @@ const FileManager = () => {
|
||||
title: t('name'),
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
fixed: 'left',
|
||||
render(value, record) {
|
||||
return (
|
||||
<Flex gap={10} align="center">
|
||||
@ -82,10 +85,10 @@ const FileManager = () => {
|
||||
className={styles.linkButton}
|
||||
onClick={() => navigateToOtherFolder(record.id)}
|
||||
>
|
||||
{value}
|
||||
<Text ellipsis={{ tooltip: value }}>{value}</Text>
|
||||
</Button>
|
||||
) : (
|
||||
value
|
||||
<Text ellipsis={{ tooltip: value }}>{value}</Text>
|
||||
)}
|
||||
</Flex>
|
||||
);
|
||||
@ -160,6 +163,7 @@ const FileManager = () => {
|
||||
rowSelection={rowSelection}
|
||||
loading={loading}
|
||||
pagination={pagination}
|
||||
scroll={{ scrollToFirstRowOnChange: true, x: '100%' }}
|
||||
/>
|
||||
<RenameModal
|
||||
visible={fileRenameVisible}
|
||||
|
||||
@ -2,7 +2,9 @@ import { paginationModel } from '@/base';
|
||||
import { BaseState } from '@/interfaces/common';
|
||||
import { IFile, IFolder } from '@/interfaces/database/file-manager';
|
||||
import i18n from '@/locales/config';
|
||||
import fileManagerService from '@/services/fileManagerService';
|
||||
import fileManagerService, {
|
||||
getDocumentFile,
|
||||
} from '@/services/fileManagerService';
|
||||
import { message } from 'antd';
|
||||
import omit from 'lodash/omit';
|
||||
import { DvaModel } from 'umi';
|
||||
@ -139,6 +141,11 @@ const model: DvaModel<FileManagerModelState> = {
|
||||
}
|
||||
return data.retcode;
|
||||
},
|
||||
*getDocumentFile({ payload = {} }, { call }) {
|
||||
const ret = yield call(getDocumentFile, payload);
|
||||
|
||||
return ret;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@ -45,6 +45,7 @@ const IconMap = {
|
||||
文心一言: 'wenxin',
|
||||
Ollama: 'ollama',
|
||||
Xinference: 'xinference',
|
||||
DeepSeek: 'deepseek',
|
||||
};
|
||||
|
||||
const LlmIcon = ({ name }: { name: string }) => {
|
||||
|
||||
Reference in New Issue
Block a user