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:
Jack
2026-04-15 11:27:43 +08:00
committed by GitHub
parent e1dede1366
commit bc5f78996b
13 changed files with 339 additions and 319 deletions

View File

@@ -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],