mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-28 12:56:16 +02:00
can't seem to make url_for work
This commit is contained in:
@@ -22,7 +22,7 @@ async def api_lnurl_response(request: Request, link_id):
|
|||||||
|
|
||||||
rate = await get_fiat_rate_satoshis(link.currency) if link.currency else 1
|
rate = await get_fiat_rate_satoshis(link.currency) if link.currency else 1
|
||||||
resp = LnurlPayResponse(
|
resp = LnurlPayResponse(
|
||||||
callback=url_for("lnurlp.api_lnurl_callback", link_id=link.id, extra=request.path_params['extra'], _external=True),
|
callback=request.url_for("lnurlp.api_lnurl_callback", link_id=link.id, extra=request.path_params['extra'], _external=True),
|
||||||
min_sendable=math.ceil(link.min * rate) * 1000,
|
min_sendable=math.ceil(link.min * rate) * 1000,
|
||||||
max_sendable=round(link.max * rate) * 1000,
|
max_sendable=round(link.max * rate) * 1000,
|
||||||
metadata=link.lnurlpay_metadata,
|
metadata=link.lnurlpay_metadata,
|
||||||
@@ -35,7 +35,7 @@ async def api_lnurl_response(request: Request, link_id):
|
|||||||
return params
|
return params
|
||||||
|
|
||||||
|
|
||||||
@lnurlp_ext.get("/api/v1/lnurl/cb/{link_id}", status_code=HTTPStatus.OK)
|
@lnurlp_ext.get("/api/v1/lnurl/cb/{link_id}", status_code=HTTPStatus.OK, name="lnurlp.api_lnurl_callback")
|
||||||
async def api_lnurl_callback(request: Request, link_id):
|
async def api_lnurl_callback(request: Request, link_id):
|
||||||
link = await increment_pay_link(link_id, served_pr=1)
|
link = await increment_pay_link(link_id, served_pr=1)
|
||||||
if not link:
|
if not link:
|
||||||
|
@@ -37,10 +37,9 @@ class PayLink(BaseModel):
|
|||||||
data = dict(row)
|
data = dict(row)
|
||||||
return cls(**data)
|
return cls(**data)
|
||||||
|
|
||||||
@property
|
|
||||||
def lnurl(self) -> str:
|
def lnurl(self, req: Request) -> str:
|
||||||
r = Request
|
url = req.url_for("lnurlp.api_lnurl_response", link_id=self.id)
|
||||||
url = r.url_for("lnurlp.api_lnurl_response", link_id=self.id, _external=True)
|
|
||||||
return lnurl_encode(url)
|
return lnurl_encode(url)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@@ -51,7 +51,7 @@ new Vue({
|
|||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'GET',
|
'GET',
|
||||||
'/lnurlp/api/v1/links?all_wallets',
|
'/lnurlp/api/v1/links?all_wallets=true',
|
||||||
this.g.user.wallets[0].inkey
|
this.g.user.wallets[0].inkey
|
||||||
)
|
)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
@@ -6,7 +6,7 @@ from pydantic.main import BaseModel
|
|||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from lnurl.exceptions import InvalidUrl as LnurlInvalidUrl # type: ignore
|
from lnurl.exceptions import InvalidUrl as LnurlInvalidUrl # type: ignore
|
||||||
from starlette.exceptions import HTTPException
|
from starlette.exceptions import HTTPException
|
||||||
from starlette.requests import Request
|
from fastapi import Request
|
||||||
from starlette.responses import HTMLResponse, JSONResponse # type: ignore
|
from starlette.responses import HTMLResponse, JSONResponse # type: ignore
|
||||||
|
|
||||||
from lnbits.core.crud import get_user
|
from lnbits.core.crud import get_user
|
||||||
@@ -30,17 +30,19 @@ async def api_list_currencies_available():
|
|||||||
|
|
||||||
@lnurlp_ext.get("/api/v1/links", status_code=HTTPStatus.OK)
|
@lnurlp_ext.get("/api/v1/links", status_code=HTTPStatus.OK)
|
||||||
# @api_check_wallet_key("invoice")
|
# @api_check_wallet_key("invoice")
|
||||||
async def api_links(wallet: WalletTypeInfo = Depends(get_key_type), all_wallets: bool = Query(False)):
|
async def api_links(req: Request, wallet: WalletTypeInfo = Depends(get_key_type), all_wallets: bool = Query(False)):
|
||||||
wallet_ids = [wallet.wallet.id]
|
wallet_ids = [wallet.wallet.id]
|
||||||
|
|
||||||
if all_wallets:
|
if all_wallets:
|
||||||
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
|
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
|
||||||
|
# print("LINKS", [link.dict() for link in await get_pay_links(wallet_ids)])
|
||||||
|
print("LINKS", [{"lnurl": link.lnurl(req)} for link in await get_pay_links(wallet_ids)])
|
||||||
try:
|
try:
|
||||||
return [
|
return [link.dict() for link in await get_pay_links(wallet_ids)]
|
||||||
{**link._asdict(), **{"lnurl": link.lnurl}}
|
# return [
|
||||||
for link in await get_pay_links(wallet_ids)
|
# {**link.dict(), "lnurl": link.lnurl}
|
||||||
]
|
# for link in await get_pay_links(wallet_ids)
|
||||||
|
# ]
|
||||||
|
|
||||||
except LnurlInvalidUrl:
|
except LnurlInvalidUrl:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
@@ -57,7 +59,7 @@ async def api_links(wallet: WalletTypeInfo = Depends(get_key_type), all_wallets:
|
|||||||
|
|
||||||
@lnurlp_ext.get("/api/v1/links/{link_id}", status_code=HTTPStatus.OK)
|
@lnurlp_ext.get("/api/v1/links/{link_id}", status_code=HTTPStatus.OK)
|
||||||
# @api_check_wallet_key("invoice")
|
# @api_check_wallet_key("invoice")
|
||||||
async def api_link_retrieve(link_id, wallet: WalletTypeInfo = Depends(get_key_type)):
|
async def api_link_retrieve(r: Request, link_id, wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||||
link = await get_pay_link(link_id)
|
link = await get_pay_link(link_id)
|
||||||
|
|
||||||
if not link:
|
if not link:
|
||||||
@@ -74,7 +76,7 @@ async def api_link_retrieve(link_id, wallet: WalletTypeInfo = Depends(get_key_ty
|
|||||||
)
|
)
|
||||||
# return {"message": "Not your pay link."}, HTTPStatus.FORBIDDEN
|
# return {"message": "Not your pay link."}, HTTPStatus.FORBIDDEN
|
||||||
|
|
||||||
return {**link._asdict(), **{"lnurl": link.lnurl}}
|
return {**link._asdict(), **{"lnurl": link.lnurl(r)}}
|
||||||
|
|
||||||
|
|
||||||
@lnurlp_ext.post("/api/v1/links", status_code=HTTPStatus.CREATED)
|
@lnurlp_ext.post("/api/v1/links", status_code=HTTPStatus.CREATED)
|
||||||
|
Reference in New Issue
Block a user