Skip to content

Commit

Permalink
feat(cli): Remove unused import and variable
Browse files Browse the repository at this point in the history
The commit removes an unused import and variable in the `cli.py` file. The import for `Content` from the models module is removed, as it is not being used in the code.

fix(config): Add temporary work directory for replay processing

This commit adds a new configuration option to the `default.toml` file. The `temp_workdir` setting specifies the temporary directory path for replay processing. The default value is set to "/tmp/wowskarma/minimap".

refactor(routes): Update filepath handling in render_replay function

In this commit, the filepath handling in the `render_replay` function of the `render.py` file is updated. Instead of using a hardcoded path, it now uses the configured temporary work directory from settings. Additionally, pathlib.Path is used to concatenate filepaths and ensure platform compatibility.
  • Loading branch information
SakuraIsayeki committed Jul 21, 2023
1 parent 90b3e5a commit 192acb1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 0 additions & 2 deletions wowskarma_api_minimap/src/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from .app import app
from .config import settings
from .db import create_db_and_tables, engine
from .models.content import Content
from .security import User

cli = typer.Typer(name="WOWS Karma - Minimap API")
Expand Down Expand Up @@ -53,7 +52,6 @@ def shell(): # pragma: no cover
"create_user": create_user,
"select": select,
"session": Session(engine),
"Content": Content,
}
typer.echo(f"Auto imports: {list(_vars.keys())}")
try:
Expand Down
3 changes: 2 additions & 1 deletion wowskarma_api_minimap/src/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ connect_args = {check_same_thread=false}
echo = false

[default.replay]
max_file_size = 5242880 # Max replay file size in bytes. Default is 5MB
max_file_size = 5242880 # Max replay file size in bytes. Default is 5MB
temp_workdir = "/tmp/wowskarma/minimap" # Temporary directory for replay processing
8 changes: 5 additions & 3 deletions wowskarma_api_minimap/src/routes/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import tempfile
import os

import pathlib
from fastapi import APIRouter, HTTPException, status, UploadFile, BackgroundTasks
from fastapi.responses import FileResponse
from renderer.data import ReplayData
Expand Down Expand Up @@ -43,20 +44,21 @@ async def render_replay(
# /tmp/wows-karma/minimap/

# Ensure the folder exists, if not, create it.
os.makedirs("/tmp/wows-karma/minimap/", exist_ok=True)
os.makedirs(settings.replay.temp_workdir, exist_ok=True)

# Render time!
replay_info = ReplayParser(file.file, True).get_info()
replay_data: ReplayData = replay_info["hidden"]["replay_data"]

filepath = f"/tmp/wows-karma/minimap/{binascii.b2a_hex(os.urandom(7))}.mp4"
# Concat filepaths to get the full path to the replay file.
filepath = pathlib.Path(settings.replay.temp_workdir, f"{binascii.b2a_hex(os.urandom(7))}.mp4")
renderer = Renderer(
replay_data,
enable_chat=True,
team_tracers=True,
target_player_id=target_player_id
)
renderer.start(filepath)
renderer.start(str(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 192acb1

Please sign in to comment.