Don't ignore thumb in send_file(input file)

Fixes #1404
This commit is contained in:
Lonami Exo 2020-03-14 12:12:40 +01:00
parent 68438f4621
commit ccfd7a1015
2 changed files with 14 additions and 10 deletions

View File

@ -637,6 +637,14 @@ class UploadMethods:
if as_image is None: if as_image is None:
as_image = utils.is_image(file) and not force_document as_image = utils.is_image(file) and not force_document
if as_image or not thumb:
# Images don't have thumb so don't bother uploading it
thumb = None
else:
if isinstance(thumb, pathlib.Path):
thumb = str(thumb.absolute())
thumb = await self.upload_file(thumb)
# `aiofiles` do not base `io.IOBase` but do have `read`, so we # `aiofiles` do not base `io.IOBase` but do have `read`, so we
# just check for the read attribute to see if it's file-like. # just check for the read attribute to see if it's file-like.
if not isinstance(file, (str, bytes)) and not hasattr(file, 'read'): if not isinstance(file, (str, bytes)) and not hasattr(file, 'read'):
@ -654,7 +662,8 @@ class UploadMethods:
force_document=force_document, force_document=force_document,
voice_note=voice_note, voice_note=voice_note,
video_note=video_note, video_note=video_note,
supports_streaming=supports_streaming supports_streaming=supports_streaming,
thumb=thumb,
), as_image) ), as_image)
except TypeError: except TypeError:
# Can't turn whatever was given into media # Can't turn whatever was given into media
@ -699,17 +708,11 @@ class UploadMethods:
supports_streaming=supports_streaming supports_streaming=supports_streaming
) )
input_kw = {}
if thumb:
if isinstance(thumb, pathlib.Path):
thumb = str(thumb.absolute())
input_kw['thumb'] = await self.upload_file(thumb)
media = types.InputMediaUploadedDocument( media = types.InputMediaUploadedDocument(
file=file_handle, file=file_handle,
mime_type=mime_type, mime_type=mime_type,
attributes=attributes, attributes=attributes,
**input_kw thumb=thumb
) )
return file_handle, media, as_image return file_handle, media, as_image

View File

@ -427,7 +427,8 @@ def get_input_geo(geo):
def get_input_media( def get_input_media(
media, *, media, *,
is_photo=False, attributes=None, force_document=False, is_photo=False, attributes=None, force_document=False,
voice_note=False, video_note=False, supports_streaming=False voice_note=False, video_note=False, supports_streaming=False,
thumb=None,
): ):
""" """
Similar to :meth:`get_input_peer`, but for media. Similar to :meth:`get_input_peer`, but for media.
@ -481,7 +482,7 @@ def get_input_media(
supports_streaming=supports_streaming supports_streaming=supports_streaming
) )
return types.InputMediaUploadedDocument( return types.InputMediaUploadedDocument(
file=media, mime_type=mime, attributes=attrs) file=media, mime_type=mime, attributes=attrs, thumb=thumb)
if isinstance(media, types.MessageMediaGame): if isinstance(media, types.MessageMediaGame):
return types.InputMediaGame(id=types.InputGameID( return types.InputMediaGame(id=types.InputGameID(