mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-23 08:56:42 +08:00
Consolidateion of document upload API (#14106)
### What problem does this PR solve? Consolidation WEB API & HTTP API for document upload Before consolidation Web API: POST /v1/document/upload Http API - POST /api/v1/datasets/<dataset_id>/documents After consolidation, Restful API -- POST /api/v1/datasets/<dataset_id>/documents ### Type of change - [x] Refactoring
This commit is contained in:
@@ -19,6 +19,7 @@ import { EMPTY_METADATA_FIELD } from '@/pages/dataset/dataset/use-select-filters
|
||||
import kbService, {
|
||||
listDocument,
|
||||
renameDocument,
|
||||
uploadDocument,
|
||||
} from '@/services/knowledge-service';
|
||||
import api, { restAPIv1, webAPI } from '@/utils/api';
|
||||
import { getSearchValue } from '@/utils/common-util';
|
||||
@@ -66,22 +67,24 @@ export const useUploadNextDocument = () => {
|
||||
} = useMutation<ResponseType<IDocumentInfo[]>, Error, File[]>({
|
||||
mutationKey: [DocumentApiAction.UploadDocument],
|
||||
mutationFn: async (fileList) => {
|
||||
if (!id) {
|
||||
return { code: 500, message: 'Dataset ID is required' };
|
||||
}
|
||||
const formData = new FormData();
|
||||
formData.append('kb_id', id!);
|
||||
fileList.forEach((file: any) => {
|
||||
formData.append('file', file);
|
||||
});
|
||||
|
||||
try {
|
||||
const ret = await kbService.documentUpload(formData);
|
||||
const code = get(ret, 'data.code');
|
||||
const ret = await uploadDocument(id, formData);
|
||||
const code = get(ret, 'code');
|
||||
|
||||
if (code === 0 || code === 500) {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: [DocumentApiAction.FetchDocumentList],
|
||||
});
|
||||
}
|
||||
return ret?.data;
|
||||
return ret;
|
||||
} catch (error) {
|
||||
console.warn(error);
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user