mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42: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:
@ -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'] });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user