mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-03-15 12:20:21 +01:00
Merge pull request #1291 from lnbits/lnurldevicefix
swaps incremental id for small uuid for pos/atm
This commit is contained in:
commit
fce1a96736
1 changed files with 3 additions and 12 deletions
|
@ -1,5 +1,7 @@
|
||||||
from typing import List, Optional, Union
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
|
import shortuuid
|
||||||
|
|
||||||
from lnbits.helpers import urlsafe_short_hash
|
from lnbits.helpers import urlsafe_short_hash
|
||||||
|
|
||||||
from . import db
|
from . import db
|
||||||
|
@ -12,7 +14,7 @@ async def create_lnurldevice(
|
||||||
data: createLnurldevice,
|
data: createLnurldevice,
|
||||||
) -> lnurldevices:
|
) -> lnurldevices:
|
||||||
if data.device == "pos" or data.device == "atm":
|
if data.device == "pos" or data.device == "atm":
|
||||||
lnurldevice_id = str(await get_lnurldeviceposcount())
|
lnurldevice_id = shortuuid.uuid()[:5]
|
||||||
else:
|
else:
|
||||||
lnurldevice_id = urlsafe_short_hash()
|
lnurldevice_id = urlsafe_short_hash()
|
||||||
lnurldevice_key = urlsafe_short_hash()
|
lnurldevice_key = urlsafe_short_hash()
|
||||||
|
@ -82,17 +84,6 @@ 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,)
|
||||||
|
|
Loading…
Add table
Reference in a new issue