Skip to content

Commit

Permalink
Get docker-compose working, 500 error on failure
Browse files Browse the repository at this point in the history
The docker-compose.yml setting now works for the new cache dir.

This emits a 500 Server Error if something goes wrong now.
  • Loading branch information
obscurerichard committed Jan 16, 2025
1 parent 8c61c48 commit bea4ca0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ services:
ports:
- "${FREEZING_WEB_PORT:-8000}:8000"
volumes:
- ./data/cache:/data/cache
- ./data/cache:/cache
- ./leaderboards:/data/leaderboards
- ./data/sessions:/data/sessions
environment:
Expand Down
31 changes: 18 additions & 13 deletions freezing/web/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,19 +410,24 @@ def _get_cached(key: str, compute):
return compute()

cache_file = Path(cache_dir).joinpath(key).resolve()

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
This path depends on a
user-provided value
.
if not str(cache_file).startswith(str(Path(cache_dir).resolve())):
raise Exception("Invalid cache file path")
if cache_file.is_file():
time_stamp = datetime.datetime.fromtimestamp(cache_file.stat().st_mtime)
age = datetime.datetime.now() - time_stamp
if age.total_seconds() < config.JSON_CACHE_MINUTES * 60:
return cache_file.read_bytes()

content = compute()
cache_file.parent.mkdir(parents=True, exist_ok=True)
cache_file.write_bytes(content)

return content
try:
if not str(cache_file).startswith(str(Path(cache_dir).resolve())):
raise Exception("Invalid cache file path")
if cache_file.is_file():

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
This path depends on a
user-provided value
.
time_stamp = datetime.datetime.fromtimestamp(cache_file.stat().st_mtime)

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
This path depends on a
user-provided value
.
age = datetime.datetime.now() - time_stamp
if age.total_seconds() < config.JSON_CACHE_MINUTES * 60:
return cache_file.read_bytes()

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
This path depends on a
user-provided value
.

content = compute()
cache_file.parent.mkdir(parents=True, exist_ok=True)

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
This path depends on a
user-provided value
.
cache_file.write_bytes(content)

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
This path depends on a
user-provided value
.

return content
except Exception as e:
err = f"Error retrieving cached item {key}: {e}"
log.exception(err)
abort(500, err)


def _make_gzip_json_response(content, private=False):
Expand Down

0 comments on commit bea4ca0

Please sign in to comment.