mirror of
https://github.com/jointakahe/takahe.git
synced 2025-06-05 18:28:49 +00:00
Tweak to predictable image namer
This commit is contained in:
parent
b5895e4d28
commit
5e343d2129
1 changed files with 7 additions and 4 deletions
|
@ -20,10 +20,13 @@ def upload_namer(prefix, instance, filename):
|
||||||
_, old_extension = os.path.splitext(filename)
|
_, old_extension = os.path.splitext(filename)
|
||||||
|
|
||||||
if prefix == "profile_images":
|
if prefix == "profile_images":
|
||||||
# If we're saving images for an Identity, we only keep the most recently
|
# If we're saving images for an Identity, we name predictably as
|
||||||
# received. Ideally, we should hash the file content and de-duplicate
|
# avatar images are not considered "secret", and otherwise we'll waste
|
||||||
# but this is the easy and immediate solution.
|
# space.
|
||||||
return f"{prefix}/{urllib.parse.quote(instance.handle)}{old_extension}"
|
handle_safe = urllib.parse.quote(instance.handle)
|
||||||
|
return (
|
||||||
|
f"{prefix}/{handle_safe[:2]}/{handle_safe[:4]}/{handle_safe}{old_extension}"
|
||||||
|
)
|
||||||
|
|
||||||
new_filename = secrets.token_urlsafe(20)
|
new_filename = secrets.token_urlsafe(20)
|
||||||
now = timezone.now()
|
now = timezone.now()
|
||||||
|
|
Loading…
Reference in a new issue