Fix files uploading

This commit is contained in:
2023-03-31 10:21:16 +02:00
parent 08a2680653
commit 185420ea3d
3 changed files with 67 additions and 59 deletions

View File

@@ -1,5 +1,6 @@
from typing import AsyncIterator, Optional, Union
import sentry_sdk
import telethon.client
import telethon.errors
import telethon.hints
@@ -24,9 +25,16 @@ class BaseStorage:
async def upload(
self, file: telethon.hints.FileLike, caption: Optional[str] = None
) -> Optional[tuple[Union[str, int], int]]:
message = await self.client.send_file(
self.channel_id, file=file, caption=caption
)
try:
message = await self.client.send_file(
self.channel_id, file=file, caption=caption
)
except telethon.errors.FilePartInvalidError as e:
sentry_sdk.capture_exception(e)
return None
except telethon.errors.PhotoInvalidError as e:
sentry_sdk.capture_exception(e)
return None
if not message.media:
return None