aboutsummaryrefslogtreecommitdiff
path: root/qc_app
diff options
context:
space:
mode:
Diffstat (limited to 'qc_app')
-rw-r--r--qc_app/files.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/qc_app/files.py b/qc_app/files.py
index 0304296..205a39c 100644
--- a/qc_app/files.py
+++ b/qc_app/files.py
@@ -1,6 +1,8 @@
"""Utilities to deal with uploaded files."""
+import hashlib
from pathlib import Path
from typing import Union
+from datetime import datetime
from werkzeug.utils import secure_filename
from werkzeug.datastructures import FileStorage
@@ -9,7 +11,10 @@ def save_file(fileobj: FileStorage, upload_dir: Path) -> Union[Path, bool]:
"""Save the uploaded file and return the path."""
if not bool(fileobj):
return False
- filename = Path(secure_filename(fileobj.filename)) # type: ignore[arg-type]
+ hashed_name = hashlib.sha512(
+ f"{fileobj.filename}::{datetime.now().isoformat()}".encode("utf8")
+ ).hexdigest()
+ filename = Path(secure_filename(hashed_name)) # type: ignore[arg-type]
if not upload_dir.exists():
upload_dir.mkdir()