Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/content-script/site-adapters/bilibili/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ export default {
const subtitleData = await subtitleResponse.json()
const subtitles = subtitleData.body

let subtitleContent = ''
for (let i = 0; i < subtitles.length; i++) {
if (i === subtitles.length - 1) subtitleContent += subtitles[i].content
else subtitleContent += subtitles[i].content + ','
}
const subtitleContent = subtitles
.map((s) => s.content)
.filter((c) => c != null)
.join(',')
Comment on lines +54 to +57
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation assumes that subtitles is always an array and that each element s is a valid object. If the API returns an unexpected response (e.g., subtitleData.body is missing or contains null entries), this code will throw a TypeError. Adding a fallback for subtitles and using optional chaining for s.content would make this more robust.

Suggested change
const subtitleContent = subtitles
.map((s) => s.content)
.filter((c) => c != null)
.join(',')
const subtitleContent = (subtitles || [])
.map((s) => s?.content)
.filter((c) => c != null)
.join(',')


return await cropText(
`You are an expert video summarizer. Create a comprehensive summary of the following Bilibili video in markdown format, ` +
Expand Down