aboutsummaryrefslogtreecommitdiff
path: root/uploader
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-01-21 14:52:40 -0600
committerFrederick Muriuki Muriithi2025-01-21 14:52:40 -0600
commit6ff5fa52c08d825c4ac275a75b228f3b4bf83eff (patch)
tree5af71eb6ac8a73984935de9b10a48c52c8096ab4 /uploader
parent9843ed55d0eea4d4d7a227419f20532c25e52ba1 (diff)
downloadgn-uploader-6ff5fa52c08d825c4ac275a75b228f3b4bf83eff.tar.gz
Make filename hashing optional.
Diffstat (limited to 'uploader')
-rw-r--r--uploader/files/functions.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/uploader/files/functions.py b/uploader/files/functions.py
index 5a3dece..7b9f06b 100644
--- a/uploader/files/functions.py
+++ b/uploader/files/functions.py
@@ -10,12 +10,15 @@ from werkzeug.datastructures import FileStorage
from .chunks import chunked_binary_read
-def save_file(fileobj: FileStorage, upload_dir: Path) -> Path:
+def save_file(fileobj: FileStorage, upload_dir: Path, hashed: bool = True) -> Path:
"""Save the uploaded file and return the path."""
assert bool(fileobj), "Invalid file object!"
- hashed_name = hashlib.sha512(
- f"{fileobj.filename}::{datetime.now().isoformat()}".encode("utf8")
- ).hexdigest()
+ hashed_name = (
+ hashlib.sha512(
+ f"{fileobj.filename}::{datetime.now().isoformat()}".encode("utf8")
+ ).hexdigest()
+ if hashed else
+ fileobj.filename)
filename = Path(secure_filename(hashed_name)) # type: ignore[arg-type]
if not upload_dir.exists():
upload_dir.mkdir()