4.8.1 test-fix (#1561)

This commit is contained in:
Archer
2024-05-22 18:49:39 +08:00
committed by GitHub
parent 87e4afe89b
commit b1aafde7c9
65 changed files with 1245 additions and 293 deletions

View File

@@ -2,7 +2,6 @@ import { SseResponseEventEnum } from '@fastgpt/global/core/workflow/runtime/cons
import { getErrText } from '@fastgpt/global/common/error/utils';
import type { ChatHistoryItemResType } from '@fastgpt/global/core/chat/type.d';
import type { StartChatFnProps } from '@/components/ChatBox/type.d';
import { getToken } from '@/web/support/user/auth';
import { DispatchNodeResponseKeyEnum } from '@fastgpt/global/core/workflow/runtime/constants';
import dayjs from 'dayjs';
import {
@@ -117,8 +116,7 @@ export const streamFetch = ({
const requestData = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
token: getToken()
'Content-Type': 'application/json'
},
signal: abortCtrl.signal,
body: JSON.stringify({

View File

@@ -4,7 +4,7 @@ import axios, {
AxiosResponse,
AxiosProgressEvent
} from 'axios';
import { clearToken, getToken } from '@/web/support/user/auth';
import { clearToken } from '@/web/support/user/auth';
import { TOKEN_ERROR_CODE } from '@fastgpt/global/common/error/errorCode';
import { TeamErrEnum } from '@fastgpt/global/common/error/code/team';
import { useSystemStore } from '../system/useSystemStore';
@@ -15,6 +15,7 @@ interface ConfigType {
onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
cancelToken?: AbortController;
maxQuantity?: number;
withCredentials?: boolean;
}
interface ResponseDataType {
code: number;
@@ -61,7 +62,6 @@ function requestFinish({ url }: { url: string }) {
*/
function startInterceptors(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig {
if (config.headers) {
config.headers.token = getToken();
}
return config;
@@ -138,7 +138,7 @@ instance.interceptors.response.use(responseSuccess, (err) => Promise.reject(err)
function request(
url: string,
data: any,
{ cancelToken, maxQuantity, ...config }: ConfigType,
{ cancelToken, maxQuantity, withCredentials, ...config }: ConfigType,
method: Method
): any {
/* 去空 */
@@ -158,6 +158,7 @@ function request(
data: ['POST', 'PUT'].includes(method) ? data : null,
params: !['POST', 'PUT'].includes(method) ? data : null,
signal: cancelToken?.signal,
withCredentials,
...config // 用户自定义配置,可以覆盖前面的配置
})
.then((res) => checkRes(res.data))

View File

@@ -1,31 +0,0 @@
import { getToken } from '@/web/support/user/auth';
import { hasHttps } from '@fastgpt/web/common/system/utils';
export const xmlDownloadFetch = async ({ url, filename }: { url: string; filename: string }) => {
if (hasHttps()) {
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
} else {
const response = await fetch(url, {
headers: {
token: `${getToken()}`
}
});
if (!response.ok) throw new Error('Network response was not ok.');
const blob = await response.blob();
const downloadUrl = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none'; // 隐藏<a>元素
a.href = downloadUrl;
a.download = filename;
document.body.appendChild(a);
a.click(); // 模拟用户点击
document.body.removeChild(a);
window.URL.revokeObjectURL(downloadUrl); // 清理生成的URL
}
};

View File

@@ -0,0 +1,8 @@
export const downloadFetch = async ({ url, filename }: { url: string; filename: string }) => {
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
};

View File

@@ -5,7 +5,6 @@ import type { AppTTSConfigType } from '@fastgpt/global/core/app/type.d';
import { TTSTypeEnum } from '@/web/core/app/constants';
import { useTranslation } from 'next-i18next';
import type { OutLinkChatAuthProps } from '@fastgpt/global/support/permission/chat.d';
import { getToken } from '@/web/support/user/auth';
import { useMount } from 'ahooks';
const contentType = 'audio/mpeg';
@@ -41,8 +40,7 @@ export const useAudioPlay = (props?: OutLinkChatAuthProps & { ttsConfig?: AppTTS
const response = await fetch('/api/core/chat/item/getSpeech', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
token: getToken()
'Content-Type': 'application/json'
},
signal: audioController.current.signal,
body: JSON.stringify({