From da7f7fb618b3a9de48ba1fb2e663aa6a029be5b9 Mon Sep 17 00:00:00 2001 From: Tiago vasconcelos Date: Fri, 13 Aug 2021 09:42:15 +0100 Subject: [PATCH 1/2] fix js error on fetch copilots --- lnbits/extensions/copilot/templates/copilot/index.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lnbits/extensions/copilot/templates/copilot/index.html b/lnbits/extensions/copilot/templates/copilot/index.html index d5f7cccd..69914e99 100644 --- a/lnbits/extensions/copilot/templates/copilot/index.html +++ b/lnbits/extensions/copilot/templates/copilot/index.html @@ -526,7 +526,9 @@ this.g.user.wallets[0].inkey ) .then(function (response) { - self.CopilotLinks = response.data.map(mapCopilot) + if(response.data){ + self.CopilotLinks = response.data.map(mapCopilot) + } }) .catch(function (error) { LNbits.utils.notifyApiError(error) From 20ecfb48106c2f93079bcf82dffee1785ac9bf39 Mon Sep 17 00:00:00 2001 From: Tiago vasconcelos Date: Fri, 13 Aug 2021 16:31:07 +0100 Subject: [PATCH 2/2] Fix for postgres compatibility --- lnbits/extensions/copilot/crud.py | 24 +++++------ lnbits/extensions/copilot/migrations.py | 43 +++++++++++++++++++ .../copilot/templates/copilot/index.html | 31 ++++++++++--- 3 files changed, 78 insertions(+), 20 deletions(-) diff --git a/lnbits/extensions/copilot/crud.py b/lnbits/extensions/copilot/crud.py index a60fdd4e..d083675e 100644 --- a/lnbits/extensions/copilot/crud.py +++ b/lnbits/extensions/copilot/crud.py @@ -29,14 +29,14 @@ async def create_copilot( lnurl_title: Optional[str] = None, show_message: Optional[int] = 0, show_ack: Optional[int] = 0, - show_price: Optional[int] = 0, + show_price: Optional[str] = None, amount_made: Optional[int] = None, ) -> Copilots: copilot_id = urlsafe_short_hash() await db.execute( """ - INSERT INTO copilots ( + INSERT INTO copilot.copilots ( id, "user", lnurl_toggle, @@ -55,15 +55,14 @@ async def create_copilot( show_message, show_ack, show_price, - lnurl_title, amount_made ) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( copilot_id, user, - lnurl_toggle, + int(lnurl_toggle), wallet, title, animation1, @@ -76,10 +75,9 @@ async def create_copilot( animation2webhook, animation3webhook, lnurl_title, - show_message, - show_ack, + int(show_message), + int(show_ack), show_price, - lnurl_title, 0, ), ) @@ -89,21 +87,21 @@ async def create_copilot( async def update_copilot(copilot_id: str, **kwargs) -> Optional[Copilots]: q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()]) await db.execute( - f"UPDATE copilots SET {q} WHERE id = ?", (*kwargs.values(), copilot_id) + f"UPDATE copilot.copilots SET {q} WHERE id = ?", (*kwargs.values(), copilot_id) ) - row = await db.fetchone("SELECT * FROM copilots WHERE id = ?", (copilot_id,)) + row = await db.fetchone("SELECT * FROM copilot.copilots WHERE id = ?", (copilot_id,)) return Copilots.from_row(row) if row else None async def get_copilot(copilot_id: str) -> Copilots: - row = await db.fetchone("SELECT * FROM copilots WHERE id = ?", (copilot_id,)) + row = await db.fetchone("SELECT * FROM copilot.copilots WHERE id = ?", (copilot_id,)) return Copilots.from_row(row) if row else None async def get_copilots(user: str) -> List[Copilots]: - rows = await db.fetchall("""SELECT * FROM copilots WHERE "user" = ?""", (user,)) + rows = await db.fetchall("""SELECT * FROM copilot.copilots WHERE "user" = ?""", (user,)) return [Copilots.from_row(row) for row in rows] async def delete_copilot(copilot_id: str) -> None: - await db.execute("DELETE FROM copilots WHERE id = ?", (copilot_id,)) + await db.execute("DELETE FROM copilot.copilots WHERE id = ?", (copilot_id,)) diff --git a/lnbits/extensions/copilot/migrations.py b/lnbits/extensions/copilot/migrations.py index e4149f56..c1fbfc0d 100644 --- a/lnbits/extensions/copilot/migrations.py +++ b/lnbits/extensions/copilot/migrations.py @@ -31,3 +31,46 @@ async def m001_initial(db): ); """ ) + +async def m002_fix_data_types(db): + """ + Fix data types. + """ + + if(db.type != "SQLITE"): + await db.execute("ALTER TABLE copilot.copilots ALTER COLUMN show_price TYPE TEXT;") + + # If needed, migration for SQLite (RENAME not working properly) + # + # await db.execute( + # f""" + # CREATE TABLE copilot.new_copilots ( + # id TEXT NOT NULL PRIMARY KEY, + # "user" TEXT, + # title TEXT, + # lnurl_toggle INTEGER, + # wallet TEXT, + # animation1 TEXT, + # animation2 TEXT, + # animation3 TEXT, + # animation1threshold INTEGER, + # animation2threshold INTEGER, + # animation3threshold INTEGER, + # animation1webhook TEXT, + # animation2webhook TEXT, + # animation3webhook TEXT, + # lnurl_title TEXT, + # show_message INTEGER, + # show_ack INTEGER, + # show_price TEXT, + # amount_made INTEGER, + # fullscreen_cam INTEGER, + # iframe_url TEXT, + # timestamp TIMESTAMP NOT NULL DEFAULT {db.timestamp_now} + # ); + # """ + # ) + # + # await db.execute("INSERT INTO copilot.new_copilots SELECT * FROM copilot.copilots;") + # await db.execute("DROP TABLE IF EXISTS copilot.copilots;") + # await db.execute("ALTER TABLE copilot.new_copilots RENAME TO copilot.copilots;") diff --git a/lnbits/extensions/copilot/templates/copilot/index.html b/lnbits/extensions/copilot/templates/copilot/index.html index 69914e99..12d7058a 100644 --- a/lnbits/extensions/copilot/templates/copilot/index.html +++ b/lnbits/extensions/copilot/templates/copilot/index.html @@ -49,6 +49,7 @@ +
{{ col.label }}
- +