fix jukebox issues introduced from mypy pr (#1387)

* fix jukebox issues introduced from mypy pr

* fix no invoice

Co-authored-by: ben <ben@arc.wales>
This commit is contained in:
dni ⚡ 2023-01-23 10:17:16 +01:00 committed by GitHub
parent ca51b57355
commit d30a6dc5c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 9 deletions

View File

@ -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(

View File

@ -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

View File

@ -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

View File

@ -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,