Merge pull request #1236 from lnbits/lnurldeviceshorten

Swaps UUID for number, to reduce URL size
This commit is contained in:
Arc 2022-12-23 22:56:40 +00:00 committed by GitHub
commit e541f0224c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -11,7 +11,10 @@ from .models import createLnurldevice, lnurldevicepayment, lnurldevices
async def create_lnurldevice(
data: createLnurldevice,
) -> lnurldevices:
lnurldevice_id = urlsafe_short_hash()
if data.device == "pos" or data.device == "atm":
lnurldevice_id = str(await get_lnurldeviceposcount())
else:
lnurldevice_id = urlsafe_short_hash()
lnurldevice_key = urlsafe_short_hash()
await db.execute(
"""
@ -79,6 +82,17 @@ async def update_lnurldevice(lnurldevice_id: str, **kwargs) -> Optional[lnurldev
return lnurldevices(**row) if row else None
async def get_lnurldeviceposcount() -> int:
row = await db.fetchall(
"SELECT * FROM lnurldevice.lnurldevices WHERE device = ? OR device = ?",
(
"pos",
"atm",
),
)
return len(row) + 1
async def get_lnurldevice(lnurldevice_id: str) -> lnurldevices:
row = await db.fetchone(
"SELECT * FROM lnurldevice.lnurldevices WHERE id = ?", (lnurldevice_id,)

View File

@ -17,8 +17,8 @@ class createLnurldevice(BaseModel):
wallet: str
currency: str
device: str
profit: float
amount: int
profit: float = 0
amount: Optional[int] = 0
pin: int = 0
profit1: float = 0
amount1: int = 0