async media: add ability to upload media asynchronously

Co-authored-by: Tulir Asokan <tulir@maunium.net>
This commit is contained in:
Sumner Evans
2022-03-25 14:49:45 -06:00
parent f8596ef368
commit 601058d61c
6 changed files with 43 additions and 9 deletions
@@ -317,6 +317,7 @@ async def parallel_transfer_to_matrix(
filename: str,
encrypt: bool,
parallel_id: int,
async_upload: bool = False,
) -> DBTelegramFile:
size = location.size
mime_type = location.mime_type
@@ -340,7 +341,11 @@ async def parallel_transfer_to_matrix(
data = encrypted(data)
up_mime_type = "application/octet-stream"
content_uri = await intent.upload_media(
data, mime_type=up_mime_type, filename=filename, size=size if not encrypt else None
data,
mime_type=up_mime_type,
filename=filename,
size=size if not encrypt else None,
async_upload=async_upload and not encrypt,
)
if decryption_info:
decryption_info.url = content_uri