diff --git a/lnbits/app.py b/lnbits/app.py index e27824cfb..96b3f483f 100644 --- a/lnbits/app.py +++ b/lnbits/app.py @@ -62,7 +62,7 @@ from .tasks import ( def create_app() -> FastAPI: configure_logger() app = FastAPI( - title="LNbits API", + title=settings.lnbits_title, description=( "API for LNbits, the free and open source bitcoin wallet and " "accounts system with plugins." diff --git a/lnbits/core/__init__.py b/lnbits/core/__init__.py index 3c9a5601d..718bbd0ca 100644 --- a/lnbits/core/__init__.py +++ b/lnbits/core/__init__.py @@ -5,7 +5,7 @@ from lnbits.db import Database db = Database("database") -core_app: APIRouter = APIRouter() +core_app: APIRouter = APIRouter(tags=["Core"]) core_app_extra: CoreAppExtra = CoreAppExtra() diff --git a/lnbits/core/models.py b/lnbits/core/models.py index c1ee7097b..e64fd7e66 100644 --- a/lnbits/core/models.py +++ b/lnbits/core/models.py @@ -319,3 +319,12 @@ class CreateInvoice(BaseModel): extra: Optional[dict] = None webhook: Optional[str] = None bolt11: Optional[str] = None + + +class CreateTopup(BaseModel): + id: str + amount: int + + +class CreateLnurlAuth(BaseModel): + callback: str diff --git a/lnbits/core/views/admin_api.py b/lnbits/core/views/admin_api.py index a14583b9b..f6ed18d00 100644 --- a/lnbits/core/views/admin_api.py +++ b/lnbits/core/views/admin_api.py @@ -6,12 +6,12 @@ from subprocess import Popen from typing import Optional from urllib.parse import urlparse -from fastapi import Body, Depends +from fastapi import Depends from fastapi.responses import FileResponse from starlette.exceptions import HTTPException from lnbits.core.crud import get_wallet -from lnbits.core.models import User +from lnbits.core.models import CreateTopup, User from lnbits.core.services import ( get_balance_delta, update_cached_settings, @@ -25,7 +25,12 @@ from .. import core_app, core_app_extra from ..crud import delete_admin_settings, get_admin_settings, update_admin_settings -@core_app.get("/admin/api/v1/audit", dependencies=[Depends(check_admin)]) +@core_app.get( + "/admin/api/v1/audit", + name="Audit", + description="show the current balance of the node and the LNbits database", + dependencies=[Depends(check_admin)], +) async def api_auditor(): try: delta, node_balance, total_balance = await get_balance_delta() @@ -86,14 +91,13 @@ async def api_restart_server() -> dict[str, str]: @core_app.put( "/admin/api/v1/topup/", + name="Topup", status_code=HTTPStatus.OK, dependencies=[Depends(check_super_user)], ) -async def api_topup_balance( - id: str = Body(...), amount: int = Body(...) -) -> dict[str, str]: +async def api_topup_balance(data: CreateTopup) -> dict[str, str]: try: - await get_wallet(id) + await get_wallet(data.id) except Exception: raise HTTPException( status_code=HTTPStatus.FORBIDDEN, detail="wallet does not exist." @@ -104,7 +108,7 @@ async def api_topup_balance( status_code=HTTPStatus.FORBIDDEN, detail="VoidWallet active" ) - await update_wallet_balance(wallet_id=id, amount=int(amount)) + await update_wallet_balance(wallet_id=data.id, amount=int(data.amount)) return {"status": "Success"} diff --git a/lnbits/core/views/api.py b/lnbits/core/views/api.py index b48f3da65..241c8d085 100644 --- a/lnbits/core/views/api.py +++ b/lnbits/core/views/api.py @@ -29,10 +29,10 @@ from lnbits.core.helpers import ( stop_extension_background_work, ) from lnbits.core.models import ( - Callback, ConversionData, CreateInvoice, CreateLnurl, + CreateLnurlAuth, DecodePayment, Payment, PaymentFilters, @@ -649,7 +649,7 @@ async def api_payments_decode(data: DecodePayment, response: Response): @core_app.post("/api/v1/lnurlauth") async def api_perform_lnurlauth( - data: Callback, wallet: WalletTypeInfo = Depends(require_admin_key) + data: CreateLnurlAuth, wallet: WalletTypeInfo = Depends(require_admin_key) ): err = await perform_lnurlauth(data.callback, wallet=wallet) if err: @@ -906,7 +906,11 @@ async def delete_extension_db(ext_id: str): # TINYURL -@core_app.post("/api/v1/tinyurl") +@core_app.post( + "/api/v1/tinyurl", + name="Tinyurl", + description="creates a tinyurl", +) async def api_create_tinyurl( url: str, endless: bool = False, wallet: WalletTypeInfo = Depends(get_key_type) ): @@ -923,7 +927,11 @@ async def api_create_tinyurl( ) -@core_app.get("/api/v1/tinyurl/{tinyurl_id}") +@core_app.get( + "/api/v1/tinyurl/{tinyurl_id}", + name="Tinyurl", + description="get a tinyurl by id", +) async def api_get_tinyurl( tinyurl_id: str, wallet: WalletTypeInfo = Depends(get_key_type) ): @@ -941,7 +949,11 @@ async def api_get_tinyurl( ) -@core_app.delete("/api/v1/tinyurl/{tinyurl_id}") +@core_app.delete( + "/api/v1/tinyurl/{tinyurl_id}", + name="Tinyurl", + description="delete a tinyurl by id", +) async def api_delete_tinyurl( tinyurl_id: str, wallet: WalletTypeInfo = Depends(get_key_type) ): @@ -960,16 +972,17 @@ async def api_delete_tinyurl( ) -@core_app.get("/t/{tinyurl_id}") +@core_app.get( + "/t/{tinyurl_id}", + name="Tinyurl", + description="redirects a tinyurl by id", +) async def api_tinyurl(tinyurl_id: str): - try: - tinyurl = await get_tinyurl(tinyurl_id) - if tinyurl: - response = RedirectResponse(url=tinyurl.url) - return response - else: - return - except Exception: + tinyurl = await get_tinyurl(tinyurl_id) + if tinyurl: + response = RedirectResponse(url=tinyurl.url) + return response + else: raise HTTPException( status_code=HTTPStatus.NOT_FOUND, detail="unable to find tinyurl" ) diff --git a/lnbits/core/views/generic.py b/lnbits/core/views/generic.py index b9694f0e7..f07b10ad8 100644 --- a/lnbits/core/views/generic.py +++ b/lnbits/core/views/generic.py @@ -35,7 +35,9 @@ from ..crud import ( ) from ..services import pay_invoice, redeem_lnurl_withdraw -core_html_routes: APIRouter = APIRouter(tags=["Core NON-API Website Routes"]) +core_html_routes: APIRouter = APIRouter( + tags=["Core NON-API Website Routes"], include_in_schema=False +) @core_html_routes.get("/favicon.ico", response_class=FileResponse) diff --git a/lnbits/settings.py b/lnbits/settings.py index 9315c46f0..64ab5faa2 100644 --- a/lnbits/settings.py +++ b/lnbits/settings.py @@ -268,6 +268,7 @@ class EnvSettings(LNbitsSettings): host: str = Field(default="127.0.0.1") port: int = Field(default=5000) forwarded_allow_ips: str = Field(default="*") + lnbits_title: str = Field(default="LNbits API") lnbits_path: str = Field(default=".") lnbits_commit: str = Field(default="unknown") super_user: str = Field(default="")