add user IP to RealDebrid POST requests

This commit is contained in:
mhdzumair
2024-04-21 20:25:33 +05:30
parent be1c14069d
commit 59d04f1475
5 changed files with 51 additions and 19 deletions
+1 -17
View File
@@ -11,23 +11,7 @@ from starlette.routing import Match
from db.config import settings
from db.schemas import UserData
from utils import crypto, const
def get_client_ip(request: Request) -> str | None:
"""
Extract the client's real IP address from the request headers or fallback to the client host.
"""
x_forwarded_for = request.headers.get("X-Forwarded-For")
if x_forwarded_for:
# In some cases, this header can contain multiple IPs
# separated by commas.
# The first one is the original client's IP.
return x_forwarded_for.split(",")[0].strip()
# Fallback to X-Real-IP if X-Forwarded-For is not available
x_real_ip = request.headers.get("X-Real-IP")
if x_real_ip:
return x_real_ip
return request.client.host if request.client else "Unknown"
from utils.network import get_client_ip
async def find_route_handler(app, request: Request) -> Optional[Callable]: