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
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( async def create_lnurldevice(
data: createLnurldevice, data: createLnurldevice,
) -> lnurldevices: ) -> 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() lnurldevice_key = urlsafe_short_hash()
await db.execute( await db.execute(
""" """
@@ -79,6 +82,17 @@ async def update_lnurldevice(lnurldevice_id: str, **kwargs) -> Optional[lnurldev
return lnurldevices(**row) if row else None 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: async def get_lnurldevice(lnurldevice_id: str) -> lnurldevices:
row = await db.fetchone( row = await db.fetchone(
"SELECT * FROM lnurldevice.lnurldevices WHERE id = ?", (lnurldevice_id,) "SELECT * FROM lnurldevice.lnurldevices WHERE id = ?", (lnurldevice_id,)

View File

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