checks if hostname is .onion and change scheme (#11)

* checks if hostname is .onion and change scheme
* resolve @motorina0 's comments
This commit is contained in:
Tiago Vasconcelos 2023-09-24 19:22:48 +01:00 committed by GitHub
commit 049826071c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 5 deletions

View file

@ -3,10 +3,10 @@ from sqlite3 import Row
from typing import Dict, Optional
from urllib.parse import ParseResult, urlparse, urlunparse
from fastapi import Request
from fastapi.param_functions import Query
from lnurl.types import LnurlPayMetadata
from pydantic import BaseModel
from starlette.requests import Request
from lnbits.lnurl import encode as lnurl_encode
@ -55,8 +55,13 @@ class PayLink(BaseModel):
data["max"] /= data["fiat_base_multiplier"]
return cls(**data)
def lnurl(self, req: Request) -> str:
def lnurl(self, req: Request) -> str:
url = req.url_for("lnurlp.api_lnurl_response", link_id=self.id)
# 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 lnurl_encode(str(url))
def success_action(self, payment_hash: str) -> Optional[Dict]: