Fix player crash: gate file polling on confirmed download completion
Never start polling until backend status==="complete" or video.is_downloaded is true, preventing the player from loading a partially-written file. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -697,24 +697,22 @@ export default function Watch() {
|
|||||||
.catch(() => { pollTimerRef.current = setTimeout(() => pollForFile(url), 1500); });
|
.catch(() => { pollTimerRef.current = setTimeout(() => pollForFile(url), 1500); });
|
||||||
}, [fileReady]);
|
}, [fileReady]);
|
||||||
|
|
||||||
|
// Only poll once the backend confirms the download is fully written.
|
||||||
|
// Polling before status==="complete" risks playing a partial file.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!dlStatus?.file_url || fileReady || !playRequested) return;
|
if (fileReady || !playRequested) return;
|
||||||
pollForFile(dlStatus.file_url);
|
const backendDone = dlStatus?.status === "complete" || !!video?.is_downloaded;
|
||||||
|
const fileUrl = dlStatus?.file_url ?? (video?.is_downloaded ? `/files/${youtubeVideoId}.mp4` : null);
|
||||||
|
if (!backendDone || !fileUrl) return;
|
||||||
|
pollForFile(fileUrl);
|
||||||
return () => clearTimeout(pollTimerRef.current);
|
return () => clearTimeout(pollTimerRef.current);
|
||||||
}, [dlStatus?.file_url, fileReady, pollForFile, playRequested]);
|
}, [playRequested, fileReady, dlStatus?.status, dlStatus?.file_url, video?.is_downloaded, youtubeVideoId, pollForFile]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!video?.is_downloaded || fileReady || !playRequested) return;
|
|
||||||
pollForFile(`/files/${youtubeVideoId}.mp4`);
|
|
||||||
}, [video?.is_downloaded, playRequested]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
||||||
|
|
||||||
const downloadMut = useMutation({
|
const downloadMut = useMutation({
|
||||||
mutationFn: () => createDownload(youtubeVideoId, selectedQuality),
|
mutationFn: () => createDownload(youtubeVideoId, selectedQuality),
|
||||||
onSuccess: (res) => {
|
onSuccess: (res) => {
|
||||||
const dl = res.data;
|
setDownloadId(res.data.id);
|
||||||
setDownloadId(dl.id);
|
|
||||||
refetchVideo();
|
refetchVideo();
|
||||||
if (dl.status === "complete" && dl.file_url) pollForFile(dl.file_url);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user