From 5705666ac0025ecc83c9cdb4ee0ebf94983ee069 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 26 Jan 2026 13:55:28 -0600 Subject: Move the UPLOAD_DIRECTORY under the SCRATCH_DIRECTORY by default. If the UPLOAD_DIRECTORY is not specified in the configuration file(s), then, by default, have it under the SCRATCH_DIRECTORY. --- uploader/__init__.py | 17 +++++++++++++++-- uploader/default_settings.py | 3 ++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/uploader/__init__.py b/uploader/__init__.py index a28ed8d..32eabba 100644 --- a/uploader/__init__.py +++ b/uploader/__init__.py @@ -78,9 +78,22 @@ def __setup_scratch_directory__(app: Flask) -> Flask: app.config["SCRATCH_DIRECTORY"]).absolute() return app -def update_unspecified_defaults(app: Flask): +def __setup_upload_directory__(app: Flask) -> Flask: + if app.config.get("UPLOAD_DIRECTORY", "").strip() == "": + app.config["UPLOAD_DIRECTORY"] = app.config[ + "SCRATCH_DIRECTORY"].joinpath("uploads") + else: + app.config["UPLOAD_DIRECTORY"] = Path( + app.config["UPLOAD_DIRECTORY"].strip()).absolute() + + return app + + +def update_unspecified_defaults(app: Flask) -> Flask: """Setup the defaults for necessary configurations that do not have values specified for them.""" - __setup_scratch_directory__(app) + return __setup_upload_directory__(__setup_scratch_directory__(app)) + + def create_app(config: Optional[dict] = None): """The application factory. diff --git a/uploader/default_settings.py b/uploader/default_settings.py index 75dc53a..0ac12e5 100644 --- a/uploader/default_settings.py +++ b/uploader/default_settings.py @@ -5,13 +5,14 @@ actual configuration file used for the production and staging systems. LOG_LEVEL = "WARNING" SECRET_KEY = b"" -UPLOAD_FOLDER = "/tmp/qc_app_files" # Scratch directory and uploads: # *** The scratch directory *** # We avoid `/tmp` entirely for the scratch directory to avoid shared global # mutable state with other users/applications/processes. SCRATCH_DIRECTORY = "~/tmp/gn-uploader-scratchdir" +UPLOAD_FOLDER = ""# If not set, will be under scratch directory. + REDIS_URL = "redis://" JOBS_TTL_SECONDS = 1209600 # 14 days GNQC_REDIS_PREFIX="gn-uploader" -- cgit 1.4.1