### What problem does this PR solve? fix: Set the default value of Self RAG to false #1220 fix: Change all tool file names to kebab format ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)tags/v0.9.0
| import weekYear from 'dayjs/plugin/weekYear'; | import weekYear from 'dayjs/plugin/weekYear'; | ||||
| import weekday from 'dayjs/plugin/weekday'; | import weekday from 'dayjs/plugin/weekday'; | ||||
| import React, { ReactNode, useEffect, useState } from 'react'; | import React, { ReactNode, useEffect, useState } from 'react'; | ||||
| import storage from './utils/authorizationUtil'; | |||||
| import storage from './utils/authorization-util'; | |||||
| dayjs.extend(customParseFormat); | dayjs.extend(customParseFormat); | ||||
| dayjs.extend(advancedFormat); | dayjs.extend(advancedFormat); |
| import { useMemo } from 'react'; | import { useMemo } from 'react'; | ||||
| import MarkdownContent from '@/pages/chat/markdown-content'; | 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 { Avatar, Flex, List } from 'antd'; | ||||
| import NewDocumentLink from '../new-document-link'; | import NewDocumentLink from '../new-document-link'; | ||||
| import SvgIcon from '../svg-icon'; | import SvgIcon from '../svg-icon'; |
| import { | import { | ||||
| getExtension, | getExtension, | ||||
| isSupportedPreviewDocumentType, | isSupportedPreviewDocumentType, | ||||
| } from '@/utils/documentUtils'; | |||||
| } from '@/utils/document-util'; | |||||
| import React from 'react'; | import React from 'react'; | ||||
| interface IProps extends React.PropsWithChildren { | interface IProps extends React.PropsWithChildren { |
| import authorizationUtil from '@/utils/authorizationUtil'; | |||||
| import authorizationUtil from '@/utils/authorization-util'; | |||||
| import { message } from 'antd'; | import { message } from 'antd'; | ||||
| import { useEffect, useMemo, useState } from 'react'; | import { useEffect, useMemo, useState } from 'react'; | ||||
| import { useNavigate, useSearchParams } from 'umi'; | import { useNavigate, useSearchParams } from 'umi'; |
| import { IChunk, IKnowledgeFile } from '@/interfaces/database/knowledge'; | import { IChunk, IKnowledgeFile } from '@/interfaces/database/knowledge'; | ||||
| import { IChangeParserConfigRequestBody } from '@/interfaces/request/document'; | import { IChangeParserConfigRequestBody } from '@/interfaces/request/document'; | ||||
| import { api_host } from '@/utils/api'; | import { api_host } from '@/utils/api'; | ||||
| import { buildChunkHighlights } from '@/utils/documentUtils'; | |||||
| import { buildChunkHighlights } from '@/utils/document-util'; | |||||
| import { UploadFile } from 'antd'; | import { UploadFile } from 'antd'; | ||||
| import { useCallback, useMemo, useState } from 'react'; | import { useCallback, useMemo, useState } from 'react'; | ||||
| import { IHighlight } from 'react-pdf-highlighter'; | import { IHighlight } from 'react-pdf-highlighter'; |
| IAddLlmRequestBody, | IAddLlmRequestBody, | ||||
| IDeleteLlmRequestBody, | IDeleteLlmRequestBody, | ||||
| } from '@/interfaces/request/llm'; | } from '@/interfaces/request/llm'; | ||||
| import { sortLLmFactoryListBySpecifiedOrder } from '@/utils/commonUtil'; | |||||
| import { sortLLmFactoryListBySpecifiedOrder } from '@/utils/common-util'; | |||||
| import { useCallback, useEffect, useMemo } from 'react'; | import { useCallback, useEffect, useMemo } from 'react'; | ||||
| import { useDispatch, useSelector } from 'umi'; | import { useDispatch, useSelector } from 'umi'; | ||||
| import { IKnowledgeFile } from '@/interfaces/database/knowledge'; | import { IKnowledgeFile } from '@/interfaces/database/knowledge'; | ||||
| import { IChangeParserConfigRequestBody } from '@/interfaces/request/document'; | import { IChangeParserConfigRequestBody } from '@/interfaces/request/document'; | ||||
| import api from '@/utils/api'; | import api from '@/utils/api'; | ||||
| import { getAuthorization } from '@/utils/authorizationUtil'; | |||||
| import { getAuthorization } from '@/utils/authorization-util'; | |||||
| import { PaginationProps } from 'antd'; | import { PaginationProps } from 'antd'; | ||||
| import axios from 'axios'; | import axios from 'axios'; | ||||
| import { EventSourceParserStream } from 'eventsource-parser/stream'; | import { EventSourceParserStream } from 'eventsource-parser/stream'; |
| import { Authorization } from '@/constants/authorization'; | import { Authorization } from '@/constants/authorization'; | ||||
| import userService from '@/services/user-service'; | import userService from '@/services/user-service'; | ||||
| import authorizationUtil from '@/utils/authorizationUtil'; | |||||
| import authorizationUtil from '@/utils/authorization-util'; | |||||
| import { useMutation } from '@tanstack/react-query'; | import { useMutation } from '@tanstack/react-query'; | ||||
| import { message } from 'antd'; | import { message } from 'antd'; | ||||
| import { useTranslation } from 'react-i18next'; | import { useTranslation } from 'react-i18next'; |
| import { getOneNamespaceEffectsLoading } from '@/utils/storeUtil'; | |||||
| import { getOneNamespaceEffectsLoading } from '@/utils/store-util'; | |||||
| import { useSelector } from 'umi'; | import { useSelector } from 'umi'; | ||||
| // Get the loading status of given effects under a certain namespace | // Get the loading status of given effects under a certain namespace |
| import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks'; | import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks'; | ||||
| import { IChunk, IKnowledgeFile } from '@/interfaces/database/knowledge'; | 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 { useCallback, useMemo, useState } from 'react'; | ||||
| import { IHighlight } from 'react-pdf-highlighter'; | import { IHighlight } from 'react-pdf-highlighter'; | ||||
| import { useSelector } from 'umi'; | import { useSelector } from 'umi'; |
| import kbService from '@/services/knowledge-service'; | import kbService from '@/services/knowledge-service'; | ||||
| import { message } from 'antd'; | import { message } from 'antd'; | ||||
| import { pick } from 'lodash'; | import { pick } from 'lodash'; | ||||
| // import { delay } from '@/utils/storeUtil'; | |||||
| // import { delay } from '@/utils/store-util'; | |||||
| import i18n from '@/locales/config'; | import i18n from '@/locales/config'; | ||||
| import { DvaModel } from 'umi'; | import { DvaModel } from 'umi'; | ||||
| import { useFetchTenantInfo } from '@/hooks/user-setting-hooks'; | import { useFetchTenantInfo } from '@/hooks/user-setting-hooks'; | ||||
| import { Pagination } from '@/interfaces/common'; | import { Pagination } from '@/interfaces/common'; | ||||
| import { IChangeParserConfigRequestBody } from '@/interfaces/request/document'; | import { IChangeParserConfigRequestBody } from '@/interfaces/request/document'; | ||||
| import { getUnSupportedFilesCount } from '@/utils/documentUtils'; | |||||
| import { getUnSupportedFilesCount } from '@/utils/document-util'; | |||||
| import { PaginationProps, UploadFile } from 'antd'; | import { PaginationProps, UploadFile } from 'antd'; | ||||
| import { useCallback, useEffect, useMemo, useState } from 'react'; | import { useCallback, useEffect, useMemo, useState } from 'react'; | ||||
| import { useDispatch, useNavigate, useSelector } from 'umi'; | import { useDispatch, useNavigate, useSelector } from 'umi'; |
| import { useSetSelectedRecord } from '@/hooks/logic-hooks'; | import { useSetSelectedRecord } from '@/hooks/logic-hooks'; | ||||
| import { useSelectParserList } from '@/hooks/user-setting-hooks'; | import { useSelectParserList } from '@/hooks/user-setting-hooks'; | ||||
| import { IKnowledgeFile } from '@/interfaces/database/knowledge'; | 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 { Divider, Flex, Switch, Table, Typography } from 'antd'; | ||||
| import type { ColumnsType } from 'antd/es/table'; | import type { ColumnsType } from 'antd/es/table'; | ||||
| import { useTranslation } from 'react-i18next'; | import { useTranslation } from 'react-i18next'; |
| import { useRemoveDocument } from '@/hooks/document-hooks'; | import { useRemoveDocument } from '@/hooks/document-hooks'; | ||||
| import { IKnowledgeFile } from '@/interfaces/database/knowledge'; | import { IKnowledgeFile } from '@/interfaces/database/knowledge'; | ||||
| import { api_host } from '@/utils/api'; | import { api_host } from '@/utils/api'; | ||||
| import { downloadFile } from '@/utils/fileUtil'; | |||||
| import { downloadFile } from '@/utils/file-util'; | |||||
| import { | import { | ||||
| DeleteOutlined, | DeleteOutlined, | ||||
| DownloadOutlined, | DownloadOutlined, |
| import { normFile } from '@/utils/fileUtil'; | |||||
| import { normFile } from '@/utils/file-util'; | |||||
| import { PlusOutlined } from '@ant-design/icons'; | import { PlusOutlined } from '@ant-design/icons'; | ||||
| import { Button, Form, Input, Radio, Select, Space, Upload } from 'antd'; | import { Button, Form, Input, Radio, Select, Space, Upload } from 'antd'; | ||||
| import { | import { |
| import { | import { | ||||
| getBase64FromUploadFileList, | getBase64FromUploadFileList, | ||||
| getUploadFileListFromBase64, | getUploadFileListFromBase64, | ||||
| } from '@/utils/fileUtil'; | |||||
| } from '@/utils/file-util'; | |||||
| import { useIsFetching } from '@tanstack/react-query'; | import { useIsFetching } from '@tanstack/react-query'; | ||||
| import { Form, UploadFile } from 'antd'; | import { Form, UploadFile } from 'antd'; | ||||
| import { FormInstance } from 'antd/lib'; | import { FormInstance } from 'antd/lib'; |
| valuePropName="checked" | valuePropName="checked" | ||||
| name={['prompt_config', 'self_rag']} | name={['prompt_config', 'self_rag']} | ||||
| tooltip={t('selfRagTip')} | tooltip={t('selfRagTip')} | ||||
| initialValue={true} | |||||
| initialValue={false} | |||||
| > | > | ||||
| <Switch /> | <Switch /> | ||||
| </Form.Item> | </Form.Item> |
| useFetchLlmModelOnVisible, | useFetchLlmModelOnVisible, | ||||
| useFetchModelId, | useFetchModelId, | ||||
| } from '@/hooks/logic-hooks'; | } from '@/hooks/logic-hooks'; | ||||
| import { getBase64FromUploadFileList } from '@/utils/fileUtil'; | |||||
| import { getBase64FromUploadFileList } from '@/utils/file-util'; | |||||
| import { removeUselessFieldsFromValues } from '@/utils/form'; | import { removeUselessFieldsFromValues } from '@/utils/form'; | ||||
| import styles from './index.less'; | import styles from './index.less'; | ||||
| import { useSelectFileThumbnails } from '@/hooks/knowledge-hooks'; | import { useSelectFileThumbnails } from '@/hooks/knowledge-hooks'; | ||||
| import { IReference } from '@/interfaces/database/chat'; | import { IReference } from '@/interfaces/database/chat'; | ||||
| import { IChunk } from '@/interfaces/database/knowledge'; | import { IChunk } from '@/interfaces/database/knowledge'; | ||||
| import { getExtension } from '@/utils/documentUtils'; | |||||
| import { getExtension } from '@/utils/document-util'; | |||||
| import { InfoCircleOutlined } from '@ant-design/icons'; | import { InfoCircleOutlined } from '@ant-design/icons'; | ||||
| import { Button, Flex, Popover, Space } from 'antd'; | import { Button, Flex, Popover, Space } from 'antd'; | ||||
| import DOMPurify from 'dompurify'; | import DOMPurify from 'dompurify'; |
| import { useTranslate } from '@/hooks/common-hooks'; | import { useTranslate } from '@/hooks/common-hooks'; | ||||
| import { IFile } from '@/interfaces/database/file-manager'; | import { IFile } from '@/interfaces/database/file-manager'; | ||||
| import { api_host } from '@/utils/api'; | import { api_host } from '@/utils/api'; | ||||
| import { downloadFile } from '@/utils/fileUtil'; | |||||
| import { downloadFile } from '@/utils/file-util'; | |||||
| import { | import { | ||||
| DeleteOutlined, | DeleteOutlined, | ||||
| DownloadOutlined, | DownloadOutlined, | ||||
| import { | import { | ||||
| getExtension, | getExtension, | ||||
| isSupportedPreviewDocumentType, | isSupportedPreviewDocumentType, | ||||
| } from '@/utils/documentUtils'; | |||||
| } from '@/utils/document-util'; | |||||
| import styles from './index.less'; | import styles from './index.less'; | ||||
| interface IProps { | interface IProps { |
| import { useTranslate } from '@/hooks/common-hooks'; | import { useTranslate } from '@/hooks/common-hooks'; | ||||
| import { useNextFetchKnowledgeList } from '@/hooks/knowledge-hooks'; | import { useNextFetchKnowledgeList } from '@/hooks/knowledge-hooks'; | ||||
| import { IModalProps } from '@/interfaces/common'; | import { IModalProps } from '@/interfaces/common'; | ||||
| import { filterOptionsByInput } from '@/utils/commonUtil'; | |||||
| import { filterOptionsByInput } from '@/utils/common-util'; | |||||
| import { Form, Modal, Select } from 'antd'; | import { Form, Modal, Select } from 'antd'; | ||||
| import { useEffect } from 'react'; | import { useEffect } from 'react'; | ||||
| import RenameModal from '@/components/rename-modal'; | import RenameModal from '@/components/rename-modal'; | ||||
| import SvgIcon from '@/components/svg-icon'; | import SvgIcon from '@/components/svg-icon'; | ||||
| import { useTranslate } from '@/hooks/common-hooks'; | 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 ConnectToKnowledgeModal from './connect-to-knowledge-modal'; | ||||
| import FolderCreateModal from './folder-create-modal'; | import FolderCreateModal from './folder-create-modal'; | ||||
| import styles from './index.less'; | import styles from './index.less'; |
| getBase64FromUploadFileList, | getBase64FromUploadFileList, | ||||
| getUploadFileListFromBase64, | getUploadFileListFromBase64, | ||||
| normFile, | normFile, | ||||
| } from '@/utils/fileUtil'; | |||||
| } from '@/utils/file-util'; | |||||
| import { PlusOutlined } from '@ant-design/icons'; | import { PlusOutlined } from '@ant-design/icons'; | ||||
| import { | import { | ||||
| Button, | Button, |
| import upperFirst from 'lodash/upperFirst'; | import upperFirst from 'lodash/upperFirst'; | ||||
| import { useEffect } from 'react'; | import { useEffect } from 'react'; | ||||
| import { toFixed } from '@/utils/commonUtil'; | |||||
| import { toFixed } from '@/utils/common-util'; | |||||
| import styles from './index.less'; | import styles from './index.less'; | ||||
| const { Text } = Typography; | const { Text } = Typography; |
| import api from '@/utils/api'; | import api from '@/utils/api'; | ||||
| import registerServer from '@/utils/registerServer'; | |||||
| import registerServer from '@/utils/register-server'; | |||||
| import request from '@/utils/request'; | import request from '@/utils/request'; | ||||
| const { | const { |
| import api from '@/utils/api'; | import api from '@/utils/api'; | ||||
| import registerServer from '@/utils/registerServer'; | |||||
| import registerServer from '@/utils/register-server'; | |||||
| import request from '@/utils/request'; | import request from '@/utils/request'; | ||||
| import pureRequest from 'axios'; | import pureRequest from 'axios'; | ||||
| import api from '@/utils/api'; | import api from '@/utils/api'; | ||||
| import registerServer from '@/utils/registerServer'; | |||||
| import registerServer from '@/utils/register-server'; | |||||
| import request from '@/utils/request'; | import request from '@/utils/request'; | ||||
| const { | const { |
| import api from '@/utils/api'; | import api from '@/utils/api'; | ||||
| import registerServer from '@/utils/registerServer'; | |||||
| import registerServer from '@/utils/register-server'; | |||||
| import request from '@/utils/request'; | import request from '@/utils/request'; | ||||
| import pureRequest from 'umi-request'; | import pureRequest from 'umi-request'; | ||||
| import api from '@/utils/api'; | import api from '@/utils/api'; | ||||
| import registerServer from '@/utils/registerServer'; | |||||
| import registerServer from '@/utils/register-server'; | |||||
| import request from '@/utils/request'; | import request from '@/utils/request'; | ||||
| const { | const { |
| import { Authorization, Token, UserInfo } from '@/constants/authorization'; | import { Authorization, Token, UserInfo } from '@/constants/authorization'; | ||||
| import { getSearchValue } from './commonUtil'; | |||||
| import { getSearchValue } from './common-util'; | |||||
| const KeySet = [Authorization, Token, UserInfo]; | const KeySet = [Authorization, Token, UserInfo]; | ||||
| const storage = { | const storage = { |
| 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) | |||||
| }; | |||||
| }; |
| import omit from 'lodash/omit'; | |||||
| import { RequestMethod } from 'umi-request'; | |||||
| type Service<T extends string> = Record< | |||||
| T, | |||||
| (params?: any, urlAppendix?: string) => any | |||||
| >; | |||||
| const registerServer = <T extends string>( | |||||
| opt: Record<T, { url: string; method: string }>, | |||||
| request: RequestMethod, | |||||
| ) => { | |||||
| const server: Service<T> = {} as Service<T>; | |||||
| 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<T extends string> = Record< | |||||
| T, | |||||
| (params?: any, urlAppendix?: string) => any | |||||
| >; | |||||
| const registerServer = <T extends string>( | |||||
| opt: Record<T, { url: string; method: string }>, | |||||
| request: RequestMethod, | |||||
| ) => { | |||||
| const server: Service<T> = {} as Service<T>; | |||||
| 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 { 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; |