Add stream_replays table, related schema, and API endpoints for managing stream replays

This commit is contained in:
Nikita
2025-12-23 23:20:22 -08:00
parent 1bb0450d02
commit 7f6f7d2f37
9 changed files with 643 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ import {
getSpotifyNowPlaying,
type SpotifyNowPlayingResponse,
} from "@/lib/spotify/now-playing"
import { getStreamStatus } from "@/lib/stream/status"
export const Route = createFileRoute("/$username")({
ssr: false,
@@ -56,6 +57,7 @@ function StreamPage() {
)
const [nowPlayingLoading, setNowPlayingLoading] = useState(false)
const [nowPlayingError, setNowPlayingError] = useState(false)
const [streamLive, setStreamLive] = useState(false)
useEffect(() => {
let isActive = true
@@ -118,6 +120,33 @@ function StreamPage() {
}
}, [username])
// Poll stream status for nikiv from nikiv.dev/api/stream-status
useEffect(() => {
if (username !== "nikiv") {
return
}
let isActive = true
const fetchStatus = async () => {
const status = await getStreamStatus()
if (isActive) {
setStreamLive(status.isLive)
}
}
// Fetch immediately
fetchStatus()
// Poll every 10 seconds
const interval = setInterval(fetchStatus, 10000)
return () => {
isActive = false
clearInterval(interval)
}
}, [username])
const stream = data?.stream ?? null
const playback = stream?.playback ?? null
const fallbackPlayback = stream?.hls_url
@@ -208,9 +237,11 @@ function StreamPage() {
}
}, [activePlayback?.type, stream?.hls_url])
// For nikiv, use streamLive from the polled API status
// For other users, use stream?.is_live from the database
const isLiveStatus = username === "nikiv" ? streamLive : Boolean(stream?.is_live)
const isActuallyLive =
Boolean(stream?.is_live) &&
(activePlayback?.type !== "hls" || hlsLive !== false)
isLiveStatus && (activePlayback?.type !== "hls" || hlsLive !== false)
const shouldFetchSpotify = username === "nikiv" && !isActuallyLive
useEffect(() => {