parent
8aefea7260
commit
badc420069
29 changed files with 3048 additions and 212 deletions
34
models.py
34
models.py
|
|
@ -1,15 +1,13 @@
|
|||
import json
|
||||
from sqlite3 import Row
|
||||
from typing import Dict, Optional
|
||||
from urllib.parse import ParseResult, urlparse, urlunparse
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import Request
|
||||
from fastapi.param_functions import Query
|
||||
from lnurl import encode as lnurl_encode
|
||||
from lnurl.types import LnurlPayMetadata
|
||||
from pydantic import BaseModel
|
||||
|
||||
from lnbits.lnurl import encode as lnurl_encode
|
||||
|
||||
from .helpers import parse_nostr_private_key
|
||||
from .nostr.key import PrivateKey
|
||||
|
||||
|
|
@ -19,7 +17,7 @@ class LnurlpSettings(BaseModel):
|
|||
|
||||
@property
|
||||
def private_key(self) -> PrivateKey:
|
||||
return parse_nostr_private_key(self.nostr_private_key)
|
||||
return parse_nostr_private_key(self.nostr_private_key)
|
||||
|
||||
@property
|
||||
def public_key(self) -> str:
|
||||
|
|
@ -72,29 +70,13 @@ class PayLink(BaseModel):
|
|||
return cls(**data)
|
||||
|
||||
def lnurl(self, req: Request) -> str:
|
||||
url = str(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"):
|
||||
url = req.url_for("lnurlp.api_lnurl_response", link_id=self.id)
|
||||
url_str = str(url)
|
||||
if url.netloc.endswith(".onion"):
|
||||
# change url string scheme to http
|
||||
url = url.replace("https://", "http://")
|
||||
url_str = url_str.replace("https://", "http://")
|
||||
|
||||
return lnurl_encode(url)
|
||||
|
||||
def success_action(self, payment_hash: str) -> Optional[Dict]:
|
||||
if self.success_url:
|
||||
url: ParseResult = urlparse(self.success_url)
|
||||
# qs = parse_qs(url.query)
|
||||
# setattr(qs, "payment_hash", payment_hash)
|
||||
# url = url._replace(query=urlencode(qs, doseq=True))
|
||||
return {
|
||||
"tag": "url",
|
||||
"description": self.success_text or "~",
|
||||
"url": urlunparse(url),
|
||||
}
|
||||
elif self.success_text:
|
||||
return {"tag": "message", "message": self.success_text}
|
||||
else:
|
||||
return None
|
||||
return lnurl_encode(url_str)
|
||||
|
||||
@property
|
||||
def lnurlpay_metadata(self) -> LnurlPayMetadata:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue