diff options
author | Frederick Muriuki Muriithi | 2025-01-21 14:52:40 -0600 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-01-21 14:52:40 -0600 |
commit | 6ff5fa52c08d825c4ac275a75b228f3b4bf83eff (patch) | |
tree | 5af71eb6ac8a73984935de9b10a48c52c8096ab4 /uploader | |
parent | 9843ed55d0eea4d4d7a227419f20532c25e52ba1 (diff) | |
download | gn-uploader-6ff5fa52c08d825c4ac275a75b228f3b4bf83eff.tar.gz |
Make filename hashing optional.
Diffstat (limited to 'uploader')
-rw-r--r-- | uploader/files/functions.py | 11 |
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() |