refactor(video): share R2 playback URL resolution and guard drift resync

- move resolveR2PlaybackUrl into lib/video-upload-validation.ts so the compare
  view and the main video page cannot drift apart
- validate the resolved URL with isPlayableVideoUrl before it reaches <video src>
- add a per-player cooldown so a follower that cannot keep up is not seeked
  every second, which would stutter rather than correct
This commit is contained in:
yusufipk
2026-07-25 16:48:39 +07:00
parent d830c9a386
commit 2bad0a249f
3 changed files with 65 additions and 35 deletions
+2 -12
View File
@@ -14,6 +14,7 @@ import { VideoPageError } from '@/components/video-page/video-page-error';
import { GuestNameGate } from '@/components/video-page/guest-name-gate';
import { useCommentMedia } from '@/components/video-page/hooks/use-comment-media';
import { validateAnnotationStrokes } from '@/lib/validation';
import { resolveR2PlaybackUrl } from '@/lib/video-upload-validation';
import { useVersionActions } from '@/components/video-page/hooks/use-version-actions';
import { useWatchProgress } from '@/components/video-page/hooks/use-watch-progress';
import { useVideoPlayer } from '@/components/video-page/hooks/use-video-player';
@@ -288,18 +289,7 @@ export function VideoPageContent({
return `https://${bunnyCdnHostname}/${activeVersion.videoId}/playlist.m3u8`;
}
if (activeVersion.providerId === 'r2') {
if (activeVersion.originalUrl.startsWith('/api/upload/video/')) {
return activeVersion.originalUrl;
}
if (activeVersion.originalUrl.startsWith('videos/')) {
const filename = activeVersion.originalUrl.slice('videos/'.length);
return `/api/upload/video/${filename}`;
}
if (activeVersion.videoId.startsWith('videos/')) {
const filename = activeVersion.videoId.slice('videos/'.length);
return `/api/upload/video/${filename}`;
}
return activeVersion.originalUrl;
return resolveR2PlaybackUrl(activeVersion);
}
try {
const url = new URL(activeVersion.originalUrl);