aboutsummaryrefslogtreecommitdiff
path: root/qc_app/files.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-07-25 11:07:33 -0500
committerFrederick Muriuki Muriithi2024-07-25 14:34:09 -0500
commit754e8f214b940e05298cb360ed829f5c685d55a5 (patch)
tree62c2c5b601746621f0949b38937ad232f006dee2 /qc_app/files.py
parentde9e1b9fe37928b864bea28b408de6c14d04526b (diff)
downloadgn-uploader-754e8f214b940e05298cb360ed829f5c685d55a5.tar.gz
Rename module: qc_app --> uploader
Diffstat (limited to 'qc_app/files.py')
-rw-r--r--qc_app/files.py26
1 files changed, 0 insertions, 26 deletions
diff --git a/qc_app/files.py b/qc_app/files.py
deleted file mode 100644
index b163612..0000000
--- a/qc_app/files.py
+++ /dev/null
@@ -1,26 +0,0 @@
-"""Utilities to deal with uploaded files."""
-import hashlib
-from pathlib import Path
-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) -> 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()
- filename = Path(secure_filename(hashed_name)) # type: ignore[arg-type]
- if not upload_dir.exists():
- upload_dir.mkdir()
-
- filepath = Path(upload_dir, filename)
- fileobj.save(filepath)
- return filepath
-
-def fullpath(filename: str):
- """Get a file's full path. This makes use of `flask.current_app`."""
- return Path(current_app.config["UPLOAD_FOLDER"], filename).absolute()