From 6ff5fa52c08d825c4ac275a75b228f3b4bf83eff Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 21 Jan 2025 14:52:40 -0600 Subject: Make filename hashing optional. --- uploader/files/functions.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'uploader') 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() -- cgit v1.2.3