about summary refs log tree commit diff
diff options
context:
space:
mode:
-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()