From 1176fd032221134c3754c79254bf7ef3de27b24a Mon Sep 17 00:00:00 2001 From: bitkarrot <73979971+bitkarrot@users.noreply.github.com> Date: Thu, 2 Mar 2023 22:10:18 -0800 Subject: [PATCH] add redirect paths --- __init__.py | 11 +++++++++++ views_api.py | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/__init__.py b/__init__.py index aa13bb9..0d6bb20 100644 --- a/__init__.py +++ b/__init__.py @@ -17,6 +17,17 @@ lnurlp_static_files = [ "name": "lnurlp_static", } ] + +lnurlp_redirect_paths = [ + { + "from_path": "/.well-known/lnurlp", + "redirect_to_path": "/api/v1/well-known", + "header_filters": { + "accept": "application/json" + } + } +] + scheduled_tasks: List[asyncio.Task] = [] lnurlp_ext: APIRouter = APIRouter(prefix="/lnurlp", tags=["lnurlp"]) diff --git a/views_api.py b/views_api.py index b4af294..624406f 100644 --- a/views_api.py +++ b/views_api.py @@ -1,6 +1,7 @@ import json from asyncio.log import logger from http import HTTPStatus +from urllib.parse import urlparse from fastapi import Depends, Query, Request from lnurl.exceptions import InvalidUrl as LnurlInvalidUrl @@ -19,6 +20,12 @@ from .crud import ( update_pay_link, ) from .models import CreatePayLinkData +from .lnurl import lnurl_response + +@lnurlp_ext.get("/api/v1/well-known/{username}") +async def lnaddress(username: str, request: Request): + domain = urlparse(str(request.url)).netloc + return await lnurl_response(username, domain, request) @lnurlp_ext.get("/api/v1/currencies")