mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-07 13:34:59 +03:00
Merge 8c82b3afa7
into f332e4c423
This commit is contained in:
commit
be506b87d6
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user