From b2fcdffc0d511d685ff20a8b6e736f161312b363 Mon Sep 17 00:00:00 2001 From: Tiago Vasconcelos Date: Sun, 24 Sep 2023 19:14:47 +0100 Subject: [PATCH] check .onion and change scheme to http (#7) --- lnurl.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lnurl.py b/lnurl.py index 8851040..2f06426 100644 --- a/lnurl.py +++ b/lnurl.py @@ -1,6 +1,7 @@ import json from datetime import datetime from http import HTTPStatus +from urllib.parse import urlparse import httpx import shortuuid @@ -38,6 +39,12 @@ async def api_lnurl_response(request: Request, unique_hash: str): status_code=HTTPStatus.NOT_FOUND, detail="Withdraw is spent." ) url = request.url_for("withdraw.api_lnurl_callback", unique_hash=link.unique_hash) + + # Check if url is .onion and change to http + if urlparse(url).netloc.endswith(".onion"): + # change url string scheme to http + url = url.replace("https://", "http://") + return { "tag": "withdrawRequest", "callback": url, @@ -189,6 +196,12 @@ async def api_lnurl_multi_response(request: Request, unique_hash: str, id_unique ) url = request.url_for("withdraw.api_lnurl_callback", unique_hash=link.unique_hash) + + # Check if url is .onion and change to http + if urlparse(url).netloc.endswith(".onion"): + # change url string scheme to http + url = url.replace("https://", "http://") + return { "tag": "withdrawRequest", "callback": f"{url}?id_unique_hash={id_unique_hash}",