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:
+6
-1
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user