Skip to content

Commit

Permalink
hasing support
Browse files Browse the repository at this point in the history
  • Loading branch information
pschrammel committed Jun 24, 2024
1 parent 3291c1b commit cd97b33
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions thumbor_aws/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from urllib.parse import unquote

from hashlib import sha256

def normalize_path(prefix: str, path: str) -> str:
"""Convert a URL received from Thumbor to a key in a S3 bucket."""
# Thumbor calls load/store functions with a URL that is URL-encoded and
# that always starts with a slash. S3Client doesn't expect URL-encoding
# and S3 keys don't usually start with a slash. Decode and remove slash.
path = unquote(path).lstrip("/")
# TBD: make the configurable
path = sha256(path.encode('utf-8')).hexdigest()
if prefix:
# Avoid double slash if prefix ends with a slash.
prefix = prefix.rstrip("/")
return f"{prefix}/{path}"
path = f"{prefix}/{path}"
return path

0 comments on commit cd97b33

Please sign in to comment.