Source code for oarepo_config.files

#
# Copyright (c) 2026 CESNET z.s.p.o.
#
# This file is a part of oarepo-config (see https://github.com/oarepo/oarepo-config).
#
# oarepo-config is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
#
"""Configuration for record files and upload quotas."""

from __future__ import annotations

from .base import set_constants_in_caller


[docs] def configure_files( max_file_size: int = 10 * 10**9, max_files_count: int = 100, max_total_size: int = 10 * 10**9, allow_metadata_only_records: bool = True, ) -> None: """Set up file upload quotas and the metadata-only records toggle. Controls how many files users may attach to a record deposition, how large each individual file may be, the total storage budget for the deposition, and whether a deposition can be published without any files at all. Args: max_file_size: Maximum size of a single uploaded file in bytes. Defaults to 10 GB (``10 * 10**9``). max_files_count: Maximum number of files allowed per record deposition. Defaults to ``100``. max_total_size: Maximum combined size of all files in a single record deposition, in bytes. Defaults to 10 GB (``10 * 10**9``). allow_metadata_only_records: When ``False``, users must upload at least one file before they can publish a record deposition. When ``True`` (the default), metadata-only records are allowed. Invenio configuration variables set: * ``RDM_FILES_DEFAULT_MAX_FILE_SIZE`` - backend limit on the size of a single file. * ``RDM_FILES_DEFAULT_QUOTA_SIZE`` - backend limit on the total size of all files in a record deposition. * ``RDM_RECORDS_MAX_FILES_COUNT`` - backend limit on the number of files per record. * ``RDM_ALLOW_METADATA_ONLY_RECORDS`` - whether metadata-only records are allowed. * ``APP_RDM_DEPOSIT_FORM_QUOTA`` - deposit-form UI quota object with ``maxFiles`` and ``maxStorage``. * ``FILES_REST_DEFAULT_MAX_FILE_SIZE`` and ``FILES_REST_DEFAULT_QUOTA_SIZE`` - fallback variables used by the lower-level file storage layer. Example: .. code-block:: python # Require at least one file per record, with a 5 GB total budget # and files no larger than 1 GB each. config.configure_files( max_file_size=1 * 10**9, max_files_count=20, max_total_size=5 * 10**9, allow_metadata_only_records=False, ) """ RDM_FILES_DEFAULT_MAX_FILE_SIZE = max_file_size FILES_REST_DEFAULT_MAX_FILE_SIZE = max_file_size RDM_FILES_DEFAULT_QUOTA_SIZE = max_total_size FILES_REST_DEFAULT_QUOTA_SIZE = max_total_size RDM_RECORDS_MAX_FILES_COUNT = max_files_count APP_RDM_DEPOSIT_FORM_QUOTA = { "maxFiles": max_files_count, "maxStorage": max_total_size, } RDM_ALLOW_METADATA_ONLY_RECORDS = allow_metadata_only_records set_constants_in_caller(locals())