mirror of
https://github.com/lnbits/lnbits.git
synced 2025-10-10 12:32:34 +02:00
swaps incremental id for small uuid for pos/atm
This commit is contained in:
@@ -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()[:8]
|
||||||
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,)
|
||||||
|
Reference in New Issue
Block a user