diff --git a/web/src/app.tsx b/web/src/app.tsx
index 67e1844a54..2f90e50bcf 100644
--- a/web/src/app.tsx
+++ b/web/src/app.tsx
@@ -13,7 +13,7 @@ import weekOfYear from 'dayjs/plugin/weekOfYear';
import weekYear from 'dayjs/plugin/weekYear';
import weekday from 'dayjs/plugin/weekday';
import React, { ReactNode, useEffect, useState } from 'react';
-import storage from './utils/authorizationUtil';
+import storage from './utils/authorization-util';
dayjs.extend(customParseFormat);
dayjs.extend(advancedFormat);
diff --git a/web/src/components/message-item/index.tsx b/web/src/components/message-item/index.tsx
index ea31ce3d9b..2f17e34600 100644
--- a/web/src/components/message-item/index.tsx
+++ b/web/src/components/message-item/index.tsx
@@ -8,7 +8,7 @@ import classNames from 'classnames';
import { useMemo } from 'react';
import MarkdownContent from '@/pages/chat/markdown-content';
-import { getExtension } from '@/utils/documentUtils';
+import { getExtension } from '@/utils/document-util';
import { Avatar, Flex, List } from 'antd';
import NewDocumentLink from '../new-document-link';
import SvgIcon from '../svg-icon';
diff --git a/web/src/components/new-document-link.tsx b/web/src/components/new-document-link.tsx
index 055e9d2ae6..62a23dd590 100644
--- a/web/src/components/new-document-link.tsx
+++ b/web/src/components/new-document-link.tsx
@@ -1,7 +1,7 @@
import {
getExtension,
isSupportedPreviewDocumentType,
-} from '@/utils/documentUtils';
+} from '@/utils/document-util';
import React from 'react';
interface IProps extends React.PropsWithChildren {
diff --git a/web/src/hooks/auth-hooks.ts b/web/src/hooks/auth-hooks.ts
index 114257d6cb..f1081d6830 100644
--- a/web/src/hooks/auth-hooks.ts
+++ b/web/src/hooks/auth-hooks.ts
@@ -1,4 +1,4 @@
-import authorizationUtil from '@/utils/authorizationUtil';
+import authorizationUtil from '@/utils/authorization-util';
import { message } from 'antd';
import { useEffect, useMemo, useState } from 'react';
import { useNavigate, useSearchParams } from 'umi';
diff --git a/web/src/hooks/document-hooks.ts b/web/src/hooks/document-hooks.ts
index c18e08d426..aa34c8729f 100644
--- a/web/src/hooks/document-hooks.ts
+++ b/web/src/hooks/document-hooks.ts
@@ -1,7 +1,7 @@
import { IChunk, IKnowledgeFile } from '@/interfaces/database/knowledge';
import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
import { api_host } from '@/utils/api';
-import { buildChunkHighlights } from '@/utils/documentUtils';
+import { buildChunkHighlights } from '@/utils/document-util';
import { UploadFile } from 'antd';
import { useCallback, useMemo, useState } from 'react';
import { IHighlight } from 'react-pdf-highlighter';
diff --git a/web/src/hooks/llm-hooks.ts b/web/src/hooks/llm-hooks.ts
index 78e8d947ad..dfe684b8ce 100644
--- a/web/src/hooks/llm-hooks.ts
+++ b/web/src/hooks/llm-hooks.ts
@@ -8,7 +8,7 @@ import {
IAddLlmRequestBody,
IDeleteLlmRequestBody,
} from '@/interfaces/request/llm';
-import { sortLLmFactoryListBySpecifiedOrder } from '@/utils/commonUtil';
+import { sortLLmFactoryListBySpecifiedOrder } from '@/utils/common-util';
import { useCallback, useEffect, useMemo } from 'react';
import { useDispatch, useSelector } from 'umi';
diff --git a/web/src/hooks/logic-hooks.ts b/web/src/hooks/logic-hooks.ts
index bc2eb46f37..841d74baa3 100644
--- a/web/src/hooks/logic-hooks.ts
+++ b/web/src/hooks/logic-hooks.ts
@@ -6,7 +6,7 @@ import { IAnswer } from '@/interfaces/database/chat';
import { IKnowledgeFile } from '@/interfaces/database/knowledge';
import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
import api from '@/utils/api';
-import { getAuthorization } from '@/utils/authorizationUtil';
+import { getAuthorization } from '@/utils/authorization-util';
import { PaginationProps } from 'antd';
import axios from 'axios';
import { EventSourceParserStream } from 'eventsource-parser/stream';
diff --git a/web/src/hooks/login-hooks.ts b/web/src/hooks/login-hooks.ts
index 040759d34d..f149cdac1a 100644
--- a/web/src/hooks/login-hooks.ts
+++ b/web/src/hooks/login-hooks.ts
@@ -1,6 +1,6 @@
import { Authorization } from '@/constants/authorization';
import userService from '@/services/user-service';
-import authorizationUtil from '@/utils/authorizationUtil';
+import authorizationUtil from '@/utils/authorization-util';
import { useMutation } from '@tanstack/react-query';
import { message } from 'antd';
import { useTranslation } from 'react-i18next';
diff --git a/web/src/hooks/store-hooks.ts b/web/src/hooks/store-hooks.ts
index 6670bea7be..ddd332dc0d 100644
--- a/web/src/hooks/store-hooks.ts
+++ b/web/src/hooks/store-hooks.ts
@@ -1,4 +1,4 @@
-import { getOneNamespaceEffectsLoading } from '@/utils/storeUtil';
+import { getOneNamespaceEffectsLoading } from '@/utils/store-util';
import { useSelector } from 'umi';
// Get the loading status of given effects under a certain namespace
diff --git a/web/src/pages/add-knowledge/components/knowledge-chunk/hooks.ts b/web/src/pages/add-knowledge/components/knowledge-chunk/hooks.ts
index 3666beb5e5..310d146e03 100644
--- a/web/src/pages/add-knowledge/components/knowledge-chunk/hooks.ts
+++ b/web/src/pages/add-knowledge/components/knowledge-chunk/hooks.ts
@@ -1,6 +1,6 @@
import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
import { IChunk, IKnowledgeFile } from '@/interfaces/database/knowledge';
-import { buildChunkHighlights } from '@/utils/documentUtils';
+import { buildChunkHighlights } from '@/utils/document-util';
import { useCallback, useMemo, useState } from 'react';
import { IHighlight } from 'react-pdf-highlighter';
import { useSelector } from 'umi';
diff --git a/web/src/pages/add-knowledge/components/knowledge-chunk/model.ts b/web/src/pages/add-knowledge/components/knowledge-chunk/model.ts
index c0e2cb3653..8cc127a908 100644
--- a/web/src/pages/add-knowledge/components/knowledge-chunk/model.ts
+++ b/web/src/pages/add-knowledge/components/knowledge-chunk/model.ts
@@ -3,7 +3,7 @@ import { IChunk, IKnowledgeFile } from '@/interfaces/database/knowledge';
import kbService from '@/services/knowledge-service';
import { message } from 'antd';
import { pick } from 'lodash';
-// import { delay } from '@/utils/storeUtil';
+// import { delay } from '@/utils/store-util';
import i18n from '@/locales/config';
import { DvaModel } from 'umi';
diff --git a/web/src/pages/add-knowledge/components/knowledge-file/hooks.ts b/web/src/pages/add-knowledge/components/knowledge-file/hooks.ts
index 8f9f068814..0f6c372cdb 100644
--- a/web/src/pages/add-knowledge/components/knowledge-file/hooks.ts
+++ b/web/src/pages/add-knowledge/components/knowledge-file/hooks.ts
@@ -14,7 +14,7 @@ import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
import { useFetchTenantInfo } from '@/hooks/user-setting-hooks';
import { Pagination } from '@/interfaces/common';
import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
-import { getUnSupportedFilesCount } from '@/utils/documentUtils';
+import { getUnSupportedFilesCount } from '@/utils/document-util';
import { PaginationProps, UploadFile } from 'antd';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useDispatch, useNavigate, useSelector } from 'umi';
diff --git a/web/src/pages/add-knowledge/components/knowledge-file/index.tsx b/web/src/pages/add-knowledge/components/knowledge-file/index.tsx
index 4683cacd7f..fc8e8c0c95 100644
--- a/web/src/pages/add-knowledge/components/knowledge-file/index.tsx
+++ b/web/src/pages/add-knowledge/components/knowledge-file/index.tsx
@@ -7,7 +7,7 @@ import {
import { useSetSelectedRecord } from '@/hooks/logic-hooks';
import { useSelectParserList } from '@/hooks/user-setting-hooks';
import { IKnowledgeFile } from '@/interfaces/database/knowledge';
-import { getExtension } from '@/utils/documentUtils';
+import { getExtension } from '@/utils/document-util';
import { Divider, Flex, Switch, Table, Typography } from 'antd';
import type { ColumnsType } from 'antd/es/table';
import { useTranslation } from 'react-i18next';
diff --git a/web/src/pages/add-knowledge/components/knowledge-file/parsing-action-cell/index.tsx b/web/src/pages/add-knowledge/components/knowledge-file/parsing-action-cell/index.tsx
index c0e41b5ba1..ad431ba4e6 100644
--- a/web/src/pages/add-knowledge/components/knowledge-file/parsing-action-cell/index.tsx
+++ b/web/src/pages/add-knowledge/components/knowledge-file/parsing-action-cell/index.tsx
@@ -2,7 +2,7 @@ import { useShowDeleteConfirm, useTranslate } from '@/hooks/common-hooks';
import { useRemoveDocument } from '@/hooks/document-hooks';
import { IKnowledgeFile } from '@/interfaces/database/knowledge';
import { api_host } from '@/utils/api';
-import { downloadFile } from '@/utils/fileUtil';
+import { downloadFile } from '@/utils/file-util';
import {
DeleteOutlined,
DownloadOutlined,
diff --git a/web/src/pages/add-knowledge/components/knowledge-setting/configuration.tsx b/web/src/pages/add-knowledge/components/knowledge-setting/configuration.tsx
index 1629007beb..3dd424d5c8 100644
--- a/web/src/pages/add-knowledge/components/knowledge-setting/configuration.tsx
+++ b/web/src/pages/add-knowledge/components/knowledge-setting/configuration.tsx
@@ -1,4 +1,4 @@
-import { normFile } from '@/utils/fileUtil';
+import { normFile } from '@/utils/file-util';
import { PlusOutlined } from '@ant-design/icons';
import { Button, Form, Input, Radio, Select, Space, Upload } from 'antd';
import {
diff --git a/web/src/pages/add-knowledge/components/knowledge-setting/hooks.ts b/web/src/pages/add-knowledge/components/knowledge-setting/hooks.ts
index 7a0fc39374..42cffc791d 100644
--- a/web/src/pages/add-knowledge/components/knowledge-setting/hooks.ts
+++ b/web/src/pages/add-knowledge/components/knowledge-setting/hooks.ts
@@ -11,7 +11,7 @@ import {
import {
getBase64FromUploadFileList,
getUploadFileListFromBase64,
-} from '@/utils/fileUtil';
+} from '@/utils/file-util';
import { useIsFetching } from '@tanstack/react-query';
import { Form, UploadFile } from 'antd';
import { FormInstance } from 'antd/lib';
diff --git a/web/src/pages/chat/chat-configuration-modal/assistant-setting.tsx b/web/src/pages/chat/chat-configuration-modal/assistant-setting.tsx
index cc407b4cc7..b99ce7b52e 100644
--- a/web/src/pages/chat/chat-configuration-modal/assistant-setting.tsx
+++ b/web/src/pages/chat/chat-configuration-modal/assistant-setting.tsx
@@ -95,7 +95,7 @@ const AssistantSetting = ({ show }: ISegmentedContentProps) => {
valuePropName="checked"
name={['prompt_config', 'self_rag']}
tooltip={t('selfRagTip')}
- initialValue={true}
+ initialValue={false}
>
diff --git a/web/src/pages/chat/chat-configuration-modal/index.tsx b/web/src/pages/chat/chat-configuration-modal/index.tsx
index 48400f4007..6e497f2c95 100644
--- a/web/src/pages/chat/chat-configuration-modal/index.tsx
+++ b/web/src/pages/chat/chat-configuration-modal/index.tsx
@@ -19,7 +19,7 @@ import {
useFetchLlmModelOnVisible,
useFetchModelId,
} from '@/hooks/logic-hooks';
-import { getBase64FromUploadFileList } from '@/utils/fileUtil';
+import { getBase64FromUploadFileList } from '@/utils/file-util';
import { removeUselessFieldsFromValues } from '@/utils/form';
import styles from './index.less';
diff --git a/web/src/pages/chat/markdown-content/index.tsx b/web/src/pages/chat/markdown-content/index.tsx
index 9b10e61922..6a82fe4333 100644
--- a/web/src/pages/chat/markdown-content/index.tsx
+++ b/web/src/pages/chat/markdown-content/index.tsx
@@ -3,7 +3,7 @@ import SvgIcon from '@/components/svg-icon';
import { useSelectFileThumbnails } from '@/hooks/knowledge-hooks';
import { IReference } from '@/interfaces/database/chat';
import { IChunk } from '@/interfaces/database/knowledge';
-import { getExtension } from '@/utils/documentUtils';
+import { getExtension } from '@/utils/document-util';
import { InfoCircleOutlined } from '@ant-design/icons';
import { Button, Flex, Popover, Space } from 'antd';
import DOMPurify from 'dompurify';
diff --git a/web/src/pages/file-manager/action-cell/index.tsx b/web/src/pages/file-manager/action-cell/index.tsx
index 2b28547499..56996428b9 100644
--- a/web/src/pages/file-manager/action-cell/index.tsx
+++ b/web/src/pages/file-manager/action-cell/index.tsx
@@ -1,7 +1,7 @@
import { useTranslate } from '@/hooks/common-hooks';
import { IFile } from '@/interfaces/database/file-manager';
import { api_host } from '@/utils/api';
-import { downloadFile } from '@/utils/fileUtil';
+import { downloadFile } from '@/utils/file-util';
import {
DeleteOutlined,
DownloadOutlined,
@@ -16,7 +16,7 @@ import NewDocumentLink from '@/components/new-document-link';
import {
getExtension,
isSupportedPreviewDocumentType,
-} from '@/utils/documentUtils';
+} from '@/utils/document-util';
import styles from './index.less';
interface IProps {
diff --git a/web/src/pages/file-manager/connect-to-knowledge-modal/index.tsx b/web/src/pages/file-manager/connect-to-knowledge-modal/index.tsx
index 9260c51df2..c06274a386 100644
--- a/web/src/pages/file-manager/connect-to-knowledge-modal/index.tsx
+++ b/web/src/pages/file-manager/connect-to-knowledge-modal/index.tsx
@@ -1,7 +1,7 @@
import { useTranslate } from '@/hooks/common-hooks';
import { useNextFetchKnowledgeList } from '@/hooks/knowledge-hooks';
import { IModalProps } from '@/interfaces/common';
-import { filterOptionsByInput } from '@/utils/commonUtil';
+import { filterOptionsByInput } from '@/utils/common-util';
import { Form, Modal, Select } from 'antd';
import { useEffect } from 'react';
diff --git a/web/src/pages/file-manager/index.tsx b/web/src/pages/file-manager/index.tsx
index db208933b6..0fa3f4abe7 100644
--- a/web/src/pages/file-manager/index.tsx
+++ b/web/src/pages/file-manager/index.tsx
@@ -18,8 +18,8 @@ import FileUploadModal from '@/components/file-upload-modal';
import RenameModal from '@/components/rename-modal';
import SvgIcon from '@/components/svg-icon';
import { useTranslate } from '@/hooks/common-hooks';
-import { formatNumberWithThousandsSeparator } from '@/utils/commonUtil';
-import { getExtension } from '@/utils/documentUtils';
+import { formatNumberWithThousandsSeparator } from '@/utils/common-util';
+import { getExtension } from '@/utils/document-util';
import ConnectToKnowledgeModal from './connect-to-knowledge-modal';
import FolderCreateModal from './folder-create-modal';
import styles from './index.less';
diff --git a/web/src/pages/user-setting/setting-profile/index.tsx b/web/src/pages/user-setting/setting-profile/index.tsx
index f338364d08..dd6b45b2b7 100644
--- a/web/src/pages/user-setting/setting-profile/index.tsx
+++ b/web/src/pages/user-setting/setting-profile/index.tsx
@@ -7,7 +7,7 @@ import {
getBase64FromUploadFileList,
getUploadFileListFromBase64,
normFile,
-} from '@/utils/fileUtil';
+} from '@/utils/file-util';
import { PlusOutlined } from '@ant-design/icons';
import {
Button,
diff --git a/web/src/pages/user-setting/setting-system/index.tsx b/web/src/pages/user-setting/setting-system/index.tsx
index 8f5fff0495..987d02557e 100644
--- a/web/src/pages/user-setting/setting-system/index.tsx
+++ b/web/src/pages/user-setting/setting-system/index.tsx
@@ -7,7 +7,7 @@ import lowerCase from 'lodash/lowerCase';
import upperFirst from 'lodash/upperFirst';
import { useEffect } from 'react';
-import { toFixed } from '@/utils/commonUtil';
+import { toFixed } from '@/utils/common-util';
import styles from './index.less';
const { Text } = Typography;
diff --git a/web/src/services/chat-service.ts b/web/src/services/chat-service.ts
index 496ed6754f..6d447242fd 100644
--- a/web/src/services/chat-service.ts
+++ b/web/src/services/chat-service.ts
@@ -1,5 +1,5 @@
import api from '@/utils/api';
-import registerServer from '@/utils/registerServer';
+import registerServer from '@/utils/register-server';
import request from '@/utils/request';
const {
diff --git a/web/src/services/file-manager-service.ts b/web/src/services/file-manager-service.ts
index 6f7165a90a..e4fcf63be9 100644
--- a/web/src/services/file-manager-service.ts
+++ b/web/src/services/file-manager-service.ts
@@ -1,5 +1,5 @@
import api from '@/utils/api';
-import registerServer from '@/utils/registerServer';
+import registerServer from '@/utils/register-server';
import request from '@/utils/request';
import pureRequest from 'axios';
diff --git a/web/src/services/flow-service.ts b/web/src/services/flow-service.ts
index 8308cf1f42..6bb8272e48 100644
--- a/web/src/services/flow-service.ts
+++ b/web/src/services/flow-service.ts
@@ -1,5 +1,5 @@
import api from '@/utils/api';
-import registerServer from '@/utils/registerServer';
+import registerServer from '@/utils/register-server';
import request from '@/utils/request';
const {
diff --git a/web/src/services/knowledge-service.ts b/web/src/services/knowledge-service.ts
index 32a63294d3..dffd552862 100644
--- a/web/src/services/knowledge-service.ts
+++ b/web/src/services/knowledge-service.ts
@@ -1,5 +1,5 @@
import api from '@/utils/api';
-import registerServer from '@/utils/registerServer';
+import registerServer from '@/utils/register-server';
import request from '@/utils/request';
import pureRequest from 'umi-request';
diff --git a/web/src/services/user-service.ts b/web/src/services/user-service.ts
index 71e857a922..322c6b2fec 100644
--- a/web/src/services/user-service.ts
+++ b/web/src/services/user-service.ts
@@ -1,5 +1,5 @@
import api from '@/utils/api';
-import registerServer from '@/utils/registerServer';
+import registerServer from '@/utils/register-server';
import request from '@/utils/request';
const {
diff --git a/web/src/utils/authorizationUtil.ts b/web/src/utils/authorization-util.ts
similarity index 97%
rename from web/src/utils/authorizationUtil.ts
rename to web/src/utils/authorization-util.ts
index c0d5bde254..60a4ad77c8 100644
--- a/web/src/utils/authorizationUtil.ts
+++ b/web/src/utils/authorization-util.ts
@@ -1,5 +1,5 @@
import { Authorization, Token, UserInfo } from '@/constants/authorization';
-import { getSearchValue } from './commonUtil';
+import { getSearchValue } from './common-util';
const KeySet = [Authorization, Token, UserInfo];
const storage = {
diff --git a/web/src/utils/commonUtil.ts b/web/src/utils/common-util.ts
similarity index 100%
rename from web/src/utils/commonUtil.ts
rename to web/src/utils/common-util.ts
diff --git a/web/src/utils/documentUtils.ts b/web/src/utils/document-util.ts
similarity index 100%
rename from web/src/utils/documentUtils.ts
rename to web/src/utils/document-util.ts
diff --git a/web/src/utils/domUtils.ts b/web/src/utils/dom-util.ts
similarity index 100%
rename from web/src/utils/domUtils.ts
rename to web/src/utils/dom-util.ts
diff --git a/web/src/utils/fileUtil.ts b/web/src/utils/file-util.ts
similarity index 100%
rename from web/src/utils/fileUtil.ts
rename to web/src/utils/file-util.ts
diff --git a/web/src/utils/hooks.ts b/web/src/utils/hooks.ts
deleted file mode 100644
index 2c7fb7f70e..0000000000
--- a/web/src/utils/hooks.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { useState } from 'react';
-
-export const usePagination = function (defaultPage: number, defaultPageSize: number, total: number) {
- const [page = 1, setPage] = useState(defaultPage);
- const [pageSize = 10, setPageSize] = useState(defaultPageSize);
- return {
- page,
- pageSize,
- count: total,
- setPage,
- setPageSize,
- nextPage: () => setPage(page + 1)
- };
-};
diff --git a/web/src/utils/registerServer.ts b/web/src/utils/register-server.ts
similarity index 96%
rename from web/src/utils/registerServer.ts
rename to web/src/utils/register-server.ts
index 8f03b26461..c2161411ac 100644
--- a/web/src/utils/registerServer.ts
+++ b/web/src/utils/register-server.ts
@@ -1,39 +1,39 @@
-import omit from 'lodash/omit';
-import { RequestMethod } from 'umi-request';
-
-type Service = Record<
- T,
- (params?: any, urlAppendix?: string) => any
->;
-
-const registerServer = (
- opt: Record,
- request: RequestMethod,
-) => {
- const server: Service = {} as Service;
- for (let key in opt) {
- server[key] = (params?: any, urlAppendix?: string) => {
- let url = opt[key].url;
- const requestOptions = opt[key];
- if (urlAppendix) {
- url = url + '/' + urlAppendix;
- }
- if (opt[key].method === 'post' || opt[key].method === 'POST') {
- return request(url, {
- method: opt[key].method,
- data: params,
- });
- }
-
- if (opt[key].method === 'get' || opt[key].method === 'GET') {
- return request.get(url, {
- ...omit(requestOptions, ['method', 'url']),
- params,
- });
- }
- };
- }
- return server;
-};
-
-export default registerServer;
+import omit from 'lodash/omit';
+import { RequestMethod } from 'umi-request';
+
+type Service = Record<
+ T,
+ (params?: any, urlAppendix?: string) => any
+>;
+
+const registerServer = (
+ opt: Record,
+ request: RequestMethod,
+) => {
+ const server: Service = {} as Service;
+ for (let key in opt) {
+ server[key] = (params?: any, urlAppendix?: string) => {
+ let url = opt[key].url;
+ const requestOptions = opt[key];
+ if (urlAppendix) {
+ url = url + '/' + urlAppendix;
+ }
+ if (opt[key].method === 'post' || opt[key].method === 'POST') {
+ return request(url, {
+ method: opt[key].method,
+ data: params,
+ });
+ }
+
+ if (opt[key].method === 'get' || opt[key].method === 'GET') {
+ return request.get(url, {
+ ...omit(requestOptions, ['method', 'url']),
+ params,
+ });
+ }
+ };
+ }
+ return server;
+};
+
+export default registerServer;
diff --git a/web/src/utils/request.ts b/web/src/utils/request.ts
index 89a3b505ca..6863c5ee3e 100644
--- a/web/src/utils/request.ts
+++ b/web/src/utils/request.ts
@@ -1,130 +1,132 @@
-import { Authorization } from '@/constants/authorization';
-import { ResponseType } from '@/interfaces/database/base';
-import i18n from '@/locales/config';
-import authorizationUtil, { getAuthorization } from '@/utils/authorizationUtil';
-import { message, notification } from 'antd';
-import { history } from 'umi';
-import { RequestMethod, extend } from 'umi-request';
-import { convertTheKeysOfTheObjectToSnake } from './commonUtil';
-
-const ABORT_REQUEST_ERR_MESSAGE = 'The user aborted a request.';
-
-const RetcodeMessage = {
- 200: i18n.t('message.200'),
- 201: i18n.t('message.201'),
- 202: i18n.t('message.202'),
- 204: i18n.t('message.204'),
- 400: i18n.t('message.400'),
- 401: i18n.t('message.401'),
- 403: i18n.t('message.403'),
- 404: i18n.t('message.404'),
- 406: i18n.t('message.406'),
- 410: i18n.t('message.410'),
- 422: i18n.t('message.422'),
- 500: i18n.t('message.500'),
- 502: i18n.t('message.502'),
- 503: i18n.t('message.503'),
- 504: i18n.t('message.504'),
-};
-type ResultCode =
- | 200
- | 201
- | 202
- | 204
- | 400
- | 401
- | 403
- | 404
- | 406
- | 410
- | 422
- | 500
- | 502
- | 503
- | 504;
-
-const errorHandler = (error: {
- response: Response;
- message: string;
-}): Response => {
- const { response } = error;
- if (error.message === ABORT_REQUEST_ERR_MESSAGE) {
- console.log('user abort request');
- } else {
- if (response && response.status) {
- const errorText =
- RetcodeMessage[response.status as ResultCode] || response.statusText;
- const { status, url } = response;
- notification.error({
- message: `${i18n.t('message.requestError')} ${status}: ${url}`,
- description: errorText,
- });
- } else if (!response) {
- notification.error({
- description: i18n.t('message.networkAnomalyDescription'),
- message: i18n.t('message.networkAnomaly'),
- });
- }
- }
- return response;
-};
-
-const request: RequestMethod = extend({
- errorHandler,
- timeout: 300000,
- getResponse: true,
-});
-
-request.interceptors.request.use((url: string, options: any) => {
- const data = convertTheKeysOfTheObjectToSnake(options.data);
- const params = convertTheKeysOfTheObjectToSnake(options.params);
-
- return {
- url,
- options: {
- ...options,
- data,
- params,
- headers: {
- ...(options.skipToken
- ? undefined
- : { [Authorization]: getAuthorization() }),
- ...options.headers,
- },
- interceptors: true,
- },
- };
-});
-
-request.interceptors.response.use(async (response: any, options) => {
- if (options.responseType === 'blob') {
- return response;
- }
- const data: ResponseType = await response.clone().json();
-
- if (data.retcode === 401 || data.retcode === 401) {
- notification.error({
- message: data.retmsg,
- description: data.retmsg,
- 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 {
- notification.error({
- message: `${i18n.t('message.hint')} : ${data.retcode}`,
- description: data.retmsg,
- duration: 3,
- });
- }
-
- return response;
- } else {
- return response;
- }
-});
-
-export default request;
+import { Authorization } from '@/constants/authorization';
+import { ResponseType } from '@/interfaces/database/base';
+import i18n from '@/locales/config';
+import authorizationUtil, {
+ getAuthorization,
+} from '@/utils/authorization-util';
+import { message, notification } from 'antd';
+import { history } from 'umi';
+import { RequestMethod, extend } from 'umi-request';
+import { convertTheKeysOfTheObjectToSnake } from './common-util';
+
+const ABORT_REQUEST_ERR_MESSAGE = 'The user aborted a request.';
+
+const RetcodeMessage = {
+ 200: i18n.t('message.200'),
+ 201: i18n.t('message.201'),
+ 202: i18n.t('message.202'),
+ 204: i18n.t('message.204'),
+ 400: i18n.t('message.400'),
+ 401: i18n.t('message.401'),
+ 403: i18n.t('message.403'),
+ 404: i18n.t('message.404'),
+ 406: i18n.t('message.406'),
+ 410: i18n.t('message.410'),
+ 422: i18n.t('message.422'),
+ 500: i18n.t('message.500'),
+ 502: i18n.t('message.502'),
+ 503: i18n.t('message.503'),
+ 504: i18n.t('message.504'),
+};
+type ResultCode =
+ | 200
+ | 201
+ | 202
+ | 204
+ | 400
+ | 401
+ | 403
+ | 404
+ | 406
+ | 410
+ | 422
+ | 500
+ | 502
+ | 503
+ | 504;
+
+const errorHandler = (error: {
+ response: Response;
+ message: string;
+}): Response => {
+ const { response } = error;
+ if (error.message === ABORT_REQUEST_ERR_MESSAGE) {
+ console.log('user abort request');
+ } else {
+ if (response && response.status) {
+ const errorText =
+ RetcodeMessage[response.status as ResultCode] || response.statusText;
+ const { status, url } = response;
+ notification.error({
+ message: `${i18n.t('message.requestError')} ${status}: ${url}`,
+ description: errorText,
+ });
+ } else if (!response) {
+ notification.error({
+ description: i18n.t('message.networkAnomalyDescription'),
+ message: i18n.t('message.networkAnomaly'),
+ });
+ }
+ }
+ return response;
+};
+
+const request: RequestMethod = extend({
+ errorHandler,
+ timeout: 300000,
+ getResponse: true,
+});
+
+request.interceptors.request.use((url: string, options: any) => {
+ const data = convertTheKeysOfTheObjectToSnake(options.data);
+ const params = convertTheKeysOfTheObjectToSnake(options.params);
+
+ return {
+ url,
+ options: {
+ ...options,
+ data,
+ params,
+ headers: {
+ ...(options.skipToken
+ ? undefined
+ : { [Authorization]: getAuthorization() }),
+ ...options.headers,
+ },
+ interceptors: true,
+ },
+ };
+});
+
+request.interceptors.response.use(async (response: any, options) => {
+ if (options.responseType === 'blob') {
+ return response;
+ }
+ const data: ResponseType = await response.clone().json();
+
+ if (data.retcode === 401 || data.retcode === 401) {
+ notification.error({
+ message: data.retmsg,
+ description: data.retmsg,
+ 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 {
+ notification.error({
+ message: `${i18n.t('message.hint')} : ${data.retcode}`,
+ description: data.retmsg,
+ duration: 3,
+ });
+ }
+
+ return response;
+ } else {
+ return response;
+ }
+});
+
+export default request;
diff --git a/web/src/utils/storeUtil.ts b/web/src/utils/store-util.ts
similarity index 100%
rename from web/src/utils/storeUtil.ts
rename to web/src/utils/store-util.ts