diff options
Diffstat (limited to 'matweb')
| -rw-r--r-- | matweb/file_removal_scheduler.py | 4 | ||||
| -rw-r--r-- | matweb/rest_api.py | 2 | ||||
| -rw-r--r-- | matweb/utils.py | 6 |
3 files changed, 11 insertions, 1 deletions
diff --git a/matweb/file_removal_scheduler.py b/matweb/file_removal_scheduler.py index 2ce7912..59bb9ca 100644 --- a/matweb/file_removal_scheduler.py +++ b/matweb/file_removal_scheduler.py | |||
| @@ -4,6 +4,8 @@ import sys | |||
| 4 | import os | 4 | import os |
| 5 | import random | 5 | import random |
| 6 | 6 | ||
| 7 | from matweb import utils | ||
| 8 | |||
| 7 | 9 | ||
| 8 | def run_file_removal_job(upload_folder_path): | 10 | def run_file_removal_job(upload_folder_path): |
| 9 | if random.randint(0, 10) == 0: | 11 | if random.randint(0, 10) == 0: |
| @@ -18,7 +20,7 @@ def delete_file_when_too_old(filepath): | |||
| 18 | last_time = time.time() - file_mod_time | 20 | last_time = time.time() - file_mod_time |
| 19 | 21 | ||
| 20 | # if file is older than our configured max timeframe, delete it | 22 | # if file is older than our configured max timeframe, delete it |
| 21 | if last_time > int(os.environ.get('MAT2_MAX_FILE_AGE_FOR_REMOVAL', 15 * 60)): | 23 | if last_time > utils.get_file_removal_max_age_sec(): |
| 22 | try: | 24 | try: |
| 23 | os.remove(filepath) | 25 | os.remove(filepath) |
| 24 | except OSError: | 26 | except OSError: |
diff --git a/matweb/rest_api.py b/matweb/rest_api.py index a07d2d2..f893fca 100644 --- a/matweb/rest_api.py +++ b/matweb/rest_api.py | |||
| @@ -48,6 +48,7 @@ class APIUpload(Resource): | |||
| 48 | 48 | ||
| 49 | key, secret, meta_after, output_filename = utils.cleanup(parser, filepath, self.upload_folder) | 49 | key, secret, meta_after, output_filename = utils.cleanup(parser, filepath, self.upload_folder) |
| 50 | return utils.return_file_created_response( | 50 | return utils.return_file_created_response( |
| 51 | utils.get_file_removal_max_age_sec(), | ||
| 51 | output_filename, | 52 | output_filename, |
| 52 | mime, | 53 | mime, |
| 53 | key, | 54 | key, |
| @@ -133,6 +134,7 @@ class APIBulkDownloadCreator(Resource): | |||
| 133 | abort(500, message='Unable to clean %s' % mime) | 134 | abort(500, message='Unable to clean %s' % mime) |
| 134 | key, secret, meta_after, output_filename = utils.cleanup(parser, zip_path, self.upload_folder) | 135 | key, secret, meta_after, output_filename = utils.cleanup(parser, zip_path, self.upload_folder) |
| 135 | return { | 136 | return { |
| 137 | 'inactive_after_sec': utils.get_file_removal_max_age_sec(), | ||
| 136 | 'output_filename': output_filename, | 138 | 'output_filename': output_filename, |
| 137 | 'mime': mime, | 139 | 'mime': mime, |
| 138 | 'key': key, | 140 | 'key': key, |
diff --git a/matweb/utils.py b/matweb/utils.py index 20c213d..915d735 100644 --- a/matweb/utils.py +++ b/matweb/utils.py | |||
| @@ -35,6 +35,7 @@ def check_upload_folder(upload_folder): | |||
| 35 | 35 | ||
| 36 | 36 | ||
| 37 | def return_file_created_response( | 37 | def return_file_created_response( |
| 38 | inactive_after_sec: int, | ||
| 38 | output_filename: str, | 39 | output_filename: str, |
| 39 | mime: str, | 40 | mime: str, |
| 40 | key: str, | 41 | key: str, |
| @@ -44,6 +45,7 @@ def return_file_created_response( | |||
| 44 | download_link: str | 45 | download_link: str |
| 45 | ) -> dict: | 46 | ) -> dict: |
| 46 | return { | 47 | return { |
| 48 | 'inactive_after_sec': inactive_after_sec, | ||
| 47 | 'output_filename': output_filename, | 49 | 'output_filename': output_filename, |
| 48 | 'mime': mime, | 50 | 'mime': mime, |
| 49 | 'key': key, | 51 | 'key': key, |
| @@ -106,3 +108,7 @@ def is_valid_api_download_file(filename: str, key: str, secret: str, upload_fold | |||
| 106 | if hmac.compare_digest(hash_file(complete_path, secret), key) is False: | 108 | if hmac.compare_digest(hash_file(complete_path, secret), key) is False: |
| 107 | abort(400, message='The file hash does not match') | 109 | abort(400, message='The file hash does not match') |
| 108 | return complete_path, filepath | 110 | return complete_path, filepath |
| 111 | |||
| 112 | |||
| 113 | def get_file_removal_max_age_sec() -> int: | ||
| 114 | return int(os.environ.get('MAT2_MAX_FILE_AGE_FOR_REMOVAL', 15 * 60)) | ||
