From d5a4dc801ff4a9710191340ae9cf9c93b76b2a59 Mon Sep 17 00:00:00 2001 From: benarc Date: Wed, 13 Oct 2021 10:43:11 +0100 Subject: [PATCH] copilot still not working --- lnbits/extensions/copilot/crud.py | 2 - lnbits/extensions/copilot/models.py | 46 +++++++++--------- .../copilot/templates/copilot/index.html | 3 -- lnbits/extensions/copilot/views_api.py | 48 ++++++++++--------- lnbits/extensions/jukebox/views_api.py | 1 - 5 files changed, 49 insertions(+), 51 deletions(-) diff --git a/lnbits/extensions/copilot/crud.py b/lnbits/extensions/copilot/crud.py index de5e69c8..0b04ec7a 100644 --- a/lnbits/extensions/copilot/crud.py +++ b/lnbits/extensions/copilot/crud.py @@ -11,7 +11,6 @@ async def create_copilot( data: CreateCopilotData, inkey: Optional[str] = "" ) -> Copilots: copilot_id = urlsafe_short_hash() - await db.execute( """ INSERT INTO copilot.copilots ( @@ -82,7 +81,6 @@ async def get_copilot(copilot_id: str) -> Copilots: async def get_copilots(user: str) -> List[Copilots]: rows = await db.fetchall("SELECT * FROM copilot.copilots WHERE user = ?", (user,)) - print(user) return [Copilots(**row) for row in rows] diff --git a/lnbits/extensions/copilot/models.py b/lnbits/extensions/copilot/models.py index 230825a0..4f3ef80a 100644 --- a/lnbits/extensions/copilot/models.py +++ b/lnbits/extensions/copilot/models.py @@ -10,29 +10,29 @@ from pydantic import BaseModel class CreateCopilotData(BaseModel): - id: str = Query(None) - user: str = Query(None) - title: str = Query(None) - lnurl_toggle: int = Query(None) - wallet: str = Query(None) - animation1: str = Query(None) - animation2: str = Query(None) - animation3: str = Query(None) - animation1threshold: int = Query(None) - animation2threshold: int = Query(None) - animation3threshold: int = Query(None) - animation1webhook: str = Query(None) - animation2webhook: str = Query(None) - animation3webhook: str = Query(None) - lnurl_title: str = Query(None) - show_message: int = Query(None) - show_ack: int = Query(None) - show_price: int = Query(None) - amount_made: int = Query(None) - timestamp: int = Query(None) - fullscreen_cam: int = Query(None) - iframe_url: str = Query(None) - success_url: str = Query(None) + id: Optional[str] = None + user: Optional[str] = None + title: Optional[str] = None + lnurl_toggle: Optional[int] = None + wallet: Optional[str] = None + animation1: Optional[str] = None + animation2: Optional[str] = None + animation3: Optional[str] = None + animation1threshold: Optional[int] = None + animation2threshold: Optional[int] = None + animation3threshold: Optional[int] = None + animation1webhook: Optional[str] = None + animation2webhook: Optional[str] = None + animation3webhook: Optional[str] = None + lnurl_title: Optional[str] = None + show_message: Optional[int] = None + show_ack: Optional[int] = None + show_price: Optional[int] = None + amount_made: Optional[int] = None + timestamp: Optional[int] = None + fullscreen_cam: Optional[int] = None + iframe_url: Optional[int] = None + success_url: Optional[str] = None class Copilots(BaseModel): diff --git a/lnbits/extensions/copilot/templates/copilot/index.html b/lnbits/extensions/copilot/templates/copilot/index.html index 73b23596..95c08bae 100644 --- a/lnbits/extensions/copilot/templates/copilot/index.html +++ b/lnbits/extensions/copilot/templates/copilot/index.html @@ -515,9 +515,6 @@ updatedData[property] = parseInt(data[property]) } } - console.log('updatedData') - console.log(updatedData) - console.log('updatedData') LNbits.api .request('POST', '/copilot/api/v1/copilot', wallet, updatedData) .then(function (response) { diff --git a/lnbits/extensions/copilot/views_api.py b/lnbits/extensions/copilot/views_api.py index 4e326f42..66540056 100644 --- a/lnbits/extensions/copilot/views_api.py +++ b/lnbits/extensions/copilot/views_api.py @@ -35,30 +35,16 @@ from .crud import ( #######################COPILOT########################## -@copilot_ext.post("/api/v1/copilot", response_class=HTMLResponse) -@copilot_ext.put("/api/v1/copilot/{juke_id}", response_class=HTMLResponse) -async def api_copilot_create_or_update( - data: CreateCopilotData, - copilot_id: str = Query(None), - wallet: WalletTypeInfo = Depends(get_key_type), -): - print(data) - if not copilot_id: - copilot = await create_copilot(data, inkey=wallet.wallet.inkey) - - return copilot, HTTPStatus.CREATED - else: - copilot = await update_copilot(data, copilot_id=copilot_id) - return copilot - - @copilot_ext.get("/api/v1/copilot", response_class=HTMLResponse) async def api_copilots_retrieve(wallet: WalletTypeInfo = Depends(get_key_type)): - try: - print(wallet.wallet.user) - return [copilot.dict() for copilot in await get_copilots(wallet.wallet.user)] - except: - return "" + wallet_user = wallet.wallet.user + copilots = [copilot.dict() for copilot in await get_copilots(wallet_user)] + if copilots: + return copilots + raise HTTPException( + status_code=HTTPStatus.NO_CONTENT, + detail="No Jukeboxes", + ) @copilot_ext.get("/api/v1/copilot/{copilot_id}", response_class=HTMLResponse) @@ -76,6 +62,24 @@ async def api_copilot_retrieve( return {**copilot.dict(), **{"lnurl": copilot.lnurl}} +@copilot_ext.post("/api/v1/copilot", response_class=HTMLResponse) +@copilot_ext.put("/api/v1/copilot/{juke_id}", response_class=HTMLResponse) +async def api_copilot_create_or_update( + data: CreateCopilotData, + copilot_id: str = Query(None), + wallet: WalletTypeInfo = Depends(get_key_type), +): + print("cunt") + + if not copilot_id: + copilot = await create_copilot(data, inkey=wallet.wallet.inkey) + + return copilot, HTTPStatus.CREATED + else: + copilot = await update_copilot(data, copilot_id=copilot_id) + return copilot, HTTPStatus.NOT_FOUND + + @copilot_ext.delete("/api/v1/copilot/{copilot_id}", response_class=HTMLResponse) async def api_copilot_delete( copilot_id: str = Query(None), diff --git a/lnbits/extensions/jukebox/views_api.py b/lnbits/extensions/jukebox/views_api.py index 4f2940d3..233873ef 100644 --- a/lnbits/extensions/jukebox/views_api.py +++ b/lnbits/extensions/jukebox/views_api.py @@ -39,7 +39,6 @@ async def api_get_jukeboxs( wallet_user = wallet.wallet.user jukeboxs = [jukebox.dict() for jukebox in await get_jukeboxs(wallet_user)] - print(jukeboxs) try: return jukeboxs