Skip to content

Commit

Permalink
Add logging for osu! file fetch api call
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyui committed Jun 30, 2024
1 parent ea429a3 commit 75036fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
10 changes: 9 additions & 1 deletion app/adapters/osu_api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ async def fetch_one_beatmap(
},
)
logging.info(
"Made authorized request to the v1 osu! api",
"Made request to the v1 osu! api",
extra={
"endpoint": "get_beatmaps",
"api_key_last4": osu_api_v1_key[-4:],
"authorized": True,
},
)
if response.status_code == 404:
Expand All @@ -105,6 +106,13 @@ async def fetch_one_beatmap(
async def fetch_beatmap_osu_file_data(beatmap_id: int) -> bytes | None:
try:
response = await osu_api_v1_http_client.get(f"osu/{beatmap_id}")
logging.info(
"Made request to the v1 osu! api",
extra={
"endpoint": "osu_file",
"authorized": False,
},
)
if response.status_code == 404:
return None
if response.status_code == 403:
Expand Down
18 changes: 9 additions & 9 deletions app/api/internal/v1/osu_api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ async def download_beatmap_osu_file(beatmap_id: int) -> Response:
beatmap_osu_file_data = await osu_api_v1.fetch_beatmap_osu_file_data(beatmap_id)
# TODO: consider at which points in beatmaps-service we should update
# the .osu file that is currently saved in wasabi s3 storage.
if beatmap_osu_file_data is not None:
return Response(
beatmap_osu_file_data,
media_type="application/octet-stream",
headers={
"Content-Disposition": f"attachment; filename={beatmap_id}.osu",
},
)
if beatmap_osu_file_data is None:
return Response(status_code=404)

return Response(status_code=404)
return Response(
beatmap_osu_file_data,
media_type="application/octet-stream",
headers={
"Content-Disposition": f"attachment; filename={beatmap_id}.osu",
},
)

0 comments on commit 75036fc

Please sign in to comment.