Add a secondary route with the card_uid appended to it.

This commit is contained in:
Lee Salminen 2022-08-21 08:58:38 -06:00
parent db83d803f8
commit 4242a82029
2 changed files with 25 additions and 12 deletions

View File

@ -82,6 +82,14 @@ async def get_card(card_id: str) -> Optional[Card]:
return Card.parse_obj(card)
async def get_card_by_uid(card_uid: str) -> Optional[Card]:
row = await db.fetchone("SELECT * FROM boltcards.cards WHERE uid = ?", (card_uid,))
if not row:
return None
card = dict(**row)
return Card.parse_obj(card)
async def get_card_by_otp(otp: str) -> Optional[Card]:
row = await db.fetchone("SELECT * FROM boltcards.cards WHERE otp = ?", (otp,))

View File

@ -25,6 +25,7 @@ from .crud import (
get_all_cards,
get_card,
get_card_by_otp,
get_card_by_uid,
get_cards,
get_hits,
update_card,
@ -131,13 +132,15 @@ async def api_hits(
# /boltcards/api/v1/scan?p=00000000000000000000000000000000&c=0000000000000000
@boltcards_ext.get("/api/v1/scan")
async def api_scane(p, c, request: Request):
@boltcards_ext.get("/api/v1/scan/{card_uid}")
async def api_scane(p, c, card_uid: str = None, request: Request):
# some wallets send everything as lower case, no bueno
p = p.upper()
c = c.upper()
card = None
counter = b""
if not card_uid:
# since this route is common to all cards I don't know whitch 'meta key' to use
# so I try one by one until decrypted uid matches
for cand in await get_all_cards():
@ -150,6 +153,8 @@ async def api_scane(p, c, request: Request):
break
except:
continue
else:
card = await get_card_by_uid(card_uid)
if card == None:
return {"status": "ERROR", "reason": "Unknown card."}