@@ -151,6 +151,9 @@ def matches_message(self, message, chat):
151151 if message_chat_id is None or not self .matches_chat_id (message_chat_id ):
152152 return False
153153
154+ if not self .check_size_limit (message .file .size ):
155+ return False
156+
154157 return True
155158
156159 def matches_media_type (self , media_type : str ):
@@ -171,6 +174,18 @@ def matches_chat_id(self, chat_id: int):
171174
172175 return chat_id in chat_ids
173176
177+ def check_size_limit (self , file_size_bytes : int ):
178+ max_size = self .get_max_size ()
179+ if max_size == "" :
180+ return True
181+
182+ max_size_bytes = FileSize .human_readable_to_bytes (max_size )
183+ file_size_string = FileSize .bytes_to_human_readable (file_size_bytes )
184+
185+ self .logger .debug (f"Checking file size { file_size_string } <= { max_size } " )
186+
187+ return file_size_bytes <= max_size_bytes
188+
174189 def get_download_path (self ) -> str | None :
175190 return self .get_with_fallback ("download_path" )
176191
@@ -390,16 +405,8 @@ async def download_media(self, message):
390405
391406 filename = config_rule .get_filepattern ().format_map (filename_pattern_map )
392407 filepath = download_path .joinpath (filename )
393-
394408 file_size_string = FileSize .bytes_to_human_readable (message .file .size )
395409
396- max_size = config_rule .get_max_size ()
397- if max_size != "" :
398- max_size_bytes = FileSize .human_readable_to_bytes (max_size )
399- if message .file .size > max_size_bytes :
400- logging .debug (f"Skipping media download for '{ full_original_filename } ' as it exceeds the configured max size ({ file_size_string } > { max_size } )" )
401- return
402-
403410 logging .debug (f"Downloading media file '{ full_original_filename } ' to { filepath } ({ file_size_string } )" )
404411 filepath .parent .mkdir (parents = True , exist_ok = True )
405412 await message .download_media (file = filepath )
0 commit comments