Skip to content

Commit 728f761

Browse files
committed
fix: danmaku 404 causing the video to fail to load
1 parent d19478f commit 728f761

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

  • src/renderer/src/components/modules/player/loading

src/renderer/src/components/modules/player/loading/hooks.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,15 @@ export const useDanmakuData = () => {
243243
},
244244
enabled: !!episodeId,
245245
refetchOnMount: false,
246+
retry: (failureCount: number, error: any) => {
247+
// 对于 404 等客户端错误,不重试
248+
if (error?.status === 404) {
249+
return false
250+
}
251+
// 其他错误最多重试 2 次
252+
return failureCount < 2
253+
},
254+
retryDelay: 1000,
246255
})) ?? []),
247256
{
248257
queryKey: [apiClient.comment.Commentkeys.getDanmu, episodeId],
@@ -303,13 +312,29 @@ export const useDanmakuData = () => {
303312
return [dandanplayDanmakuData, ...manualResult]
304313
}
305314

306-
// 官方弹幕库和第三方弹幕库都加载成功后,返回所有弹幕数据
315+
// 检查所有查询的完成状态(成功或最终失败)
316+
const dandanplayQuery = results.at(-2)
317+
const dandanplaySettled = dandanplayResult !== undefined || (dandanplayQuery?.isError && !dandanplayQuery?.isFetching)
318+
319+
const allThirdPartyQueriesSettled = thirdPartyResult.every(
320+
(result) => result.data !== undefined || (result.isError && !result.isFetching)
321+
)
322+
323+
// 官方弹幕库和第三方弹幕库都加载完成后,返回所有可用弹幕数据
307324
if (
308325
!onlyLoadDandanplayDanmaku &&
309-
results.every((result) => result.data !== undefined) &&
326+
dandanplaySettled &&
327+
allThirdPartyQueriesSettled &&
310328
thirdPartyResult.length === thirdPartyDanmakuUrlData.length
311329
) {
312-
return [dandanplayDanmakuData, ...thirdPartyDanmakuData, ...manualResult]
330+
// 只包含成功获取到数据的弹幕
331+
const availableDanmaku: DB_Danmaku[] = []
332+
if (dandanplayDanmakuData.content) {
333+
availableDanmaku.push(dandanplayDanmakuData)
334+
}
335+
const successfulThirdPartyData = thirdPartyDanmakuData.filter(item => item.content !== undefined)
336+
availableDanmaku.push(...successfulThirdPartyData, ...manualResult)
337+
return availableDanmaku
313338
}
314339

315340
// // 未匹配弹幕库,只加载用户手动导入弹幕
@@ -446,4 +471,4 @@ export const useLoadingHistoricalAnime = () => {
446471
setProgress(LoadingStatus.IMPORT_VIDEO)
447472
}
448473
}, [hash])
449-
}
474+
}

0 commit comments

Comments
 (0)