diff --git a/lnbits/extensions/bleskomat/__init__.py b/lnbits/extensions/bleskomat/__init__.py index 094488f49..bb967859d 100644 --- a/lnbits/extensions/bleskomat/__init__.py +++ b/lnbits/extensions/bleskomat/__init__.py @@ -1,17 +1,26 @@ from fastapi import APIRouter +from starlette.staticfiles import StaticFiles from lnbits.db import Database from lnbits.helpers import template_renderer db = Database("ext_bleskomat") +bleskomat_static_files = [ + { + "path": "/bleskomat/static", + "app": StaticFiles(directory="lnbits/extensions/bleskomat/static"), + "name": "bleskomat_static", + } +] + bleskomat_ext: APIRouter = APIRouter( prefix="/bleskomat", tags=["Bleskomat"] ) def bleskomat_renderer(): - return template_renderer(["lnbits/extensions/events/templates"]) + return template_renderer(["lnbits/extensions/bleskomat/templates"]) from .lnurl_api import * # noqa from .views import * # noqa diff --git a/lnbits/extensions/bleskomat/helpers.py b/lnbits/extensions/bleskomat/helpers.py index 3d3550488..1062ca278 100644 --- a/lnbits/extensions/bleskomat/helpers.py +++ b/lnbits/extensions/bleskomat/helpers.py @@ -36,7 +36,7 @@ def generate_bleskomat_lnurl_secret(api_key_id: str, signature: str): def get_callback_url(request: Request): - return request.url_for("bleskomat.api_bleskomat_lnurl", _external=True) + return request.url_for("bleskomat.api_bleskomat_lnurl") def is_supported_lnurl_subprotocol(tag: str) -> bool: diff --git a/lnbits/extensions/bleskomat/static/js/index.js b/lnbits/extensions/bleskomat/static/js/index.js index 4e8f993fe..f20a46599 100644 --- a/lnbits/extensions/bleskomat/static/js/index.js +++ b/lnbits/extensions/bleskomat/static/js/index.js @@ -84,7 +84,7 @@ new Vue({ LNbits.api .request( 'GET', - '/bleskomat/api/v1/bleskomats?all_wallets=True', + '/bleskomat/api/v1/bleskomats?all_wallets=true', this.g.user.wallets[0].adminkey ) .then(function (response) { diff --git a/lnbits/extensions/bleskomat/views.py b/lnbits/extensions/bleskomat/views.py index 7e58f284b..8467385eb 100644 --- a/lnbits/extensions/bleskomat/views.py +++ b/lnbits/extensions/bleskomat/views.py @@ -1,10 +1,7 @@ -from http import HTTPStatus - from fastapi import Request from fastapi.params import Depends from fastapi.templating import Jinja2Templates -from starlette.exceptions import HTTPException from starlette.responses import HTMLResponse from lnbits.core.models import User @@ -14,11 +11,13 @@ from . import bleskomat_ext, bleskomat_renderer from .exchange_rates import exchange_rate_providers_serializable, fiat_currencies from .helpers import get_callback_url +templates = Jinja2Templates(directory="templates") + @bleskomat_ext.get("/", response_class=HTMLResponse) async def index(request: Request, user: User = Depends(check_user_exists)): bleskomat_vars = { - "callback_url": get_callback_url(request), + "callback_url": get_callback_url(request=request), "exchange_rate_providers": exchange_rate_providers_serializable, "fiat_currencies": fiat_currencies, } diff --git a/lnbits/extensions/bleskomat/views_api.py b/lnbits/extensions/bleskomat/views_api.py index 53062d9af..d8960429a 100644 --- a/lnbits/extensions/bleskomat/views_api.py +++ b/lnbits/extensions/bleskomat/views_api.py @@ -1,6 +1,6 @@ from http import HTTPStatus -from fastapi.params import Query +from fastapi import Depends, Query from starlette.exceptions import HTTPException from lnbits.core.crud import get_user @@ -19,7 +19,7 @@ from .exchange_rates import fetch_fiat_exchange_rate @bleskomat_ext.get("/api/v1/bleskomats") -async def api_bleskomats(wallet: WalletTypeInfo(require_admin_key), all_wallets: bool = Query(False)): +async def api_bleskomats(wallet: WalletTypeInfo = Depends(require_admin_key), all_wallets: bool = Query(False)): wallet_ids = [wallet.wallet.id] if all_wallets: @@ -29,7 +29,7 @@ async def api_bleskomats(wallet: WalletTypeInfo(require_admin_key), all_wallets: @bleskomat_ext.get("/api/v1/bleskomat/{bleskomat_id}") -async def api_bleskomat_retrieve(wallet: WalletTypeInfo(require_admin_key), bleskomat_id): +async def api_bleskomat_retrieve(bleskomat_id, wallet: WalletTypeInfo = Depends(require_admin_key)): bleskomat = await get_bleskomat(bleskomat_id) if not bleskomat or bleskomat.wallet != wallet.wallet.id: @@ -43,7 +43,7 @@ async def api_bleskomat_retrieve(wallet: WalletTypeInfo(require_admin_key), bles @bleskomat_ext.post("/api/v1/bleskomat") @bleskomat_ext.put("/api/v1/bleskomat/{bleskomat_id}",) -async def api_bleskomat_create_or_update(data: CreateBleskomat, wallet: WalletTypeInfo(require_admin_key), bleskomat_id=None): +async def api_bleskomat_create_or_update(data: CreateBleskomat, wallet: WalletTypeInfo = Depends(require_admin_key), bleskomat_id=None): try: fiat_currency = data.fiat_currency exchange_rate_provider = data.exchange_rate_provider @@ -73,7 +73,7 @@ async def api_bleskomat_create_or_update(data: CreateBleskomat, wallet: WalletTy @bleskomat_ext.delete("/api/v1/bleskomat/{bleskomat_id}") -async def api_bleskomat_delete(wallet: WalletTypeInfo(require_admin_key), bleskomat_id): +async def api_bleskomat_delete(bleskomat_id, wallet: WalletTypeInfo = Depends(require_admin_key)): bleskomat = await get_bleskomat(bleskomat_id) if not bleskomat or bleskomat.wallet != wallet.wallet.id: