mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 12:32:30 +08:00
Unified API response json schema (#3170)
### What problem does this PR solve? Unified API response json schema ### Type of change - [x] Refactoring
This commit is contained in:
@ -53,8 +53,8 @@ const getFileIds = (fileList: UploadFile[]) => {
|
||||
};
|
||||
|
||||
const isUploadSuccess = (file: UploadFile) => {
|
||||
const retcode = get(file, 'response.retcode');
|
||||
return typeof retcode === 'number' && retcode === 0;
|
||||
const code = get(file, 'response.code');
|
||||
return typeof code === 'number' && code === 0;
|
||||
};
|
||||
|
||||
interface IProps {
|
||||
@ -116,7 +116,7 @@ const MessageInput = ({
|
||||
const creatingRet = await createConversationBeforeUploadDocument(
|
||||
file.name,
|
||||
);
|
||||
if (creatingRet?.retcode === 0) {
|
||||
if (creatingRet?.code === 0) {
|
||||
nextConversationId = creatingRet.data.id;
|
||||
}
|
||||
}
|
||||
@ -140,7 +140,7 @@ const MessageInput = ({
|
||||
originFileObj: file as any,
|
||||
response: ret,
|
||||
percent: 100,
|
||||
status: ret?.retcode === 0 ? 'done' : 'error',
|
||||
status: ret?.code === 0 ? 'done' : 'error',
|
||||
});
|
||||
return nextList;
|
||||
});
|
||||
|
||||
@ -43,8 +43,8 @@ export const useRemoveMessage = (
|
||||
const onRemoveMessage = useCallback(async () => {
|
||||
const pureId = getMessagePureId(messageId);
|
||||
if (pureId) {
|
||||
const retcode = await deleteMessage(pureId);
|
||||
if (retcode === 0) {
|
||||
const code = await deleteMessage(pureId);
|
||||
if (code === 0) {
|
||||
removeMessageById?.(messageId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,8 +6,8 @@ export const useCatchDocumentError = (url: string) => {
|
||||
|
||||
const fetchDocument = useCallback(async () => {
|
||||
const { data } = await axios.get(url);
|
||||
if (data.retcode !== 0) {
|
||||
setError(data?.retmsg);
|
||||
if (data.code !== 0) {
|
||||
setError(data?.message);
|
||||
}
|
||||
}, [url]);
|
||||
useEffect(() => {
|
||||
|
||||
@ -99,7 +99,7 @@ export const useFetchNextDialogList = () => {
|
||||
console.log('🚀 ~ queryFn: ~ params:', params);
|
||||
const { data } = await chatService.listDialog();
|
||||
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
const list: IDialog[] = data.data;
|
||||
if (list.length > 0) {
|
||||
if (list.every((x) => x.id !== dialogId)) {
|
||||
@ -128,7 +128,7 @@ export const useSetNextDialog = () => {
|
||||
mutationKey: ['setDialog'],
|
||||
mutationFn: async (params: IDialog) => {
|
||||
const { data } = await chatService.setDialog(params);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
queryClient.invalidateQueries({
|
||||
exact: false,
|
||||
queryKey: ['fetchDialogList'],
|
||||
@ -141,7 +141,7 @@ export const useSetNextDialog = () => {
|
||||
i18n.t(`message.${params.dialog_id ? 'modified' : 'created'}`),
|
||||
);
|
||||
}
|
||||
return data?.retcode;
|
||||
return data?.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -200,12 +200,12 @@ export const useRemoveNextDialog = () => {
|
||||
mutationKey: ['removeDialog'],
|
||||
mutationFn: async (dialogIds: string[]) => {
|
||||
const { data } = await chatService.removeDialog({ dialogIds });
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchDialogList'] });
|
||||
|
||||
message.success(i18n.t('message.deleted'));
|
||||
}
|
||||
return data.retcode;
|
||||
return data.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -231,7 +231,7 @@ export const useFetchNextConversationList = () => {
|
||||
enabled: !!dialogId,
|
||||
queryFn: async () => {
|
||||
const { data } = await chatService.listConversation({ dialogId });
|
||||
if (data.retcode === 0 && data.data.length > 0) {
|
||||
if (data.code === 0 && data.data.length > 0) {
|
||||
handleClickConversation(data.data[0].id, '');
|
||||
}
|
||||
return data?.data;
|
||||
@ -303,7 +303,7 @@ export const useUpdateNextConversation = () => {
|
||||
? params.conversation_id
|
||||
: getConversationId(),
|
||||
});
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchConversationList'] });
|
||||
}
|
||||
return data;
|
||||
@ -328,10 +328,10 @@ export const useRemoveNextConversation = () => {
|
||||
conversationIds,
|
||||
dialogId,
|
||||
});
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchConversationList'] });
|
||||
}
|
||||
return data.retcode;
|
||||
return data.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -353,11 +353,11 @@ export const useDeleteMessage = () => {
|
||||
conversationId,
|
||||
});
|
||||
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(i18n.t(`message.deleted`));
|
||||
}
|
||||
|
||||
return data.retcode;
|
||||
return data.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -378,10 +378,10 @@ export const useFeedback = () => {
|
||||
...params,
|
||||
conversationId,
|
||||
});
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(i18n.t(`message.operated`));
|
||||
}
|
||||
return data.retcode;
|
||||
return data.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -402,7 +402,7 @@ export const useCreateNextToken = () => {
|
||||
mutationKey: ['createToken'],
|
||||
mutationFn: async (params: Record<string, any>) => {
|
||||
const { data } = await chatService.createToken(params);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchTokenList'] });
|
||||
}
|
||||
return data?.data ?? [];
|
||||
@ -445,7 +445,7 @@ export const useRemoveNextToken = () => {
|
||||
tokens: string[];
|
||||
}) => {
|
||||
const { data } = await chatService.removeToken(params);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchTokenList'] });
|
||||
}
|
||||
return data?.data ?? [];
|
||||
|
||||
@ -57,7 +57,7 @@ export const useFetchNextChunkList = (): ResponseGetType<{
|
||||
available_int: available,
|
||||
keywords: searchString,
|
||||
});
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
const res = data.data;
|
||||
return {
|
||||
data: res.chunks,
|
||||
@ -126,11 +126,11 @@ export const useDeleteChunk = () => {
|
||||
mutationKey: ['deleteChunk'],
|
||||
mutationFn: async (params: { chunkIds: string[]; doc_id: string }) => {
|
||||
const { data } = await kbService.rm_chunk(params);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
setPaginationParams(1);
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchChunkList'] });
|
||||
}
|
||||
return data?.retcode;
|
||||
return data?.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -152,11 +152,11 @@ export const useSwitchChunk = () => {
|
||||
doc_id: string;
|
||||
}) => {
|
||||
const { data } = await kbService.switch_chunk(params);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(t('message.modified'));
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchChunkList'] });
|
||||
}
|
||||
return data?.retcode;
|
||||
return data?.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -179,11 +179,11 @@ export const useCreateChunk = () => {
|
||||
service = kbService.set_chunk;
|
||||
}
|
||||
const { data } = await service(payload);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(t('message.created'));
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchChunkList'] });
|
||||
}
|
||||
return data?.retcode;
|
||||
return data?.code;
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -69,7 +69,7 @@ export const useFetchNextDocumentList = () => {
|
||||
page_size: pagination.pageSize,
|
||||
page: pagination.current,
|
||||
});
|
||||
if (ret.data.retcode === 0) {
|
||||
if (ret.data.code === 0) {
|
||||
return ret.data.data;
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ export const useSetNextDocumentStatus = () => {
|
||||
doc_id: documentId,
|
||||
status: Number(status),
|
||||
});
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(i18n.t('message.modified'));
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchDocumentList'] });
|
||||
}
|
||||
@ -149,11 +149,11 @@ export const useSaveNextDocumentName = () => {
|
||||
doc_id: documentId,
|
||||
name: name,
|
||||
});
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(i18n.t('message.renamed'));
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchDocumentList'] });
|
||||
}
|
||||
return data.retcode;
|
||||
return data.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -176,7 +176,7 @@ export const useCreateNextDocument = () => {
|
||||
name,
|
||||
kb_id: knowledgeId,
|
||||
});
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
if (page === 1) {
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchDocumentList'] });
|
||||
} else {
|
||||
@ -185,7 +185,7 @@ export const useCreateNextDocument = () => {
|
||||
|
||||
message.success(i18n.t('message.created'));
|
||||
}
|
||||
return data.retcode;
|
||||
return data.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -215,12 +215,12 @@ export const useSetNextDocumentParser = () => {
|
||||
doc_id: documentId,
|
||||
parser_config: parserConfig,
|
||||
});
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchDocumentList'] });
|
||||
|
||||
message.success(i18n.t('message.modified'));
|
||||
}
|
||||
return data.retcode;
|
||||
return data.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -246,12 +246,12 @@ export const useUploadNextDocument = () => {
|
||||
|
||||
try {
|
||||
const ret = await kbService.document_upload(formData);
|
||||
const retcode = get(ret, 'data.retcode');
|
||||
if (retcode === 0) {
|
||||
const code = get(ret, 'data.code');
|
||||
if (code === 0) {
|
||||
message.success(i18n.t('message.uploaded'));
|
||||
}
|
||||
|
||||
if (retcode === 0 || retcode === 500) {
|
||||
if (code === 0 || code === 500) {
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchDocumentList'] });
|
||||
}
|
||||
return ret?.data;
|
||||
@ -281,12 +281,12 @@ export const useNextWebCrawl = () => {
|
||||
formData.append('kb_id', knowledgeId);
|
||||
|
||||
const ret = await kbService.web_crawl(formData);
|
||||
const retcode = get(ret, 'data.retcode');
|
||||
if (retcode === 0) {
|
||||
const code = get(ret, 'data.code');
|
||||
if (code === 0) {
|
||||
message.success(i18n.t('message.uploaded'));
|
||||
}
|
||||
|
||||
return retcode;
|
||||
return code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -317,13 +317,13 @@ export const useRunNextDocument = () => {
|
||||
doc_ids: documentIds,
|
||||
run,
|
||||
});
|
||||
const retcode = get(ret, 'data.retcode');
|
||||
if (retcode === 0) {
|
||||
const code = get(ret, 'data.code');
|
||||
if (code === 0) {
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchDocumentList'] });
|
||||
message.success(i18n.t('message.operated'));
|
||||
}
|
||||
|
||||
return retcode;
|
||||
return code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -338,7 +338,7 @@ export const useFetchDocumentInfosByIds = () => {
|
||||
initialData: [],
|
||||
queryFn: async () => {
|
||||
const { data } = await kbService.document_infos({ doc_ids: ids });
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
return data.data;
|
||||
}
|
||||
|
||||
@ -357,7 +357,7 @@ export const useFetchDocumentThumbnailsByIds = () => {
|
||||
initialData: {},
|
||||
queryFn: async () => {
|
||||
const { data } = await kbService.document_thumbnails({ doc_ids: ids });
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
return data.data;
|
||||
}
|
||||
return {};
|
||||
@ -377,11 +377,11 @@ export const useRemoveNextDocument = () => {
|
||||
mutationKey: ['removeDocument'],
|
||||
mutationFn: async (documentIds: string | string[]) => {
|
||||
const { data } = await kbService.document_rm({ doc_id: documentIds });
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(i18n.t('message.deleted'));
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchDocumentList'] });
|
||||
}
|
||||
return data.retcode;
|
||||
return data.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -398,7 +398,7 @@ export const useDeleteDocument = () => {
|
||||
mutationKey: ['deleteDocument'],
|
||||
mutationFn: async (documentIds: string[]) => {
|
||||
const data = await kbService.document_delete({ doc_ids: documentIds });
|
||||
// if (data.retcode === 0) {
|
||||
// if (data.code === 0) {
|
||||
// queryClient.invalidateQueries({ queryKey: ['fetchFlowList'] });
|
||||
// }
|
||||
return data;
|
||||
|
||||
@ -103,11 +103,11 @@ export const useDeleteFile = () => {
|
||||
mutationKey: ['deleteFile'],
|
||||
mutationFn: async (params: { fileIds: string[]; parentId: string }) => {
|
||||
const { data } = await fileManagerService.removeFile(params);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
setPaginationParams(1); // TODO: There should be a better way to paginate the request list
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchFileList'] });
|
||||
}
|
||||
return data.retcode;
|
||||
return data.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -125,11 +125,11 @@ export const useRenameFile = () => {
|
||||
mutationKey: ['renameFile'],
|
||||
mutationFn: async (params: { fileId: string; name: string }) => {
|
||||
const { data } = await fileManagerService.renameFile(params);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(t('message.renamed'));
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchFileList'] });
|
||||
}
|
||||
return data.retcode;
|
||||
return data.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -170,12 +170,12 @@ export const useCreateFolder = () => {
|
||||
...params,
|
||||
type: 'folder',
|
||||
});
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(t('message.created'));
|
||||
setPaginationParams(1);
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchFileList'] });
|
||||
}
|
||||
return data.retcode;
|
||||
return data.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -208,12 +208,12 @@ export const useUploadFile = () => {
|
||||
});
|
||||
try {
|
||||
const ret = await fileManagerService.uploadFile(formData);
|
||||
if (ret?.data.retcode === 0) {
|
||||
if (ret?.data.code === 0) {
|
||||
message.success(t('message.uploaded'));
|
||||
setPaginationParams(1);
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchFileList'] });
|
||||
}
|
||||
return ret?.data?.retcode;
|
||||
return ret?.data?.code;
|
||||
} catch (error) {
|
||||
console.log('🚀 ~ useUploadFile ~ error:', error);
|
||||
}
|
||||
@ -235,11 +235,11 @@ export const useConnectToKnowledge = () => {
|
||||
mutationKey: ['connectFileToKnowledge'],
|
||||
mutationFn: async (params: IConnectRequestBody) => {
|
||||
const { data } = await fileManagerService.connectFileToKnowledge(params);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(t('message.operated'));
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchFileList'] });
|
||||
}
|
||||
return data.retcode;
|
||||
return data.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -263,11 +263,11 @@ export const useMoveFile = () => {
|
||||
mutationKey: ['moveFile'],
|
||||
mutationFn: async (params: IMoveFileBody) => {
|
||||
const { data } = await fileManagerService.moveFile(params);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(t('message.operated'));
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchFileList'] });
|
||||
}
|
||||
return data.retcode;
|
||||
return data.code;
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -131,7 +131,7 @@ export const useSetFlow = () => {
|
||||
avatar?: string;
|
||||
}) => {
|
||||
const { data = {} } = await flowService.setCanvas(params);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(
|
||||
i18n.t(`message.${params?.id ? 'modified' : 'created'}`),
|
||||
);
|
||||
@ -154,7 +154,7 @@ export const useDeleteFlow = () => {
|
||||
mutationKey: ['deleteFlow'],
|
||||
mutationFn: async (canvasIds: string[]) => {
|
||||
const { data } = await flowService.removeCanvas({ canvasIds });
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchFlowList'] });
|
||||
}
|
||||
return data?.data ?? [];
|
||||
@ -173,7 +173,7 @@ export const useRunFlow = () => {
|
||||
mutationKey: ['runFlow'],
|
||||
mutationFn: async (params: { id: string; dsl: DSL }) => {
|
||||
const { data } = await flowService.runCanvas(params);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(i18n.t(`message.modified`));
|
||||
}
|
||||
return data?.data ?? {};
|
||||
@ -209,7 +209,7 @@ export const useTestDbConnect = () => {
|
||||
mutationKey: ['testDbConnect'],
|
||||
mutationFn: async (params: any) => {
|
||||
const ret = await flowService.testDbConnect(params);
|
||||
if (ret?.data?.retcode === 0) {
|
||||
if (ret?.data?.code === 0) {
|
||||
message.success(ret?.data?.data);
|
||||
} else {
|
||||
message.error(ret?.data?.data);
|
||||
|
||||
@ -70,7 +70,7 @@ export const useCreateKnowledge = () => {
|
||||
mutationKey: ['createKnowledge'],
|
||||
mutationFn: async (params: { id?: string; name: string }) => {
|
||||
const { data = {} } = await kbService.createKb(params);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(
|
||||
i18n.t(`message.${params?.id ? 'modified' : 'created'}`),
|
||||
);
|
||||
@ -93,7 +93,7 @@ export const useDeleteKnowledge = () => {
|
||||
mutationKey: ['deleteKnowledge'],
|
||||
mutationFn: async (id: string) => {
|
||||
const { data } = await kbService.rmKb({ kb_id: id });
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(i18n.t(`message.deleted`));
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchKnowledgeList'] });
|
||||
}
|
||||
@ -120,7 +120,7 @@ export const useUpdateKnowledge = () => {
|
||||
kb_id: knowledgeBaseId,
|
||||
...params,
|
||||
});
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(i18n.t(`message.updated`));
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchKnowledgeDetail'] });
|
||||
}
|
||||
@ -155,7 +155,7 @@ export const useTestChunkRetrieval = (): ResponsePostType<ITestingResult> & {
|
||||
page,
|
||||
size: pageSize,
|
||||
});
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
const res = data.data;
|
||||
return {
|
||||
chunks: res.chunks,
|
||||
|
||||
@ -211,12 +211,12 @@ export const useSaveApiKey = () => {
|
||||
mutationKey: ['saveApiKey'],
|
||||
mutationFn: async (params: IApiKeySavingParams) => {
|
||||
const { data } = await userService.set_api_key(params);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(t('message.modified'));
|
||||
queryClient.invalidateQueries({ queryKey: ['myLlmList'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['factoryList'] });
|
||||
}
|
||||
return data.retcode;
|
||||
return data.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -242,10 +242,10 @@ export const useSaveTenantInfo = () => {
|
||||
mutationKey: ['saveTenantInfo'],
|
||||
mutationFn: async (params: ISystemModelSettingSavingParams) => {
|
||||
const { data } = await userService.set_tenant_info(params);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(t('message.modified'));
|
||||
}
|
||||
return data.retcode;
|
||||
return data.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -263,12 +263,12 @@ export const useAddLlm = () => {
|
||||
mutationKey: ['addLlm'],
|
||||
mutationFn: async (params: IAddLlmRequestBody) => {
|
||||
const { data } = await userService.add_llm(params);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
queryClient.invalidateQueries({ queryKey: ['myLlmList'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['factoryList'] });
|
||||
message.success(t('message.modified'));
|
||||
}
|
||||
return data.retcode;
|
||||
return data.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -286,12 +286,12 @@ export const useDeleteLlm = () => {
|
||||
mutationKey: ['deleteLlm'],
|
||||
mutationFn: async (params: IDeleteLlmRequestBody) => {
|
||||
const { data } = await userService.delete_llm(params);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
queryClient.invalidateQueries({ queryKey: ['myLlmList'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['factoryList'] });
|
||||
message.success(t('message.deleted'));
|
||||
}
|
||||
return data.retcode;
|
||||
return data.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -309,12 +309,12 @@ export const useDeleteFactory = () => {
|
||||
mutationKey: ['deleteFactory'],
|
||||
mutationFn: async (params: IDeleteLlmRequestBody) => {
|
||||
const { data } = await userService.deleteFactory(params);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
queryClient.invalidateQueries({ queryKey: ['myLlmList'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['factoryList'] });
|
||||
message.success(t('message.deleted'));
|
||||
}
|
||||
return data.retcode;
|
||||
return data.code;
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -248,8 +248,8 @@ export const useSpeechWithSse = (url: string = api.tts) => {
|
||||
});
|
||||
try {
|
||||
const res = await response.clone().json();
|
||||
if (res?.retcode !== 0) {
|
||||
message.error(res?.retmsg);
|
||||
if (res?.code !== 0) {
|
||||
message.error(res?.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('🚀 ~ error:', error);
|
||||
|
||||
@ -26,7 +26,7 @@ export const useLogin = () => {
|
||||
mutationKey: ['login'],
|
||||
mutationFn: async (params: { email: string; password: string }) => {
|
||||
const { data: res = {}, response } = await userService.login(params);
|
||||
if (res.retcode === 0) {
|
||||
if (res.code === 0) {
|
||||
const { data } = res;
|
||||
message.success(t('message.logged'));
|
||||
const authorization = response.headers.get(Authorization);
|
||||
@ -42,7 +42,7 @@ export const useLogin = () => {
|
||||
Token: token,
|
||||
});
|
||||
}
|
||||
return res.retcode;
|
||||
return res.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -64,10 +64,10 @@ export const useRegister = () => {
|
||||
nickname: string;
|
||||
}) => {
|
||||
const { data = {} } = await userService.register(params);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(t('message.registered'));
|
||||
}
|
||||
return data.retcode;
|
||||
return data.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -84,12 +84,12 @@ export const useLogout = () => {
|
||||
mutationKey: ['logout'],
|
||||
mutationFn: async () => {
|
||||
const { data = {} } = await userService.logout();
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(t('message.logout'));
|
||||
authorizationUtil.removeAll();
|
||||
history.push('/login');
|
||||
}
|
||||
return data.retcode;
|
||||
return data.code;
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ export const useFetchUserInfo = (): ResponseGetType<IUserInfo> => {
|
||||
gcTime: 0,
|
||||
queryFn: async () => {
|
||||
const { data } = await userService.user_info();
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
i18n.changeLanguage(
|
||||
LanguageTranslationMap[
|
||||
data.data.language as keyof typeof LanguageTranslationMap
|
||||
@ -54,7 +54,7 @@ export const useFetchTenantInfo = (): ResponseGetType<ITenantInfo> => {
|
||||
gcTime: 0,
|
||||
queryFn: async () => {
|
||||
const { data: res } = await userService.get_tenant_info();
|
||||
if (res.retcode === 0) {
|
||||
if (res.code === 0) {
|
||||
// llm_id is chat_id
|
||||
// asr_id is speech2txt
|
||||
const { data } = res;
|
||||
@ -116,11 +116,11 @@ export const useSaveSetting = () => {
|
||||
userInfo: { new_password: string } | Partial<IUserInfo>,
|
||||
) => {
|
||||
const { data } = await userService.setting(userInfo);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(t('message.modified'));
|
||||
queryClient.invalidateQueries({ queryKey: ['userInfo'] });
|
||||
}
|
||||
return data?.retcode;
|
||||
return data?.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -135,7 +135,7 @@ export const useFetchSystemVersion = () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const { data } = await userService.getSystemVersion();
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
setVersion(data.data);
|
||||
setLoading(false);
|
||||
}
|
||||
@ -156,7 +156,7 @@ export const useFetchSystemStatus = () => {
|
||||
const fetchSystemStatus = useCallback(async () => {
|
||||
setLoading(true);
|
||||
const { data } = await userService.getSystemStatus();
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
setSystemStatus(data.data);
|
||||
setLoading(false);
|
||||
}
|
||||
@ -200,7 +200,7 @@ export const useRemoveSystemToken = () => {
|
||||
mutationKey: ['removeSystemToken'],
|
||||
mutationFn: async (token: string) => {
|
||||
const { data } = await userService.removeToken({}, token);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(t('message.deleted'));
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchSystemTokenList'] });
|
||||
}
|
||||
@ -221,7 +221,7 @@ export const useCreateSystemToken = () => {
|
||||
mutationKey: ['createSystemToken'],
|
||||
mutationFn: async (params: Record<string, any>) => {
|
||||
const { data } = await userService.createToken(params);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchSystemTokenList'] });
|
||||
}
|
||||
return data?.data ?? [];
|
||||
@ -264,10 +264,10 @@ export const useAddTenantUser = () => {
|
||||
mutationKey: ['addTenantUser'],
|
||||
mutationFn: async (email: string) => {
|
||||
const { data } = await addTenantUser(tenantInfo.tenant_id, email);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
queryClient.invalidateQueries({ queryKey: ['listTenantUser'] });
|
||||
}
|
||||
return data?.retcode;
|
||||
return data?.code;
|
||||
},
|
||||
});
|
||||
|
||||
@ -296,7 +296,7 @@ export const useDeleteTenantUser = () => {
|
||||
tenantId: tenantId ?? tenantInfo.tenant_id,
|
||||
userId,
|
||||
});
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(t('message.deleted'));
|
||||
queryClient.invalidateQueries({ queryKey: ['listTenantUser'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['listTenant'] });
|
||||
@ -342,7 +342,7 @@ export const useAgreeTenant = () => {
|
||||
mutationKey: ['agreeTenant'],
|
||||
mutationFn: async (tenantId: string) => {
|
||||
const { data } = await agreeTenant(tenantId);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
message.success(t('message.operated'));
|
||||
queryClient.invalidateQueries({ queryKey: ['listTenant'] });
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
export interface ResponseType<T = any> {
|
||||
retcode: number;
|
||||
code: number;
|
||||
data: T;
|
||||
retmsg: string;
|
||||
message: string;
|
||||
status: number;
|
||||
}
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ const ChunkCreatingModal: React.FC<IModalProps<any> & kFProps> = ({
|
||||
const { t } = useTranslation();
|
||||
|
||||
useEffect(() => {
|
||||
if (data?.retcode === 0) {
|
||||
if (data?.code === 0) {
|
||||
const { content_with_weight, important_kwd = [] } = data.data;
|
||||
form.setFieldsValue({ content: content_with_weight });
|
||||
setKeywords(important_kwd);
|
||||
|
||||
@ -96,14 +96,14 @@ export const useUpdateChunk = () => {
|
||||
|
||||
const onChunkUpdatingOk = useCallback(
|
||||
async ({ content, keywords }: { content: string; keywords: string }) => {
|
||||
const retcode = await createChunk({
|
||||
const code = await createChunk({
|
||||
content_with_weight: content,
|
||||
doc_id: documentId,
|
||||
chunk_id: chunkId,
|
||||
important_kwd: keywords, // keywords
|
||||
});
|
||||
|
||||
if (retcode === 0) {
|
||||
if (code === 0) {
|
||||
hideChunkUpdatingModal();
|
||||
}
|
||||
},
|
||||
|
||||
@ -148,20 +148,20 @@ export const useHandleUploadDocument = () => {
|
||||
async (fileList: UploadFile[]): Promise<number | undefined> => {
|
||||
if (fileList.length > 0) {
|
||||
const ret: any = await uploadDocument(fileList);
|
||||
if (typeof ret?.retmsg !== 'string') {
|
||||
if (typeof ret?.message !== 'string') {
|
||||
return;
|
||||
}
|
||||
const count = getUnSupportedFilesCount(ret?.retmsg);
|
||||
const count = getUnSupportedFilesCount(ret?.message);
|
||||
/// 500 error code indicates that some file types are not supported
|
||||
let retcode = ret?.retcode;
|
||||
let code = ret?.code;
|
||||
if (
|
||||
ret?.retcode === 0 ||
|
||||
(ret?.retcode === 500 && count !== fileList.length) // Some files were not uploaded successfully, but some were uploaded successfully.
|
||||
ret?.code === 0 ||
|
||||
(ret?.code === 500 && count !== fileList.length) // Some files were not uploaded successfully, but some were uploaded successfully.
|
||||
) {
|
||||
retcode = 0;
|
||||
code = 0;
|
||||
hideDocumentUploadModal();
|
||||
}
|
||||
return retcode;
|
||||
return code;
|
||||
}
|
||||
},
|
||||
[uploadDocument, hideDocumentUploadModal],
|
||||
|
||||
@ -176,7 +176,7 @@ export const useEditDialog = () => {
|
||||
async (dialogId?: string) => {
|
||||
if (dialogId) {
|
||||
const ret = await fetchDialog(dialogId);
|
||||
if (ret.retcode === 0) {
|
||||
if (ret.code === 0) {
|
||||
setDialog(ret.data);
|
||||
}
|
||||
}
|
||||
@ -393,7 +393,7 @@ export const useSendNextMessage = (controller: AbortController) => {
|
||||
controller,
|
||||
);
|
||||
|
||||
if (res && (res?.response.status !== 200 || res?.data?.retcode !== 0)) {
|
||||
if (res && (res?.response.status !== 200 || res?.data?.code !== 0)) {
|
||||
// cancel loading
|
||||
setValue(message.content);
|
||||
console.info('removeLatestMessage111');
|
||||
@ -421,7 +421,7 @@ export const useSendNextMessage = (controller: AbortController) => {
|
||||
true,
|
||||
conversationId,
|
||||
);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
setConversationIsNew('');
|
||||
const id = data.data.id;
|
||||
// currentConversationIdRef.current = id;
|
||||
@ -541,7 +541,7 @@ export const useRenameConversation = () => {
|
||||
is_new: false,
|
||||
});
|
||||
|
||||
if (ret.retcode === 0) {
|
||||
if (ret.code === 0) {
|
||||
hideConversationRenameModal();
|
||||
}
|
||||
},
|
||||
@ -551,7 +551,7 @@ export const useRenameConversation = () => {
|
||||
const handleShowConversationRenameModal = useCallback(
|
||||
async (conversationId: string) => {
|
||||
const ret = await fetchConversation(conversationId);
|
||||
if (ret.retcode === 0) {
|
||||
if (ret.code === 0) {
|
||||
setConversation(ret.data);
|
||||
}
|
||||
showConversationRenameModal();
|
||||
|
||||
@ -96,7 +96,7 @@ export const useSendSharedMessage = (conversationId: string) => {
|
||||
messages: [...(derivedMessages ?? []), message],
|
||||
});
|
||||
|
||||
if (res && (res?.response.status !== 200 || res?.data?.retcode !== 0)) {
|
||||
if (res && (res?.response.status !== 200 || res?.data?.code !== 0)) {
|
||||
// cancel loading
|
||||
setValue(message.content);
|
||||
removeLatestMessage();
|
||||
@ -111,7 +111,7 @@ export const useSendSharedMessage = (conversationId: string) => {
|
||||
sendMessage(message);
|
||||
} else {
|
||||
const data = await setConversation('user id');
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
const id = data.data.id;
|
||||
sendMessage(message, id);
|
||||
}
|
||||
|
||||
@ -8,8 +8,8 @@ export const useCatchError = (api: string) => {
|
||||
const fetchDocument = useCallback(async () => {
|
||||
const ret = await axios.get(api);
|
||||
const { data } = ret;
|
||||
if (!(data instanceof ArrayBuffer) && data.retcode !== 0) {
|
||||
setError(data.retmsg);
|
||||
if (!(data instanceof ArrayBuffer) && data.code !== 0) {
|
||||
setError(data.message);
|
||||
}
|
||||
return ret;
|
||||
}, [api]);
|
||||
|
||||
@ -141,8 +141,8 @@ export const useHandleDeleteFile = (
|
||||
const handleRemoveFile = () => {
|
||||
showDeleteConfirm({
|
||||
onOk: async () => {
|
||||
const retcode = await removeDocument({ fileIds, parentId });
|
||||
if (retcode === 0) {
|
||||
const code = await removeDocument({ fileIds, parentId });
|
||||
if (code === 0) {
|
||||
setSelectedRowKeys([]);
|
||||
}
|
||||
return;
|
||||
|
||||
@ -22,7 +22,7 @@ const AsyncTreeSelect = ({ value, onChange }: IProps) => {
|
||||
const onLoadData: TreeSelectProps['loadData'] = useCallback(
|
||||
async ({ id }) => {
|
||||
const ret = await fetchList(id);
|
||||
if (ret.retcode === 0) {
|
||||
if (ret.code === 0) {
|
||||
setTreeData((tree) => {
|
||||
return tree.concat(
|
||||
ret.data.files
|
||||
|
||||
@ -151,7 +151,7 @@ export const useSendMessage = (
|
||||
const res = await send(params);
|
||||
|
||||
if (receiveMessageError(res)) {
|
||||
antMessage.error(res?.data?.retmsg);
|
||||
antMessage.error(res?.data?.message);
|
||||
|
||||
// cancel loading
|
||||
setValue(message.content);
|
||||
@ -227,7 +227,7 @@ export const useSendNextMessage = () => {
|
||||
const res = await send(params);
|
||||
|
||||
if (receiveMessageError(res)) {
|
||||
antMessage.error(res?.data?.retmsg);
|
||||
antMessage.error(res?.data?.message);
|
||||
|
||||
// cancel loading
|
||||
setValue(message.content);
|
||||
|
||||
@ -497,15 +497,15 @@ export const useSaveGraphBeforeOpeningDebugDrawer = (show: () => void) => {
|
||||
const { send } = useSendMessageWithSse(api.runCanvas);
|
||||
const handleRun = useCallback(async () => {
|
||||
const saveRet = await saveGraph();
|
||||
if (saveRet?.retcode === 0) {
|
||||
if (saveRet?.code === 0) {
|
||||
// Call the reset api before opening the run drawer each time
|
||||
const resetRet = await resetFlow();
|
||||
// After resetting, all previous messages will be cleared.
|
||||
if (resetRet?.retcode === 0) {
|
||||
if (resetRet?.code === 0) {
|
||||
// fetch prologue
|
||||
const sendRet = await send({ id });
|
||||
if (receiveMessageError(sendRet)) {
|
||||
message.error(sendRet?.data?.retmsg);
|
||||
message.error(sendRet?.data?.message);
|
||||
} else {
|
||||
refetch();
|
||||
show();
|
||||
|
||||
@ -53,7 +53,7 @@ export const useSaveFlow = () => {
|
||||
// },
|
||||
});
|
||||
|
||||
if (ret?.retcode === 0) {
|
||||
if (ret?.code === 0) {
|
||||
hideFlowSettingModal();
|
||||
navigate(`/flow/${ret.data.id}`);
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ export const buildDslComponentsByGraph = (
|
||||
};
|
||||
|
||||
export const receiveMessageError = (res: any) =>
|
||||
res && (res?.response.status !== 200 || res?.data?.retcode !== 0);
|
||||
res && (res?.response.status !== 200 || res?.data?.code !== 0);
|
||||
|
||||
// Replace the id in the object with text
|
||||
export const replaceIdWithText = (
|
||||
|
||||
@ -27,7 +27,7 @@ export const useSaveKnowledge = () => {
|
||||
name,
|
||||
});
|
||||
|
||||
if (ret?.retcode === 0) {
|
||||
if (ret?.code === 0) {
|
||||
hideModal();
|
||||
navigate(
|
||||
`/knowledge/${KnowledgeRouteKey.Configuration}?id=${ret.data.kb_id}`,
|
||||
|
||||
@ -33,20 +33,20 @@ const Login = () => {
|
||||
const rsaPassWord = rsaPsw(params.password) as string;
|
||||
|
||||
if (title === 'login') {
|
||||
const retcode = await login({
|
||||
const code = await login({
|
||||
email: params.email,
|
||||
password: rsaPassWord,
|
||||
});
|
||||
if (retcode === 0) {
|
||||
if (code === 0) {
|
||||
navigate('/knowledge');
|
||||
}
|
||||
} else {
|
||||
const retcode = await register({
|
||||
const code = await register({
|
||||
nickname: params.nickname,
|
||||
email: params.email,
|
||||
password: rsaPassWord,
|
||||
});
|
||||
if (retcode === 0) {
|
||||
if (code === 0) {
|
||||
setTitle('login');
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,8 +17,8 @@ export const useAddUser = () => {
|
||||
|
||||
const handleAddUserOk = useCallback(
|
||||
async (email: string) => {
|
||||
const retcode = await addTenantUser(email);
|
||||
if (retcode === 0) {
|
||||
const code = await addTenantUser(email);
|
||||
if (code === 0) {
|
||||
hideAddingTenantModal();
|
||||
}
|
||||
},
|
||||
@ -40,8 +40,8 @@ export const useHandleDeleteUser = () => {
|
||||
const handleDeleteTenantUser = (userId: string) => () => {
|
||||
showDeleteConfirm({
|
||||
onOk: async () => {
|
||||
const retcode = await deleteTenantUser({ userId });
|
||||
if (retcode === 0) {
|
||||
const code = await deleteTenantUser({ userId });
|
||||
if (code === 0) {
|
||||
}
|
||||
return;
|
||||
},
|
||||
|
||||
@ -109,21 +109,21 @@ request.interceptors.response.use(async (response: any, options) => {
|
||||
|
||||
const data: ResponseType = await response.clone().json();
|
||||
|
||||
if (data.retcode === 401 || data.retcode === 401) {
|
||||
if (data.code === 401 || data.code === 401) {
|
||||
notification.error({
|
||||
message: data.retmsg,
|
||||
description: data.retmsg,
|
||||
message: data.message,
|
||||
description: data.message,
|
||||
duration: 3,
|
||||
});
|
||||
authorizationUtil.removeAll();
|
||||
history.push('/login'); // Will not jump to the login page
|
||||
} else if (data.retcode !== 0) {
|
||||
if (data.retcode === 100) {
|
||||
message.error(data.retmsg);
|
||||
} else if (data.code !== 0) {
|
||||
if (data.code === 100) {
|
||||
message.error(data.message);
|
||||
} else {
|
||||
notification.error({
|
||||
message: `${i18n.t('message.hint')} : ${data.retcode}`,
|
||||
description: data.retmsg,
|
||||
message: `${i18n.t('message.hint')} : ${data.code}`,
|
||||
description: data.message,
|
||||
duration: 3,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user