Feat: Upload document #3221 (#7209)

### What problem does this PR solve?

Feat: Upload document #3221

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2025-04-23 10:39:09 +08:00
committed by GitHub
parent 1e91318445
commit b44bbd11b8
15 changed files with 341 additions and 206 deletions

View File

@ -5,12 +5,9 @@ import {
useRunNextDocument,
useSaveNextDocumentName,
useSetNextDocumentParser,
useUploadNextDocument,
} from '@/hooks/document-hooks';
import { useGetKnowledgeSearchParams } from '@/hooks/route-hook';
import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
import { getUnSupportedFilesCount } from '@/utils/document-util';
import { UploadFile } from 'antd';
import { useCallback, useState } from 'react';
import { useNavigate } from 'umi';
@ -134,46 +131,6 @@ export const useGetRowSelection = () => {
return rowSelection;
};
export const useHandleUploadDocument = () => {
const {
visible: documentUploadVisible,
hideModal: hideDocumentUploadModal,
showModal: showDocumentUploadModal,
} = useSetModalState();
const { uploadDocument, loading } = useUploadNextDocument();
const onDocumentUploadOk = useCallback(
async (fileList: UploadFile[]): Promise<number | undefined> => {
if (fileList.length > 0) {
const ret: any = await uploadDocument(fileList);
if (typeof ret?.message !== 'string') {
return;
}
const count = getUnSupportedFilesCount(ret?.message);
/// 500 error code indicates that some file types are not supported
let code = ret?.code;
if (
ret?.code === 0 ||
(ret?.code === 500 && count !== fileList.length) // Some files were not uploaded successfully, but some were uploaded successfully.
) {
code = 0;
hideDocumentUploadModal();
}
return code;
}
},
[uploadDocument, hideDocumentUploadModal],
);
return {
documentUploadLoading: loading,
onDocumentUploadOk,
documentUploadVisible,
hideDocumentUploadModal,
showDocumentUploadModal,
};
};
export const useHandleWebCrawl = () => {
const {
visible: webCrawlUploadVisible,

View File

@ -2,7 +2,7 @@ import { FileUploadDialog } from '@/components/file-upload-dialog';
import ListFilterBar from '@/components/list-filter-bar';
import { Upload } from 'lucide-react';
import { DatasetTable } from './dataset-table';
import { useHandleUploadDocument } from './hooks';
import { useHandleUploadDocument } from './use-upload-document';
export default function Dataset() {
const {

View File

@ -0,0 +1,44 @@
import { useSetModalState } from '@/hooks/common-hooks';
import { useUploadNextDocument } from '@/hooks/use-document-request';
import { getUnSupportedFilesCount } from '@/utils/document-util';
import { useCallback } from 'react';
export const useHandleUploadDocument = () => {
const {
visible: documentUploadVisible,
hideModal: hideDocumentUploadModal,
showModal: showDocumentUploadModal,
} = useSetModalState();
const { uploadDocument, loading } = useUploadNextDocument();
const onDocumentUploadOk = useCallback(
async (fileList: File[]): Promise<number | undefined> => {
if (fileList.length > 0) {
const ret: any = await uploadDocument(fileList);
if (typeof ret?.message !== 'string') {
return;
}
const count = getUnSupportedFilesCount(ret?.message);
/// 500 error code indicates that some file types are not supported
let code = ret?.code;
if (
ret?.code === 0 ||
(ret?.code === 500 && count !== fileList.length) // Some files were not uploaded successfully, but some were uploaded successfully.
) {
code = 0;
hideDocumentUploadModal();
}
return code;
}
},
[uploadDocument, hideDocumentUploadModal],
);
return {
documentUploadLoading: loading,
onDocumentUploadOk,
documentUploadVisible,
hideDocumentUploadModal,
showDocumentUploadModal,
};
};