diff --git a/app/routers/runs.py b/app/routers/runs.py index 94a4fce..d462059 100644 --- a/app/routers/runs.py +++ b/app/routers/runs.py @@ -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(