From 9b95a7743d722145c85cc680897d4c6d80aee168 Mon Sep 17 00:00:00 2001 From: Tiago vasconcelos Date: Mon, 28 Feb 2022 10:08:50 +0000 Subject: [PATCH 1/2] fix user keyword to "user" --- lnbits/extensions/jukebox/crud.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lnbits/extensions/jukebox/crud.py b/lnbits/extensions/jukebox/crud.py index 14dc4760..caaac7e5 100644 --- a/lnbits/extensions/jukebox/crud.py +++ b/lnbits/extensions/jukebox/crud.py @@ -12,7 +12,7 @@ async def create_jukebox( juke_id = urlsafe_short_hash() result = await db.execute( """ - INSERT INTO jukebox.jukebox (id, user, title, wallet, sp_user, sp_secret, sp_access_token, sp_refresh_token, sp_device, sp_playlists, price, profit) + INSERT INTO jukebox.jukebox (id, "user", title, wallet, sp_user, sp_secret, sp_access_token, sp_refresh_token, sp_device, sp_playlists, price, profit) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( @@ -41,6 +41,7 @@ async def update_jukebox( q = ", ".join([f"{field[0]} = ?" for field in data]) items = [f"{field[1]}" for field in data] items.append(juke_id) + q = q.replace("user", '"user"', 1) # hack to make user be "user"! await db.execute(f"UPDATE jukebox.jukebox SET {q} WHERE id = ?", (items)) row = await db.fetchone("SELECT * FROM jukebox.jukebox WHERE id = ?", (juke_id,)) return Jukebox(**row) if row else None @@ -57,11 +58,11 @@ async def get_jukebox_by_user(user: str) -> Optional[Jukebox]: async def get_jukeboxs(user: str) -> List[Jukebox]: - rows = await db.fetchall("SELECT * FROM jukebox.jukebox WHERE user = ?", (user,)) + rows = await db.fetchall('SELECT * FROM jukebox.jukebox WHERE "user" = ?', (user,)) for row in rows: if row.sp_playlists == None: await delete_jukebox(row.id) - rows = await db.fetchall("SELECT * FROM jukebox.jukebox WHERE user = ?", (user,)) + rows = await db.fetchall('SELECT * FROM jukebox.jukebox WHERE "user" = ?', (user,)) return [Jukebox(**row) for row in rows] From 6c0aa8fa8d9eb4690b7fc4722a3cc36a5334035a Mon Sep 17 00:00:00 2001 From: Tiago vasconcelos Date: Mon, 28 Feb 2022 10:09:40 +0000 Subject: [PATCH 2/2] info/error if no music is playing yet on jukebox --- lnbits/extensions/jukebox/views_api.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lnbits/extensions/jukebox/views_api.py b/lnbits/extensions/jukebox/views_api.py index 421ebf3a..3ba8cbf2 100644 --- a/lnbits/extensions/jukebox/views_api.py +++ b/lnbits/extensions/jukebox/views_api.py @@ -75,7 +75,6 @@ async def api_check_credentials_check( juke_id: str = Query(None), wallet: WalletTypeInfo = Depends(require_admin_key) ): jukebox = await get_jukebox(juke_id) - return jukebox @@ -442,7 +441,7 @@ async def api_get_jukebox_currently( token = await api_get_token(juke_id) if token == False: raise HTTPException( - status_code=HTTPStatus.FORBIDDEN, detail="INvoice not paid" + status_code=HTTPStatus.FORBIDDEN, detail="Invoice not paid" ) elif retry: raise HTTPException( @@ -456,5 +455,5 @@ async def api_get_jukebox_currently( ) except: raise HTTPException( - status_code=HTTPStatus.NOT_FOUND, detail="Something went wrong" + status_code=HTTPStatus.NOT_FOUND, detail="Something went wrong, or no song is playing yet" )