summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-17 08:21:42 -0700
committerAndrew Godwin2022-11-17 12:21:44 -0700
commitf5eafb0ca0af3ed064202abbe99bfbeef8bbb74d (patch)
treed01453e94f371956e7e989351b51e6ed6eb42541 /core
parent7f8e792402b66dbb4a721be4f44306d528931b86 (diff)
downloadtakahe-f5eafb0ca0af3ed064202abbe99bfbeef8bbb74d.tar.gz
takahe-f5eafb0ca0af3ed064202abbe99bfbeef8bbb74d.tar.bz2
takahe-f5eafb0ca0af3ed064202abbe99bfbeef8bbb74d.zip
Add image/icon upload
Diffstat (limited to 'core')
-rw-r--r--core/uploads.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/core/uploads.py b/core/uploads.py
new file mode 100644
index 0000000..ef235f0
--- /dev/null
+++ b/core/uploads.py
@@ -0,0 +1,15 @@
+import base64
+import os
+import uuid
+
+from django.utils import timezone
+
+
+def upload_namer(prefix, instance, filename):
+ """
+ Names uploaded images, obscuring their original name with a random UUID.
+ """
+ now = timezone.now()
+ _, old_extension = os.path.splitext(filename)
+ new_filename = base64.b32encode(uuid.uuid4().bytes).decode("ascii")
+ return f"{prefix}/{now.year}/{now.month}/{now.day}/{new_filename}{old_extension}"