Skip to content

Commit ada5dbf

Browse files
committed
fix: sse json error
1 parent 09f897f commit ada5dbf

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/content-script/site-adapters/youtube/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default {
5454

5555
return cropText(
5656
`Provide a structured summary of the following video in markdown format, focusing on key takeaways and crucial information, and ensuring to include the video title. The summary should be easy to read and concise, yet comprehensive.` +
57-
`The video title is "${title}". The subtitle content is as follows:\n${subtitleContent}`,
57+
`The video title is "${title}". The subtitle content is as follows:\n${subtitleContent}`,
5858
)
5959
} catch (e) {
6060
console.log(e)

src/utils/fetch-sse.mjs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,19 @@ export async function fetchSSE(resource, options) {
2222
if (!str.startsWith('{') && !str.startsWith('"{')) {
2323
parser.feed(str)
2424
} else {
25-
const formattedStr =
26-
'data: ' +
27-
JSON.stringify(
28-
JSON.parse(str.replace(/^"|"$/g, '').replaceAll('\\"', '"').replaceAll('\\\\u', '\\u')),
29-
).replaceAll('\\\\n', '\\n') +
30-
'\n\ndata: [DONE]\n\n'
31-
parser.feed(formattedStr)
25+
try {
26+
const formattedData = JSON.parse(
27+
str
28+
.replace(/^"|"$/g, '')
29+
.replaceAll('\\"', '"')
30+
.replaceAll('\\\\u', '\\u')
31+
.replaceAll('\\\\n', '\\n'),
32+
)
33+
const formattedStr = 'data: ' + JSON.stringify(formattedData) + '\n\ndata: [DONE]\n\n'
34+
parser.feed(formattedStr)
35+
} catch (error) {
36+
console.debug('json error', error)
37+
}
3238
}
3339

3440
if (!hasStarted) {

0 commit comments

Comments
 (0)