mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-13 09:49:02 +08:00
fix: safari can not in (#1590)
This commit is contained in:
parent
778cfb37a2
commit
d6a6697891
4
web/global.d.ts
vendored
4
web/global.d.ts
vendored
@ -1,5 +1,3 @@
|
|||||||
declare module 'lamejs';
|
declare module 'lamejs';
|
||||||
declare module 'react-18-input-autosize';
|
declare module 'react-18-input-autosize';
|
||||||
declare module 'fetch-readablestream' {
|
|
||||||
export default function fetchReadableStream(url: string, options?: RequestInit): Promise<Response>
|
|
||||||
}
|
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
"echarts": "^5.4.1",
|
"echarts": "^5.4.1",
|
||||||
"echarts-for-react": "^3.0.2",
|
"echarts-for-react": "^3.0.2",
|
||||||
"emoji-mart": "^5.5.2",
|
"emoji-mart": "^5.5.2",
|
||||||
"fetch-readablestream": "^0.2.0",
|
|
||||||
"i18next": "^22.4.13",
|
"i18next": "^22.4.13",
|
||||||
"i18next-resources-to-backend": "^1.1.3",
|
"i18next-resources-to-backend": "^1.1.3",
|
||||||
"immer": "^9.0.19",
|
"immer": "^9.0.19",
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
import fetchStream from 'fetch-readablestream'
|
|
||||||
import { API_PREFIX, IS_CE_EDITION, PUBLIC_API_PREFIX } from '@/config'
|
import { API_PREFIX, IS_CE_EDITION, PUBLIC_API_PREFIX } from '@/config'
|
||||||
import Toast from '@/app/components/base/toast'
|
import Toast from '@/app/components/base/toast'
|
||||||
import type { MessageEnd, MessageReplace, ThoughtItem } from '@/app/components/app/chat/type'
|
import type { MessageEnd, MessageReplace, ThoughtItem } from '@/app/components/app/chat/type'
|
||||||
import { isSupportNativeFetchStream } from '@/utils/stream'
|
|
||||||
|
|
||||||
const TIME_OUT = 100000
|
const TIME_OUT = 100000
|
||||||
const supportNativeFetchStream = isSupportNativeFetchStream()
|
|
||||||
|
|
||||||
const ContentType = {
|
const ContentType = {
|
||||||
json: 'application/json',
|
json: 'application/json',
|
||||||
@ -223,9 +220,6 @@ const baseFetch = <T>(
|
|||||||
if (body && bodyStringify)
|
if (body && bodyStringify)
|
||||||
options.body = JSON.stringify(body)
|
options.body = JSON.stringify(body)
|
||||||
|
|
||||||
// for those do not support native fetch stream, we use fetch-readablestream as polyfill
|
|
||||||
const doFetch = supportNativeFetchStream ? globalThis.fetch : fetchStream
|
|
||||||
|
|
||||||
// Handle timeout
|
// Handle timeout
|
||||||
return Promise.race([
|
return Promise.race([
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
@ -234,7 +228,7 @@ const baseFetch = <T>(
|
|||||||
}, TIME_OUT)
|
}, TIME_OUT)
|
||||||
}),
|
}),
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
doFetch(urlWithPrefix, options as RequestInit)
|
globalThis.fetch(urlWithPrefix, options as RequestInit)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const resClone = res.clone()
|
const resClone = res.clone()
|
||||||
// Error handler
|
// Error handler
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
// https://developer.chrome.com/articles/fetch-streaming-requests/#feature-detection
|
|
||||||
export const isSupportNativeFetchStream = () => {
|
|
||||||
const supportsRequestStreams = (() => {
|
|
||||||
let duplexAccessed = false
|
|
||||||
|
|
||||||
const params = {
|
|
||||||
body: new ReadableStream(),
|
|
||||||
method: 'POST',
|
|
||||||
get duplex() {
|
|
||||||
duplexAccessed = true
|
|
||||||
return 'half'
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
const hasContentType = new Request('', params).headers.has('Content-Type')
|
|
||||||
|
|
||||||
return duplexAccessed && !hasContentType
|
|
||||||
})()
|
|
||||||
|
|
||||||
return supportsRequestStreams
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user