Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import time
|
|
5 |
import asyncio
|
6 |
from typing import Dict
|
7 |
import base64
|
8 |
-
import
|
9 |
|
10 |
app = FastAPI()
|
11 |
|
@@ -910,7 +910,10 @@ async def embed_video(url: str, thumbnail: str):
|
|
910 |
@app.get("/encrypted/{encrypted_url}")
|
911 |
async def handle_encrypted_url(encrypted_url: str, request: Request):
|
912 |
decrypted_url = decrypt_url(encrypted_url)
|
913 |
-
|
|
|
|
|
|
|
914 |
|
915 |
async def get_cookies() -> Dict[str, str]:
|
916 |
try:
|
@@ -963,11 +966,24 @@ async def retry_upload(upload_url: str, file_content: bytes, content_type: str,
|
|
963 |
print(f"Error during upload: {e}")
|
964 |
|
965 |
await asyncio.sleep(delay)
|
966 |
-
delay = min(delay * 2, 60)
|
967 |
|
968 |
return False
|
969 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
970 |
def decrypt_url(encrypted_url: str) -> str:
|
971 |
-
|
972 |
-
|
973 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
import asyncio
|
6 |
from typing import Dict
|
7 |
import base64
|
8 |
+
import secrets
|
9 |
|
10 |
app = FastAPI()
|
11 |
|
|
|
910 |
@app.get("/encrypted/{encrypted_url}")
|
911 |
async def handle_encrypted_url(encrypted_url: str, request: Request):
|
912 |
decrypted_url = decrypt_url(encrypted_url)
|
913 |
+
if '/pbxt/' not in decrypted_url:
|
914 |
+
return JSONResponse(content={"error": "Invalid encrypted URL"}, status_code=400)
|
915 |
+
path = decrypted_url.split('/pbxt/')[1]
|
916 |
+
return await handle_video_stream(path, request)
|
917 |
|
918 |
async def get_cookies() -> Dict[str, str]:
|
919 |
try:
|
|
|
966 |
print(f"Error during upload: {e}")
|
967 |
|
968 |
await asyncio.sleep(delay)
|
969 |
+
delay = min(delay * 2, 60) # Exponential backoff, capped at 60 seconds
|
970 |
|
971 |
return False
|
972 |
|
973 |
+
# Generate a secure secret key
|
974 |
+
SECRET_KEY = secrets.token_urlsafe(32)
|
975 |
+
|
976 |
+
def encrypt_url(url: str) -> str:
|
977 |
+
encoded = base64.urlsafe_b64encode(url.encode()).decode()
|
978 |
+
return encoded[::-1] # Simple reversal for obfuscation
|
979 |
+
|
980 |
def decrypt_url(encrypted_url: str) -> str:
|
981 |
+
try:
|
982 |
+
decoded = base64.urlsafe_b64decode(encrypted_url[::-1]).decode()
|
983 |
+
return decoded
|
984 |
+
except:
|
985 |
+
return ""
|
986 |
+
|
987 |
+
if __name__ == "__main__":
|
988 |
+
import uvicorn
|
989 |
+
uvicorn.run(app, host="0.0.0.0", port=7820)
|