Skip to content

Commit

Permalink
feat(render): Add background task for removing temporary file
Browse files Browse the repository at this point in the history
This commit adds a new parameter `background_tasks` to the `render_replay` function in the `render.py` file. The purpose of this parameter is to allow for the addition of a background task that removes the temporary file after it has been rendered and returned as a response. This helps to clean up any leftover files and improve overall system efficiency.
  • Loading branch information
SakuraIsayeki committed Jul 21, 2023
1 parent bd9b553 commit 90b3e5a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion wowskarma_api_minimap/src/routes/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import tempfile
import os

from fastapi import APIRouter, HTTPException, status, UploadFile
from fastapi import APIRouter, HTTPException, status, UploadFile, BackgroundTasks
from fastapi.responses import FileResponse
from renderer.data import ReplayData
from renderer.render import Renderer
Expand All @@ -16,9 +16,12 @@
router = APIRouter()




@router.post("/render", dependencies=[AuthenticatedUser])
async def render_replay(
file: UploadFile,
background_tasks: BackgroundTasks,
replay_id: str | None = None,
target_player_id: int | None = None
):
Expand Down Expand Up @@ -55,4 +58,5 @@ async def render_replay(
)
renderer.start(filepath)

background_tasks.add_task(os.remove, filepath)
return FileResponse(filepath, media_type="video/mp4", filename=f"{replay_id or 'replay'}.mp4")

0 comments on commit 90b3e5a

Please sign in to comment.