From 58ce17d5f6a8f38433edefcbd8e918c4a47a545a Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Tue, 20 Oct 2026 11:20:44 +0300 Subject: [PATCH] Migrate to Pydantic 2 for LNbits 1.7.0 --- config.json | 3 ++- crud.py | 2 +- models.py | 46 +++++++++++++++++++++++----------------------- static/js/index.js | 2 +- views.py | 6 +++++- views_api.py | 4 ++-- 6 files changed, 34 insertions(+), 29 deletions(-) diff --git a/config.json b/config.json index cb36c61..e58e9a4 100644 --- a/config.json +++ b/config.json @@ -1,8 +1,9 @@ { "name": "Streamer Copilot", + "version": "1.0.4", "short_description": "Video tips/animations/webhooks", "tile": "/copilot/static/bitcoin-streaming.png", - "min_lnbits_version": "1.0.0", + "min_lnbits_version": "1.7.0", "contributors": [ { "name": "Ben Arc", diff --git a/crud.py b/crud.py index 477c8c9..a35de99 100644 --- a/crud.py +++ b/crud.py @@ -8,7 +8,7 @@ async def create_copilot(data: CreateCopilotData) -> Copilot: copilot_id = urlsafe_short_hash() - copilot = Copilot(id=copilot_id, **data.dict()) + copilot = Copilot(id=copilot_id, **data.model_dump()) await db.insert("copilot.newer_copilots", copilot) return copilot diff --git a/models.py b/models.py index e832cc3..e4febc7 100644 --- a/models.py +++ b/models.py @@ -4,52 +4,52 @@ class CreateCopilotData(BaseModel): - user: str = Query(None) - title: str = Query(None) + user: str | None = Query(None) + title: str | None = Query(None) lnurl_toggle: int = Query(0) - wallet: str = Query(None) - animation1: str = Query(None) - animation2: str = Query(None) - animation3: str = Query(None) + wallet: str | None = Query(None) + animation1: str | None = Query(None) + animation2: str | None = Query(None) + animation3: str | None = Query(None) animation1threshold: int = Query(0) animation2threshold: int = Query(0) animation3threshold: int = Query(0) - animation1webhook: str = Query(None) - animation2webhook: str = Query(None) - animation3webhook: str = Query(None) - lnurl_title: str = Query(None) + animation1webhook: str | None = Query(None) + animation2webhook: str | None = Query(None) + animation3webhook: str | None = Query(None) + lnurl_title: str | None = Query(None) show_message: int = Query(0) show_ack: int = Query(0) - show_price: str = Query(None) + show_price: str | None = Query(None) amount_made: int = Query(0) timestamp: int = Query(0) fullscreen_cam: int = Query(0) - iframe_url: str = Query(None) + iframe_url: str | None = Query(None) class Copilot(BaseModel): id: str - user: str | None + user: str | None = None title: str lnurl_toggle: int - wallet: str | None - animation1: str | None - animation2: str | None - animation3: str | None + wallet: str | None = None + animation1: str | None = None + animation2: str | None = None + animation3: str | None = None animation1threshold: int animation2threshold: int animation3threshold: int - animation1webhook: str | None - animation2webhook: str | None - animation3webhook: str | None - lnurl_title: str | None + animation1webhook: str | None = None + animation2webhook: str | None = None + animation3webhook: str | None = None + lnurl_title: str | None = None show_message: int show_ack: int - show_price: str | None + show_price: str | None = None amount_made: int timestamp: int fullscreen_cam: int - iframe_url: str | None + iframe_url: str | None = None def lnurl(self, req: Request) -> str: url = str(req.url_for("copilot.lnurl_response", cp_id=self.id)) diff --git a/static/js/index.js b/static/js/index.js index 1db2446..4980e32 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -76,7 +76,7 @@ window.app = Vue.createApp({ data: null }, options: ['bitcoin', 'confetti', 'rocket', 'face', 'martijn', 'rick'], - currencyOptions: ['sat', ...window.currencies] + currencyOptions: ['sat', ...CURRENCIES] } }, methods: { diff --git a/views.py b/views.py index bc4cc82..783207e 100644 --- a/views.py +++ b/views.py @@ -16,7 +16,11 @@ def copilot_renderer(): async def index(request: Request, user: User = Depends(check_user_exists)): return copilot_renderer().TemplateResponse( "copilot/index.html", - {"request": request, "user": user.json(), "currencies": allowed_currencies()}, + { + "request": request, + "user": user.model_dump_json(), + "currencies": allowed_currencies(), + }, ) diff --git a/views_api.py b/views_api.py index 07de398..3d40861 100644 --- a/views_api.py +++ b/views_api.py @@ -39,7 +39,7 @@ async def api_copilot_retrieve( ) if not copilot.lnurl_toggle: return copilot - return {**copilot.dict(), **{"lnurl": copilot.lnurl(req)}} + return {**copilot.model_dump(), **{"lnurl": copilot.lnurl(req)}} @copilot_api_router.post("/api/v1/copilot") @@ -66,7 +66,7 @@ async def api_copilot_update( data.user = wallet.wallet.user data.wallet = wallet.wallet.id - for key, value in data.dict().items(): + for key, value in data.model_dump().items(): if value: setattr(copilot, key, value) return await update_copilot(copilot)