mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-07 08:01:13 +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:
@@ -20,29 +20,36 @@ export const useHandleUploadDocument = () => {
|
||||
async ({ fileList, parseOnCreation }: UploadFormSchemaType) => {
|
||||
if (fileList.length > 0) {
|
||||
const ret = await uploadDocument(fileList);
|
||||
if (typeof ret?.message !== 'string') {
|
||||
|
||||
// Check for success (code === 0) or partial success (code === 500 with some files)
|
||||
const isSuccess = ret?.code === 0;
|
||||
const isPartialSuccess = ret?.code === 500 && ret?.message;
|
||||
|
||||
if (!isSuccess && !isPartialSuccess) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ret.code === 0 && parseOnCreation) {
|
||||
if (isSuccess && parseOnCreation) {
|
||||
runDocumentByIds({
|
||||
documentIds: ret.data.map((x) => x.id),
|
||||
documentIds: ret.data.map((x: any) => x.id),
|
||||
run: 1,
|
||||
shouldDelete: false,
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
if (isSuccess) {
|
||||
hideDocumentUploadModal();
|
||||
return 0;
|
||||
}
|
||||
return code;
|
||||
|
||||
// For partial success (code 500), check if any files were uploaded
|
||||
const count = getUnSupportedFilesCount(ret?.message);
|
||||
if (count !== fileList.length) {
|
||||
hideDocumentUploadModal();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ret?.code;
|
||||
}
|
||||
},
|
||||
[uploadDocument, runDocumentByIds, hideDocumentUploadModal],
|
||||
|
||||
Reference in New Issue
Block a user