diff --git a/lnbits/extensions/jukebox/crud.py b/lnbits/extensions/jukebox/crud.py index 9d6548b6e..fe710f601 100644 --- a/lnbits/extensions/jukebox/crud.py +++ b/lnbits/extensions/jukebox/crud.py @@ -77,7 +77,7 @@ async def delete_jukebox(juke_id: str): #####################################PAYMENTS -async def create_jukebox_payment(data: CreateJukeboxPayment) -> JukeboxPayment: +async def create_jukebox_payment(data: CreateJukeboxPayment) -> CreateJukeboxPayment: await db.execute( """ INSERT INTO jukebox.jukebox_payment (payment_hash, juke_id, song_id, paid) @@ -87,7 +87,7 @@ async def create_jukebox_payment(data: CreateJukeboxPayment) -> JukeboxPayment: ) jukebox_payment = await get_jukebox_payment(data.payment_hash) assert jukebox_payment, "Newly created Jukebox Payment couldn't be retrieved" - return jukebox_payment + return data async def update_jukebox_payment( diff --git a/lnbits/extensions/jukebox/models.py b/lnbits/extensions/jukebox/models.py index 70cf65230..507504f42 100644 --- a/lnbits/extensions/jukebox/models.py +++ b/lnbits/extensions/jukebox/models.py @@ -1,6 +1,7 @@ -from fastapi.param_functions import Query +from typing import Optional + +from fastapi import Query from pydantic import BaseModel -from pydantic.main import BaseModel class CreateJukeLinkData(BaseModel): @@ -21,13 +22,13 @@ class Jukebox(BaseModel): user: str title: str wallet: str - inkey: str + inkey: Optional[str] sp_user: str sp_secret: str - sp_access_token: str - sp_refresh_token: str - sp_device: str - sp_playlists: str + sp_access_token: Optional[str] + sp_refresh_token: Optional[str] + sp_device: Optional[str] + sp_playlists: Optional[str] price: int profit: int diff --git a/lnbits/extensions/jukebox/views.py b/lnbits/extensions/jukebox/views.py index 2220da08a..e1c55449e 100644 --- a/lnbits/extensions/jukebox/views.py +++ b/lnbits/extensions/jukebox/views.py @@ -31,6 +31,8 @@ async def connect_to_jukebox(request: Request, juke_id): ) devices = await api_get_jukebox_device_check(juke_id) deviceConnected = False + assert jukebox.sp_device + assert jukebox.sp_playlists for device in devices["devices"]: if device["id"] == jukebox.sp_device.split("-")[1]: deviceConnected = True diff --git a/lnbits/extensions/jukebox/views_api.py b/lnbits/extensions/jukebox/views_api.py index 1847ca50d..0cca8fc85 100644 --- a/lnbits/extensions/jukebox/views_api.py +++ b/lnbits/extensions/jukebox/views_api.py @@ -114,6 +114,7 @@ async def api_get_jukebox_song( tracks = [] async with httpx.AsyncClient() as client: try: + assert jukebox.sp_access_token r = await client.get( "https://api.spotify.com/v1/playlists/" + sp_playlist + "/tracks", timeout=40, @@ -194,6 +195,7 @@ async def api_get_jukebox_device_check( if not jukebox: raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="No Jukeboxes") async with httpx.AsyncClient() as client: + assert jukebox.sp_access_token rDevice = await client.get( "https://api.spotify.com/v1/me/player/devices", timeout=40, @@ -229,6 +231,7 @@ async def api_get_jukebox_invoice(juke_id, song_id): raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="No jukebox") try: + assert jukebox.sp_device devices = await api_get_jukebox_device_check(juke_id) deviceConnected = False for device in devices["devices"]: @@ -291,6 +294,7 @@ async def api_get_jukebox_invoice_paid( jukebox_payment = await get_jukebox_payment(pay_hash) if jukebox_payment and jukebox_payment.paid: async with httpx.AsyncClient() as client: + assert jukebox.sp_access_token r = await client.get( "https://api.spotify.com/v1/me/player/currently-playing?market=ES", timeout=40, @@ -308,6 +312,7 @@ async def api_get_jukebox_invoice_paid( if r.status_code == 204 or isPlaying == False: async with httpx.AsyncClient() as client: uri = ["spotify:track:" + song_id] + assert jukebox.sp_device r = await client.put( "https://api.spotify.com/v1/me/player/play?device_id=" + jukebox.sp_device.split("-")[1], @@ -339,6 +344,8 @@ async def api_get_jukebox_invoice_paid( ) elif r.status_code == 200: async with httpx.AsyncClient() as client: + assert jukebox.sp_access_token + assert jukebox.sp_device r = await client.post( "https://api.spotify.com/v1/me/player/queue?uri=spotify%3Atrack%3A" + song_id @@ -399,6 +406,7 @@ async def api_get_jukebox_currently( raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="No jukebox") async with httpx.AsyncClient() as client: try: + assert jukebox.sp_access_token r = await client.get( "https://api.spotify.com/v1/me/player/currently-playing?market=ES", timeout=40,