Files
mhdzumair 89dd0a00fc Implement new UserData management
Store UserData in redis if compress + encryption data length is more than 1000, or else directly setup in the url secret string. Replaces legacy encryption and decryption methods with an optimized `CryptoUtils` class supporting compression, improved encryption, and Redis-based storage.
2024-12-24 21:40:48 +05:30

37 lines
1.2 KiB
Python

from fastapi import APIRouter
from fastapi.responses import RedirectResponse
from db import schemas
from streaming_providers.premiumize.client import Premiumize
from utils import const
from utils.crypto import crypto_utils
router = APIRouter()
@router.get("/authorize")
async def authorize():
if not Premiumize.OAUTH_CLIENT_ID or not Premiumize.OAUTH_CLIENT_SECRET:
return {"error": "Premiumize OAuth not configured"}
async with Premiumize() as pm_client:
return RedirectResponse(
pm_client.get_authorization_url(), headers=const.NO_CACHE_HEADERS
)
@router.get("/oauth2_redirect")
async def oauth2_redirect(code: str):
async with Premiumize() as pm_client:
token_data = await pm_client.get_token(code)
token = pm_client.encode_token_data(token_data["access_token"])
user_data = schemas.UserData(
streaming_provider=schemas.StreamingProvider(
service="premiumize", token=token
)
)
encrypted_str = await crypto_utils.process_user_data(user_data)
return RedirectResponse(
f"/{encrypted_str}/configure", headers=const.NO_CACHE_HEADERS
)