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:
parent
7d32a36d51
commit
049826071c
3 changed files with 13 additions and 5 deletions
4
lnurl.py
4
lnurl.py
|
|
@ -1,7 +1,9 @@
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from fastapi import Request, Query
|
from fastapi import Query, Request
|
||||||
from lnurl import LnurlErrorResponse, LnurlPayActionResponse, LnurlPayResponse
|
from lnurl import LnurlErrorResponse, LnurlPayActionResponse, LnurlPayResponse
|
||||||
|
from loguru import logger
|
||||||
from starlette.exceptions import HTTPException
|
from starlette.exceptions import HTTPException
|
||||||
|
|
||||||
from lnbits.core.services import create_invoice
|
from lnbits.core.services import create_invoice
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@ from sqlite3 import Row
|
||||||
from typing import Dict, Optional
|
from typing import Dict, Optional
|
||||||
from urllib.parse import ParseResult, urlparse, urlunparse
|
from urllib.parse import ParseResult, urlparse, urlunparse
|
||||||
|
|
||||||
|
from fastapi import Request
|
||||||
from fastapi.param_functions import Query
|
from fastapi.param_functions import Query
|
||||||
from lnurl.types import LnurlPayMetadata
|
from lnurl.types import LnurlPayMetadata
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from starlette.requests import Request
|
|
||||||
|
|
||||||
from lnbits.lnurl import encode as lnurl_encode
|
from lnbits.lnurl import encode as lnurl_encode
|
||||||
|
|
||||||
|
|
@ -57,6 +57,11 @@ class PayLink(BaseModel):
|
||||||
|
|
||||||
def lnurl(self, req: Request) -> str:
|
def lnurl(self, req: Request) -> str:
|
||||||
url = req.url_for("lnurlp.api_lnurl_response", link_id=self.id)
|
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))
|
return lnurl_encode(str(url))
|
||||||
|
|
||||||
def success_action(self, payment_hash: str) -> Optional[Dict]:
|
def success_action(self, payment_hash: str) -> Optional[Dict]:
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,14 @@ from . import lnurlp_ext, scheduled_tasks
|
||||||
from .crud import (
|
from .crud import (
|
||||||
create_pay_link,
|
create_pay_link,
|
||||||
delete_pay_link,
|
delete_pay_link,
|
||||||
|
get_address_data,
|
||||||
get_pay_link,
|
get_pay_link,
|
||||||
get_pay_links,
|
get_pay_links,
|
||||||
update_pay_link,
|
update_pay_link,
|
||||||
get_address_data,
|
|
||||||
)
|
)
|
||||||
from .models import CreatePayLinkData
|
|
||||||
from .lnurl import api_lnurl_response
|
from .lnurl import api_lnurl_response
|
||||||
|
from .models import CreatePayLinkData
|
||||||
|
|
||||||
|
|
||||||
# redirected from /.well-known/lnurlp
|
# redirected from /.well-known/lnurlp
|
||||||
@lnurlp_ext.get("/api/v1/well-known/{username}")
|
@lnurlp_ext.get("/api/v1/well-known/{username}")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue