mirror of
https://github.com/wassname/chatGPTBox.git
synced 2026-07-13 02:42:02 +08:00
fix: sse json error
This commit is contained in:
+13
-7
@@ -22,13 +22,19 @@ export async function fetchSSE(resource, options) {
|
||||
if (!str.startsWith('{') && !str.startsWith('"{')) {
|
||||
parser.feed(str)
|
||||
} else {
|
||||
const formattedStr =
|
||||
'data: ' +
|
||||
JSON.stringify(
|
||||
JSON.parse(str.replace(/^"|"$/g, '').replaceAll('\\"', '"').replaceAll('\\\\u', '\\u')),
|
||||
).replaceAll('\\\\n', '\\n') +
|
||||
'\n\ndata: [DONE]\n\n'
|
||||
parser.feed(formattedStr)
|
||||
try {
|
||||
const formattedData = JSON.parse(
|
||||
str
|
||||
.replace(/^"|"$/g, '')
|
||||
.replaceAll('\\"', '"')
|
||||
.replaceAll('\\\\u', '\\u')
|
||||
.replaceAll('\\\\n', '\\n'),
|
||||
)
|
||||
const formattedStr = 'data: ' + JSON.stringify(formattedData) + '\n\ndata: [DONE]\n\n'
|
||||
parser.feed(formattedStr)
|
||||
} catch (error) {
|
||||
console.debug('json error', error)
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasStarted) {
|
||||
|
||||
Reference in New Issue
Block a user