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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user