mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 20:14:51 +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
2 changed files with 25 additions and 23 deletions
|
|
@ -949,7 +949,8 @@ class Client(Methods, Scaffold):
|
|||
offset += limit
|
||||
|
||||
if progress:
|
||||
await progress(
|
||||
func = functools.partial(
|
||||
progress,
|
||||
min(offset, file_size)
|
||||
if file_size != 0
|
||||
else offset,
|
||||
|
|
@ -957,6 +958,11 @@ class Client(Methods, Scaffold):
|
|||
*progress_args
|
||||
)
|
||||
|
||||
if inspect.iscoroutinefunction(progress):
|
||||
await func()
|
||||
else:
|
||||
await self.loop.run_in_executor(self.executor, func)
|
||||
|
||||
r = await session.send(
|
||||
raw.functions.upload.GetFile(
|
||||
location=location,
|
||||
|
|
@ -1035,20 +1041,16 @@ class Client(Methods, Scaffold):
|
|||
offset += limit
|
||||
|
||||
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(
|
||||
progress,
|
||||
min(offset, file_size) if file_size != 0 else offset,
|
||||
file_size,
|
||||
*progress_args
|
||||
)
|
||||
func = functools.partial(
|
||||
progress,
|
||||
min(offset, file_size) if file_size != 0 else offset,
|
||||
file_size,
|
||||
*progress_args
|
||||
)
|
||||
|
||||
if inspect.iscoroutinefunction(progress):
|
||||
await func()
|
||||
else:
|
||||
await self.loop.run_in_executor(self.executor, func)
|
||||
|
||||
if len(chunk) < limit:
|
||||
|
|
|
|||
|
|
@ -183,16 +183,16 @@ class SaveFile(Scaffold):
|
|||
file_part += 1
|
||||
|
||||
if progress:
|
||||
if inspect.iscoroutinefunction(progress):
|
||||
await progress(min(file_part * part_size, file_size), file_size, *progress_args)
|
||||
else:
|
||||
func = functools.partial(
|
||||
progress,
|
||||
min(file_part * part_size, file_size),
|
||||
file_size,
|
||||
*progress_args
|
||||
)
|
||||
func = functools.partial(
|
||||
progress,
|
||||
min(file_part * part_size, file_size),
|
||||
file_size,
|
||||
*progress_args
|
||||
)
|
||||
|
||||
if inspect.iscoroutinefunction(progress):
|
||||
await func()
|
||||
else:
|
||||
await self.loop.run_in_executor(self.executor, func)
|
||||
except StopTransmission:
|
||||
raise
|
||||
|
|
|
|||
Loading…
Reference in a new issue