mirror of
https://github.com/NovaOSS/nova-api.git
synced 2024-11-25 20:23:58 +01:00
Update core.py
This commit is contained in:
parent
bd4fc0ad86
commit
60a89146da
17
api/core.py
17
api/core.py
|
@ -12,7 +12,14 @@ from dotenv import load_dotenv
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
router = fastapi.APIRouter(tags=['core'])
|
router = fastapi.APIRouter(tags=['core'])
|
||||||
|
|
||||||
|
|
||||||
async def check_core_auth(request):
|
async def check_core_auth(request):
|
||||||
|
"""
|
||||||
|
|
||||||
|
### Checks the request's auth
|
||||||
|
Auth is taken from environment variable `CORE_API_KEY`
|
||||||
|
|
||||||
|
"""
|
||||||
received_auth = request.headers.get('Authorization')
|
received_auth = request.headers.get('Authorization')
|
||||||
|
|
||||||
if received_auth != os.getenv('CORE_API_KEY'):
|
if received_auth != os.getenv('CORE_API_KEY'):
|
||||||
|
@ -20,14 +27,12 @@ async def check_core_auth(request):
|
||||||
|
|
||||||
@router.get('/users')
|
@router.get('/users')
|
||||||
async def get_users(discord_id: int, incoming_request: fastapi.Request):
|
async def get_users(discord_id: int, incoming_request: fastapi.Request):
|
||||||
auth_error = await check_core_auth(incoming_request)
|
auth = await check_core_auth(incoming_request)
|
||||||
|
if auth:
|
||||||
if auth_error:
|
|
||||||
return auth_error
|
return auth_error
|
||||||
|
|
||||||
user = await users.by_discord_id(discord_id)
|
# Get user by discord ID
|
||||||
|
if not await users.by_discord_id(discord_id):
|
||||||
if not user:
|
|
||||||
return fastapi.Response(status_code=404, content='User not found.')
|
return fastapi.Response(status_code=404, content='User not found.')
|
||||||
|
|
||||||
return user
|
return user
|
||||||
|
|
Loading…
Reference in a new issue