copilot lnurls fetching

This commit is contained in:
benarc 2021-10-17 23:19:42 +01:00
parent 75ea724d12
commit 762f0ba404
3 changed files with 10 additions and 4 deletions

View file

@ -23,7 +23,9 @@ from fastapi.params import Depends
from fastapi.param_functions import Query
@copilot_ext.get("/lnurl/{cp_id}", response_class=HTMLResponse)
@copilot_ext.get(
"/lnurl/{cp_id}", response_class=HTMLResponse, name="copilot.lnurl_response"
)
async def lnurl_response(req: Request, cp_id: str = Query(None)):
cp = await get_copilot(cp_id)
if not cp:

View file

@ -5,6 +5,8 @@ from typing import Optional, Dict
from lnbits.lnurl import encode as lnurl_encode # type: ignore
from lnurl.types import LnurlPayMetadata # type: ignore
from pydantic import BaseModel
import json
from sqlite3 import Row
class CreateCopilotData(BaseModel):
@ -58,5 +60,5 @@ class Copilots(BaseModel):
success_url: str = Query(None)
def lnurl(self, req: Request) -> str:
url = req.url_for("copilot.lnurl_response", link_id=self.id)
url = req.url_for("copilot.lnurl_response", cp_id=self.id)
return lnurl_encode(url)

View file

@ -49,7 +49,9 @@ async def api_copilots_retrieve(
@copilot_ext.get("/api/v1/copilot/{copilot_id}")
async def api_copilot_retrieve(
copilot_id: str = Query(None), wallet: WalletTypeInfo = Depends(get_key_type)
req: Request,
copilot_id: str = Query(None),
wallet: WalletTypeInfo = Depends(get_key_type),
):
copilot = await get_copilot(copilot_id)
if not copilot:
@ -58,7 +60,7 @@ async def api_copilot_retrieve(
)
if not copilot.lnurl_toggle:
return copilot.dict()
return {**copilot.dict(), **{"lnurl": copilot.lnurl}}
return {**copilot.dict(), **{"lnurl": copilot.lnurl(req)}}
@copilot_ext.post("/api/v1/copilot")