This commit is contained in:
YeeChanKo 2018-08-06 15:31:22 +00:00 committed by GitHub
commit be506b87d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -393,26 +393,30 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
file_handle = None file_handle = None
as_image = utils.is_image(file) and not force_document as_image = utils.is_image(file) and not force_document
use_cache = types.InputPhoto if as_image else types.InputDocument use_cache = types.InputPhoto if as_image else types.InputDocument
if not isinstance(file, str):
file_handle = await self.upload_file(
file, progress_callback=progress_callback,
use_cache=use_cache if allow_cache else None
)
elif re.match('https?://', file):
if as_image:
media = types.InputMediaPhotoExternal(file)
elif not force_document and utils.is_gif(file):
media = types.InputMediaGifExternal(file, '')
else:
media = types.InputMediaDocumentExternal(file)
else:
bot_file = utils.resolve_bot_file_id(file)
if bot_file:
media = utils.get_input_media(bot_file)
if media: if isinstance(file, str):
pass # Already have media, don't check the rest if re.match('https?://', file):
elif isinstance(file_handle, use_cache): if as_image:
media = types.InputMediaPhotoExternal(file)
elif not force_document and utils.is_gif(file):
media = types.InputMediaGifExternal(file, '')
else:
media = types.InputMediaDocumentExternal(file)
else:
bot_file = utils.resolve_bot_file_id(file)
if bot_file:
media = utils.get_input_media(bot_file)
# Return if media is resolved
if media:
return None, media
# Proceed with local file handle
file_handle = await self.upload_file(
file, progress_callback=progress_callback,
use_cache=use_cache if allow_cache else None
)
if isinstance(file_handle, use_cache):
# File was cached, so an instance of use_cache was returned # File was cached, so an instance of use_cache was returned
if as_image: if as_image:
media = types.InputMediaPhoto(file_handle) media = types.InputMediaPhoto(file_handle)