fix: guard against missing messages and reaction issues

Added a guard in `api_server.download_media_file` to detect `None` or empty messages and return a 404 error, preventing downstream failures.

Enhanced `PostParser._extract_reactions` to handle paid reactions, custom emojis, and unknown types, aggregating counts correctly. Updated `_extract_flags` to skip paid and custom emoji reactions, ensuring flag detection works reliably.
This commit is contained in:
vvzvlad
2026-05-17 23:12:11 +03:00
parent 40fa9797e8
commit dd5999b51f
2 changed files with 26 additions and 4 deletions
+6 -1
View File
@@ -360,7 +360,12 @@ async def download_media_file(channel: Union[str, int], post_id: int, file_uniqu
except asyncio.TimeoutError:
logger.error(f"Timeout getting messages for {channel}/{post_id}")
raise HTTPException(status_code=504, detail="Request timeout")
# Guard: message may be None (deleted) or an empty stub returned by Pyrogram
if not message or getattr(message, 'empty', False):
logger.warning(f"Message {post_id} not found or empty in channel {channel}")
raise HTTPException(status_code=404, detail="Post not found or deleted")
if message.media == MessageMediaType.POLL:
return None, False