url_for issues
This commit is contained in:
@@ -10,6 +10,7 @@ from starlette.responses import HTMLResponse, JSONResponse # type: ignore
|
||||
|
||||
from lnbits.core.crud import get_user
|
||||
from lnbits.decorators import WalletTypeInfo, get_key_type
|
||||
from .models import CreateWithdrawData
|
||||
|
||||
# from fastapi import FastAPI, Query, Response
|
||||
|
||||
@@ -27,7 +28,7 @@ from .crud import (
|
||||
|
||||
@withdraw_ext.get("/api/v1/links", status_code=HTTPStatus.OK)
|
||||
# @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]
|
||||
|
||||
if all_wallets:
|
||||
@@ -35,8 +36,8 @@ async def api_links(wallet: WalletTypeInfo = Depends(get_key_type), all_wallets:
|
||||
try:
|
||||
return [
|
||||
{
|
||||
**link._asdict(),
|
||||
**{"lnurl": link.lnurl},
|
||||
**link.dict(),
|
||||
**{"lnurl": link.lnurl(req)},
|
||||
}
|
||||
for link in await get_withdraw_links(wallet_ids)
|
||||
]
|
||||
@@ -73,18 +74,18 @@ async def api_link_retrieve(link_id, wallet: WalletTypeInfo = Depends(get_key_ty
|
||||
|
||||
return {**link, **{"lnurl": link.lnurl}}
|
||||
|
||||
class CreateData(BaseModel):
|
||||
title: str = Query(...)
|
||||
min_withdrawable: int = Query(..., ge=1)
|
||||
max_withdrawable: int = Query(..., ge=1)
|
||||
uses: int = Query(..., ge=1)
|
||||
wait_time: int = Query(..., ge=1)
|
||||
is_unique: bool
|
||||
# class CreateData(BaseModel):
|
||||
# title: str = Query(...)
|
||||
# min_withdrawable: int = Query(..., ge=1)
|
||||
# max_withdrawable: int = Query(..., ge=1)
|
||||
# uses: int = Query(..., ge=1)
|
||||
# wait_time: int = Query(..., ge=1)
|
||||
# is_unique: bool
|
||||
|
||||
@withdraw_ext.post("/api/v1/links", status_code=HTTPStatus.CREATED)
|
||||
@withdraw_ext.put("/api/v1/links/{link_id}", status_code=HTTPStatus.OK)
|
||||
# @api_check_wallet_key("admin")
|
||||
async def api_link_create_or_update(data: CreateData, link_id: str = None):
|
||||
async def api_link_create_or_update(req: Request, data: CreateWithdrawData, link_id: str = None, wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||
if data.max_withdrawable < data.min_withdrawable:
|
||||
raise HTTPException(
|
||||
detail="`max_withdrawable` needs to be at least `min_withdrawable`.",
|
||||
@@ -122,11 +123,11 @@ async def api_link_create_or_update(data: CreateData, link_id: str = None):
|
||||
link = await update_withdraw_link(link_id, **data, usescsv=usescsv, used=0)
|
||||
else:
|
||||
link = await create_withdraw_link(
|
||||
wallet_id=wallet.wallet.id, **data, usescsv=usescsv
|
||||
wallet_id=wallet.wallet.id, data=data, usescsv=usescsv
|
||||
)
|
||||
# if link_id:
|
||||
# response.status_code = HTTPStatus.OK
|
||||
return {**link, **{"lnurl": link.lnurl}}
|
||||
return {**link.dict(), **{"lnurl": link.lnurl(req)}}
|
||||
|
||||
|
||||
@withdraw_ext.delete("/api/v1/links/{link_id}")
|
||||
|
||||
Reference in New Issue
Block a user