Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -881,13 +881,18 @@ async def handle_video_stream(path: str, request: Request):
|
|
881 |
|
882 |
return StreamingResponse(generate(), status_code=response.status_code, headers=headers)
|
883 |
|
884 |
-
@app.get("/
|
885 |
async def handle_encrypted_stream(encrypted_data: str, request: Request):
|
886 |
try:
|
887 |
browser_info = request.headers.get('User-Agent', '') + request.headers.get('Accept-Language', '') + str(request.client.host)
|
888 |
-
key = hashlib.sha256(browser_info.encode()).hexdigest()[:32]
|
889 |
-
|
890 |
-
|
|
|
|
|
|
|
|
|
|
|
891 |
|
892 |
if not decrypted_url.startswith('/rbxg/'):
|
893 |
raise ValueError("Invalid decrypted URL")
|
@@ -989,7 +994,7 @@ async def retry_upload(upload_url: str, file_content: bytes, content_type: str,
|
|
989 |
print(f"Error during upload: {e}")
|
990 |
|
991 |
await asyncio.sleep(delay)
|
992 |
-
delay = min(delay * 2, 60)
|
993 |
|
994 |
return False
|
995 |
|
|
|
881 |
|
882 |
return StreamingResponse(generate(), status_code=response.status_code, headers=headers)
|
883 |
|
884 |
+
@app.get("/e/{encrypted_data}")
|
885 |
async def handle_encrypted_stream(encrypted_data: str, request: Request):
|
886 |
try:
|
887 |
browser_info = request.headers.get('User-Agent', '') + request.headers.get('Accept-Language', '') + str(request.client.host)
|
888 |
+
key = hashlib.sha256(browser_info.encode()).hexdigest()[:32]
|
889 |
+
|
890 |
+
encrypted_bytes = base64.b64decode(encrypted_data)
|
891 |
+
iv = encrypted_bytes[:16]
|
892 |
+
ciphertext = encrypted_bytes[16:]
|
893 |
+
|
894 |
+
cipher = Fernet(base64.urlsafe_b64encode(key.encode()))
|
895 |
+
decrypted_url = cipher.decrypt(base64.urlsafe_b64encode(iv + ciphertext)).decode()
|
896 |
|
897 |
if not decrypted_url.startswith('/rbxg/'):
|
898 |
raise ValueError("Invalid decrypted URL")
|
|
|
994 |
print(f"Error during upload: {e}")
|
995 |
|
996 |
await asyncio.sleep(delay)
|
997 |
+
delay = min(delay * 2, 60) # Exponential backoff, capped at 60 seconds
|
998 |
|
999 |
return False
|
1000 |
|