From 2885764c516132c373c7e779b746f8f57cbdb1ac Mon Sep 17 00:00:00 2001 From: ocueye Date: Thu, 21 Nov 2024 14:01:49 +0000 Subject: [PATCH] added filesize config --- htt.conf | 3 ++- start.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/htt.conf b/htt.conf index 8da3c9c..f3e43f1 100644 --- a/htt.conf +++ b/htt.conf @@ -1,4 +1,5 @@ [DEFAULT] cleartime = 10 domain = localhost:8170 -port = 8170 \ No newline at end of file +port = 8170 +filesizemb = 200 \ No newline at end of file diff --git a/start.py b/start.py index 0dc636d..26dfea1 100644 --- a/start.py +++ b/start.py @@ -10,7 +10,8 @@ config.read('htt.conf') domain = str(config['DEFAULT']['domain']) MAINTENANCE_INTERVAL_MINUTES = float(config['DEFAULT']['cleartime']) port = int(config['DEFAULT']['port']) - +maxfilesize = int(config['DEFAULT']['filesizemb']) +maxfilesize = maxfilesize * 10 * 1024 * 1024 def popup(mesage,link="",file="popup.html"): out = load(file) out = out.replace("",str(mesage)) @@ -67,6 +68,14 @@ class FileUploadApp: def upload(self, file): clear_cache() try: + # test file size + file_size = 0 + file.file.seek(0, os.SEEK_END) # Seek to the end of the file + file_size = file.file.tell() # Get the current position (file size) + file.file.seek(0) + if file_size > MAX_FILE_SIZE: + return popup(f"This file is to large, max size is is {maxfilesize}") + # Find the lowest unused number as the identifier existing_ids = set(int(folder) for folder in os.listdir(self.upload_dir) if folder.isdigit()) ident = 1 # Start checking from 1