diff options
author | Frederick Muriuki Muriithi | 2024-02-09 04:22:51 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-02-12 18:17:38 +0300 |
commit | 4c077c01db19e8adc01d9559677ad5693a1db909 (patch) | |
tree | 3aeedc2ef8b18aa5a6bddb162531487687ae11e9 /qc_app/files.py | |
parent | dd369b846524fed0c08d1b7318fd73478506c3ee (diff) | |
download | gn-uploader-4c077c01db19e8adc01d9559677ad5693a1db909.tar.gz |
Raise error if file is missing rather than returning a Union value.
Diffstat (limited to 'qc_app/files.py')
-rw-r--r-- | qc_app/files.py | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/qc_app/files.py b/qc_app/files.py index baac5ec..b163612 100644 --- a/qc_app/files.py +++ b/qc_app/files.py @@ -1,17 +1,15 @@ """Utilities to deal with uploaded files.""" import hashlib from pathlib import Path -from typing import Union from datetime import datetime from flask import current_app from werkzeug.utils import secure_filename from werkzeug.datastructures import FileStorage -def save_file(fileobj: FileStorage, upload_dir: Path) -> Union[Path, bool]: +def save_file(fileobj: FileStorage, upload_dir: Path) -> Path: """Save the uploaded file and return the path.""" - if not bool(fileobj): - return False + assert bool(fileobj), "Invalid file object!" hashed_name = hashlib.sha512( f"{fileobj.filename}::{datetime.now().isoformat()}".encode("utf8") ).hexdigest() |