feat: add optional domain field (#120)
* feat: add optional domain field closes #119
This commit is contained in:
parent
76c5841bc8
commit
17135b45ae
8 changed files with 107 additions and 46 deletions
30
views_api.py
30
views_api.py
|
|
@ -23,15 +23,15 @@ from .crud import (
|
|||
update_lnurlp_settings,
|
||||
update_pay_link,
|
||||
)
|
||||
from .helpers import lnurl_encode_link_id, parse_nostr_private_key
|
||||
from .models import CreatePayLinkData, LnurlpSettings, PayLink
|
||||
from .helpers import lnurl_encode_link, parse_nostr_private_key
|
||||
from .models import CreatePayLinkData, LnurlpSettings, PayLink, PublicPayLink
|
||||
|
||||
lnurlp_api_router = APIRouter()
|
||||
|
||||
|
||||
def check_lnurl_encode(req: Request, link_id: str) -> str:
|
||||
def check_lnurl_encode(req: Request, link: PayLink) -> str:
|
||||
try:
|
||||
return lnurl_encode_link_id(req, link_id)
|
||||
return lnurl_encode_link(req, link.id, link.domain)
|
||||
except InvalidUrl as exc:
|
||||
raise HTTPException(
|
||||
detail=(
|
||||
|
|
@ -60,11 +60,11 @@ async def api_links(
|
|||
|
||||
links = await get_pay_links(wallet_ids)
|
||||
for link in links:
|
||||
link.lnurl = check_lnurl_encode(req=req, link_id=link.id)
|
||||
link.lnurl = check_lnurl_encode(req, link)
|
||||
return links
|
||||
|
||||
|
||||
@lnurlp_api_router.get("/api/v1/links/{link_id}", status_code=HTTPStatus.OK)
|
||||
@lnurlp_api_router.get("/api/v1/links/{link_id}")
|
||||
async def api_link_retrieve(
|
||||
req: Request, link_id: str, key_info: WalletTypeInfo = Depends(require_invoice_key)
|
||||
) -> PayLink:
|
||||
|
|
@ -85,7 +85,18 @@ async def api_link_retrieve(
|
|||
detail="Not your pay link.", status_code=HTTPStatus.FORBIDDEN
|
||||
)
|
||||
|
||||
link.lnurl = check_lnurl_encode(req, link.id)
|
||||
link.lnurl = check_lnurl_encode(req, link)
|
||||
return link
|
||||
|
||||
|
||||
@lnurlp_api_router.get("/api/v1/links/public/{link_id}", response_model=PublicPayLink)
|
||||
async def api_link_public_retrieve(req: Request, link_id: str) -> PayLink:
|
||||
link = await get_pay_link(link_id)
|
||||
if not link:
|
||||
raise HTTPException(
|
||||
detail="Pay link does not exist.", status_code=HTTPStatus.NOT_FOUND
|
||||
)
|
||||
link.lnurl = lnurl_encode_link(req, link.id, link.domain)
|
||||
return link
|
||||
|
||||
|
||||
|
|
@ -168,7 +179,7 @@ async def api_link_create_or_update(
|
|||
detail="Wallet does not exist.", status_code=HTTPStatus.FORBIDDEN
|
||||
)
|
||||
|
||||
# admins are allowed to create/edit paylinks beloging to regular users
|
||||
# admins are allowed to create/edit paylinks belonging to regular users
|
||||
user = await get_user(key_info.wallet.user)
|
||||
admin_user = user.admin if user else False
|
||||
if not admin_user and new_wallet.user != key_info.wallet.user:
|
||||
|
|
@ -197,8 +208,7 @@ async def api_link_create_or_update(
|
|||
|
||||
link = await create_pay_link(data)
|
||||
|
||||
link.lnurl = check_lnurl_encode(req=req, link_id=link.id)
|
||||
|
||||
link.lnurl = check_lnurl_encode(req, link)
|
||||
return link
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue