Redirect /hls/stream.m3u8 to IPFS playlist when available

When the local HLS playlist doesn't exist, check for IPFS playlist
CID in pending/completed run and redirect to the IPFS gateway.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-03 22:09:19 +00:00
parent fe6730ce72
commit 9096824444

View File

@@ -1079,6 +1079,26 @@ async def serve_hls_content(
else:
raise HTTPException(400, "Invalid file type")
# For playlist requests, check IPFS first (redirect to IPFS gateway)
if filename == "stream.m3u8" and not file_path.exists():
import database
from fastapi.responses import RedirectResponse
await database.init_db()
# Check pending run for IPFS playlist
pending = await database.get_pending_run(run_id)
if pending and pending.get("ipfs_playlist_cid"):
gateway = os.environ.get("IPFS_GATEWAY_URL", "https://ipfs.io/ipfs")
ipfs_url = f"{gateway}/{pending['ipfs_playlist_cid']}"
return RedirectResponse(url=ipfs_url, status_code=302)
# Check completed run cache
run = await database.get_run_cache(run_id)
if run and run.get("ipfs_playlist_cid"):
gateway = os.environ.get("IPFS_GATEWAY_URL", "https://ipfs.io/ipfs")
ipfs_url = f"{gateway}/{run['ipfs_playlist_cid']}"
return RedirectResponse(url=ipfs_url, status_code=302)
# Try local file first
if file_path.exists():
return FileResponse(