mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 05:18:10 +00:00
Fix sync callback progress not working properly for downloads
- Reduce duplicated code - Fixes #484
This commit is contained in:
parent
58667d2ae8
commit
ae88c851bb
@ -949,7 +949,8 @@ class Client(Methods, Scaffold):
|
|||||||
offset += limit
|
offset += limit
|
||||||
|
|
||||||
if progress:
|
if progress:
|
||||||
await progress(
|
func = functools.partial(
|
||||||
|
progress,
|
||||||
min(offset, file_size)
|
min(offset, file_size)
|
||||||
if file_size != 0
|
if file_size != 0
|
||||||
else offset,
|
else offset,
|
||||||
@ -957,6 +958,11 @@ class Client(Methods, Scaffold):
|
|||||||
*progress_args
|
*progress_args
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if inspect.iscoroutinefunction(progress):
|
||||||
|
await func()
|
||||||
|
else:
|
||||||
|
await self.loop.run_in_executor(self.executor, func)
|
||||||
|
|
||||||
r = await session.send(
|
r = await session.send(
|
||||||
raw.functions.upload.GetFile(
|
raw.functions.upload.GetFile(
|
||||||
location=location,
|
location=location,
|
||||||
@ -1035,13 +1041,6 @@ class Client(Methods, Scaffold):
|
|||||||
offset += limit
|
offset += limit
|
||||||
|
|
||||||
if progress:
|
if progress:
|
||||||
if inspect.iscoroutinefunction(progress):
|
|
||||||
await progress(
|
|
||||||
min(offset, file_size) if file_size != 0 else offset,
|
|
||||||
file_size,
|
|
||||||
*progress_args
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
func = functools.partial(
|
func = functools.partial(
|
||||||
progress,
|
progress,
|
||||||
min(offset, file_size) if file_size != 0 else offset,
|
min(offset, file_size) if file_size != 0 else offset,
|
||||||
@ -1049,6 +1048,9 @@ class Client(Methods, Scaffold):
|
|||||||
*progress_args
|
*progress_args
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if inspect.iscoroutinefunction(progress):
|
||||||
|
await func()
|
||||||
|
else:
|
||||||
await self.loop.run_in_executor(self.executor, func)
|
await self.loop.run_in_executor(self.executor, func)
|
||||||
|
|
||||||
if len(chunk) < limit:
|
if len(chunk) < limit:
|
||||||
|
@ -183,9 +183,6 @@ class SaveFile(Scaffold):
|
|||||||
file_part += 1
|
file_part += 1
|
||||||
|
|
||||||
if progress:
|
if progress:
|
||||||
if inspect.iscoroutinefunction(progress):
|
|
||||||
await progress(min(file_part * part_size, file_size), file_size, *progress_args)
|
|
||||||
else:
|
|
||||||
func = functools.partial(
|
func = functools.partial(
|
||||||
progress,
|
progress,
|
||||||
min(file_part * part_size, file_size),
|
min(file_part * part_size, file_size),
|
||||||
@ -193,6 +190,9 @@ class SaveFile(Scaffold):
|
|||||||
*progress_args
|
*progress_args
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if inspect.iscoroutinefunction(progress):
|
||||||
|
await func()
|
||||||
|
else:
|
||||||
await self.loop.run_in_executor(self.executor, func)
|
await self.loop.run_in_executor(self.executor, func)
|
||||||
except StopTransmission:
|
except StopTransmission:
|
||||||
raise
|
raise
|
||||||
|
Loading…
x
Reference in New Issue
Block a user