Логирование использования токенов и мелкие доработки.
This commit is contained in:
+15
-4
@@ -6,6 +6,7 @@ from statistics import median
|
||||
from db import *
|
||||
from call2api import check_user_token, user_in_db, transfer_coins, get_stats, create_invoice, delete_invoice, \
|
||||
get_invoice
|
||||
from func import log
|
||||
|
||||
|
||||
#------------------------------------------------------------
|
||||
@@ -94,6 +95,7 @@ async def user_in_db_api(
|
||||
):
|
||||
if not token_check(username, user_token):
|
||||
raise HTTPException(status_code=401, detail='Invalid username or token')
|
||||
await log(session, user_token, f'/user_in_db')
|
||||
return await user_in_db(token=SYSTEM_API_TOKEN, username=username)
|
||||
|
||||
@app.post('/api/transfer_coins/')
|
||||
@@ -106,46 +108,55 @@ async def transfer_coins_api(
|
||||
):
|
||||
if not token_check(username, user_token):
|
||||
raise HTTPException(status_code=401, detail='Invalid username or token')
|
||||
await log(session, user_token, f'/transfer_coins: (dst_username: {dst_username}, amount: {amount})')
|
||||
return await transfer_coins(token=SYSTEM_API_TOKEN, src_username=username
|
||||
, dst_username=dst_username, amount=amount)
|
||||
|
||||
@app.post('/api/get_stats/')
|
||||
async def get_stats_api(
|
||||
username: str = Body(),
|
||||
user_token: str = Body()
|
||||
user_token: str = Body(),
|
||||
session: AsyncSession = Depends(get_session)
|
||||
):
|
||||
if not token_check(username, user_token):
|
||||
raise HTTPException(status_code=401, detail='Invalid username or token')
|
||||
await log(session, user_token, f'/get_stats')
|
||||
return await get_stats(token=SYSTEM_API_TOKEN)
|
||||
|
||||
@app.post('/api/create_invoice/')
|
||||
async def create_invoice_api(
|
||||
username: str = Body(),
|
||||
user_token: str = Body(),
|
||||
amount: float | None = Body(None)
|
||||
amount: float | None = Body(None),
|
||||
session: AsyncSession = Depends(get_session)
|
||||
):
|
||||
if not token_check(username, user_token):
|
||||
raise HTTPException(status_code=401, detail='Invalid username or token')
|
||||
await log(session, user_token, f'/create_invoice: (amount: {amount})')
|
||||
return await create_invoice(token=SYSTEM_API_TOKEN, dst_username=username, amount=amount)
|
||||
|
||||
@app.post('/api/delete_invoice/')
|
||||
async def delete_invoice_api(
|
||||
username: str = Body(),
|
||||
user_token: str = Body(),
|
||||
id: str = Body()
|
||||
id: str = Body(),
|
||||
session: AsyncSession = Depends(get_session)
|
||||
):
|
||||
if not token_check(username, user_token):
|
||||
raise HTTPException(status_code=401, detail='Invalid username or token')
|
||||
await log(session, user_token, f'/delete_invoice: (id: {id})')
|
||||
return await delete_invoice(token=SYSTEM_API_TOKEN, id=id)
|
||||
|
||||
@app.post('/api/get_invoice/')
|
||||
async def get_invoice_api(
|
||||
username: str = Body(),
|
||||
user_token: str = Body(),
|
||||
id: str = Body()
|
||||
id: str = Body(),
|
||||
session: AsyncSession = Depends(get_session)
|
||||
):
|
||||
if not token_check(username, user_token):
|
||||
raise HTTPException(status_code=401, detail='Invalid username or token')
|
||||
await log(session, user_token, f'/get_invoice: (id: {id})')
|
||||
return await get_invoice(token=SYSTEM_API_TOKEN, id=id)
|
||||
|
||||
#------------------------- END ------------------------------
|
||||
|
||||
Reference in New Issue
Block a user