mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-28 21:02:31 +02:00
retreiving hits
This commit is contained in:
@@ -101,16 +101,13 @@ async def get_hit(hit_id: str) -> Optional[Hit]:
|
|||||||
|
|
||||||
return Hit.parse_obj(hit)
|
return Hit.parse_obj(hit)
|
||||||
|
|
||||||
async def get_hits(wallet_ids: Union[str, List[str]]) -> List[Hit]:
|
async def get_hits(cards_ids: Union[str, List[str]]) -> List[Hit]:
|
||||||
|
q = ",".join(["?"] * len(cards_ids))
|
||||||
cards = get_cards(wallet_ids)
|
|
||||||
|
|
||||||
q = ",".join(["?"] * len(cards))
|
|
||||||
rows = await db.fetchall(
|
rows = await db.fetchall(
|
||||||
f"SELECT * FROM boltcards.hits WHERE wallet IN ({q})", (*(card.card_id for card in cards),)
|
f"SELECT * FROM boltcards.hits WHERE card_id IN ({q})", (*cards_ids,)
|
||||||
)
|
)
|
||||||
|
|
||||||
return [Card(**row) for row in rows]
|
return [Hit(**row) for row in rows]
|
||||||
|
|
||||||
async def create_hit(
|
async def create_hit(
|
||||||
card_id, ip, useragent, old_ctr, new_ctr
|
card_id, ip, useragent, old_ctr, new_ctr
|
||||||
|
@@ -28,12 +28,3 @@ class Hit(BaseModel):
|
|||||||
old_ctr: int
|
old_ctr: int
|
||||||
new_ctr: int
|
new_ctr: int
|
||||||
time: int
|
time: int
|
||||||
|
|
||||||
'''
|
|
||||||
class CreateHitData(BaseModel):
|
|
||||||
card_id: str = Query(...)
|
|
||||||
ip: str = Query(...)
|
|
||||||
useragent: str = Query(...)
|
|
||||||
old_ctr: int = Query(...)
|
|
||||||
new_ctr: int = Query(...)
|
|
||||||
'''
|
|
||||||
|
@@ -368,7 +368,6 @@
|
|||||||
if (this.g.user.wallets.length) {
|
if (this.g.user.wallets.length) {
|
||||||
this.getCards()
|
this.getCards()
|
||||||
this.getWithdraws()
|
this.getWithdraws()
|
||||||
this.getHits()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@@ -24,6 +24,7 @@ from .crud import (
|
|||||||
get_cards,
|
get_cards,
|
||||||
get_card,
|
get_card,
|
||||||
create_card,
|
create_card,
|
||||||
|
get_hits,
|
||||||
update_card,
|
update_card,
|
||||||
delete_card,
|
delete_card,
|
||||||
update_card_counter
|
update_card_counter
|
||||||
@@ -102,6 +103,22 @@ async def api_link_delete(card_id, wallet: WalletTypeInfo = Depends(require_admi
|
|||||||
await delete_card(card_id)
|
await delete_card(card_id)
|
||||||
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||||
|
|
||||||
|
@boltcards_ext.get("/api/v1/hits")
|
||||||
|
async def api_hits(
|
||||||
|
g: WalletTypeInfo = Depends(get_key_type), all_wallets: bool = Query(False)
|
||||||
|
):
|
||||||
|
wallet_ids = [g.wallet.id]
|
||||||
|
|
||||||
|
if all_wallets:
|
||||||
|
wallet_ids = (await get_user(g.wallet.user)).wallet_ids
|
||||||
|
|
||||||
|
cards = await get_cards(wallet_ids)
|
||||||
|
cards_ids = []
|
||||||
|
for card in cards:
|
||||||
|
cards_ids.append(card.id)
|
||||||
|
|
||||||
|
return [hit.dict() for hit in await get_hits(cards_ids)]
|
||||||
|
|
||||||
@boltcards_ext.get("/api/v1/scan/") # pay.btcslovnik.cz/boltcards/api/v1/scan/?uid=00000000000000&ctr=000000&c=0000000000000000
|
@boltcards_ext.get("/api/v1/scan/") # pay.btcslovnik.cz/boltcards/api/v1/scan/?uid=00000000000000&ctr=000000&c=0000000000000000
|
||||||
async def api_scan(
|
async def api_scan(
|
||||||
uid, ctr, c,
|
uid, ctr, c,
|
||||||
@@ -124,8 +141,17 @@ async def api_scan(
|
|||||||
|
|
||||||
await update_card_counter(ctr_int, card.id)
|
await update_card_counter(ctr_int, card.id)
|
||||||
|
|
||||||
link = await get_withdraw_link(card.withdraw, 0)
|
ip = request.client.host
|
||||||
|
if request.headers['x-real-ip']:
|
||||||
|
ip = request.headers['x-real-ip']
|
||||||
|
elif request.headers['x-forwarded-for']:
|
||||||
|
ip = request.headers['x-forwarded-for']
|
||||||
|
|
||||||
|
agent = request.headers['user-agent'] if 'user-agent' in request.headers else ''
|
||||||
|
|
||||||
|
await create_hit(card.id, ip, agent, card.counter, ctr_int)
|
||||||
|
|
||||||
|
link = await get_withdraw_link(card.withdraw, 0)
|
||||||
return link.lnurl_response(request)
|
return link.lnurl_response(request)
|
||||||
|
|
||||||
@boltcards_ext.get("/api/v1/scane/")
|
@boltcards_ext.get("/api/v1/scane/")
|
||||||
@@ -152,8 +178,8 @@ async def api_scane(
|
|||||||
print(getSunMAC(card_uid, counter, bytes.fromhex(card.file_key)).hex().upper())
|
print(getSunMAC(card_uid, counter, bytes.fromhex(card.file_key)).hex().upper())
|
||||||
return {"status": "ERROR", "reason": "CMAC does not check."}
|
return {"status": "ERROR", "reason": "CMAC does not check."}
|
||||||
|
|
||||||
counter_int = int.from_bytes(counter, "little")
|
ctr_int = int.from_bytes(counter, "little")
|
||||||
if counter_int <= card.counter:
|
if ctr_int <= card.counter:
|
||||||
return {"status": "ERROR", "reason": "This link is already used."}
|
return {"status": "ERROR", "reason": "This link is already used."}
|
||||||
|
|
||||||
await update_card_counter(counter_int, card.id)
|
await update_card_counter(counter_int, card.id)
|
||||||
@@ -164,7 +190,9 @@ async def api_scane(
|
|||||||
elif request.headers['x-forwarded-for']:
|
elif request.headers['x-forwarded-for']:
|
||||||
ip = request.headers['x-forwarded-for']
|
ip = request.headers['x-forwarded-for']
|
||||||
|
|
||||||
await create_hit(card.id, ip, request.headers['user-agent'], card.counter, counter_int)
|
agent = request.headers['user-agent'] if 'user-agent' in request.headers else ''
|
||||||
|
|
||||||
|
await create_hit(card.id, ip, agent, card.counter, ctr_int)
|
||||||
|
|
||||||
link = await get_withdraw_link(card.withdraw, 0)
|
link = await get_withdraw_link(card.withdraw, 0)
|
||||||
return link.lnurl_response(request)
|
return link.lnurl_response(request)
|
||||||
|
Reference in New Issue
Block a user