fix bleskomat

This commit is contained in:
Tiago vasconcelos 2021-10-27 12:01:45 +01:00
parent 336e3a833a
commit 1653c45f12
5 changed files with 20 additions and 12 deletions

View File

@ -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

View File

@ -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:

View File

@ -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) {

View File

@ -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,
}

View File

@ -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: