Heretic Webdl -

# Remove stale timestamps timestamps = [ts for ts in _rate_limiter[ip] if ts > window_start] _rate_limiter[ip] = timestamps

CMD ["gunicorn", "-k", "uvicorn

from .downloader import stream_remote_file from .config import settings heretic webdl

async with httpx.AsyncClient(follow_redirects=True, timeout=30) as client: try: # `stream=True` gives us an async iterator over the body async with client.stream("GET", url) as resp: # Basic sanity checks if resp.status_code != 200: raise HTTPException( status_code=status.HTTP_502_BAD_GATEWAY, detail=f"Remote server returned resp.status_code", ) # Remove stale timestamps timestamps = [ts for

# 4️⃣ (optional) set env vars in a .env file cp .env.example .env # edit .env as needed detail=f"Remote server returned resp.status_code"

class Settings: # ---- security / abuse limits ------------------------------------------------- MAX_CONTENT_LENGTH = int(os.getenv("MAX_CONTENT_LENGTH", "104857600")) # 100 MiB # Optional whitelist (comma‑separated). If empty → allow any domain. WHITELISTED_DOMAINS = set( filter(None, os.getenv("WHITELISTED_DOMAINS", "").split(",")) ) # Rate limiting – simple token bucket stored in memory (good enough for free tier) RATE_LIMIT = int(os.getenv("RATE_LIMIT", "10")) # requests per minute per IP