parent
7be349c937
commit
73dfcb6fb0
@ -364,15 +364,15 @@ const getWrite = (chat: any, reader: any, stream: boolean) => {
|
|||||||
let str = decoder.decode(value, { stream: true })
|
let str = decoder.decode(value, { stream: true })
|
||||||
// 这里解释一下 start 因为数据流返回流并不是按照后端chunk返回 我们希望得到的chunk是data:{xxx}\n\n 但是它获取到的可能是 data:{ -> xxx}\n\n 总而言之就是 fetch不能保证每个chunk都说以data:开始 \n\n结束
|
// 这里解释一下 start 因为数据流返回流并不是按照后端chunk返回 我们希望得到的chunk是data:{xxx}\n\n 但是它获取到的可能是 data:{ -> xxx}\n\n 总而言之就是 fetch不能保证每个chunk都说以data:开始 \n\n结束
|
||||||
tempResult += str
|
tempResult += str
|
||||||
if (tempResult.endsWith('\n\n')) {
|
const split = tempResult.match(/data:.*}\n\n/g)
|
||||||
str = tempResult
|
if (split) {
|
||||||
tempResult = ''
|
str = split.join('')
|
||||||
|
tempResult = tempResult.replace(str, '')
|
||||||
} else {
|
} else {
|
||||||
return reader.read().then(write_stream)
|
return reader.read().then(write_stream)
|
||||||
}
|
}
|
||||||
// 这里解释一下 end
|
// 这里解释一下 end
|
||||||
if (str && str.startsWith('data:')) {
|
if (str && str.startsWith('data:')) {
|
||||||
const split = str.match(/data:.*}\n\n/g)
|
|
||||||
if (split) {
|
if (split) {
|
||||||
for (const index in split) {
|
for (const index in split) {
|
||||||
const chunk = JSON?.parse(split[index].replace('data:', ''))
|
const chunk = JSON?.parse(split[index].replace('data:', ''))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user