Add support for downloading files in different DCs
This commit is contained in:
parent
0cfce2c165
commit
e242f2a555
@ -817,6 +817,7 @@ class Client:
|
|||||||
return r
|
return r
|
||||||
|
|
||||||
def get_file(self,
|
def get_file(self,
|
||||||
|
dc_id: int,
|
||||||
id: int = None,
|
id: int = None,
|
||||||
access_hash: int = None,
|
access_hash: int = None,
|
||||||
volume_id: int = None,
|
volume_id: int = None,
|
||||||
@ -827,6 +828,38 @@ class Client:
|
|||||||
# TODO: Use proper file name and extension
|
# TODO: Use proper file name and extension
|
||||||
# TODO: Remove redundant code
|
# TODO: Remove redundant code
|
||||||
|
|
||||||
|
if dc_id != self.dc_id:
|
||||||
|
exported_auth = self.send(
|
||||||
|
functions.auth.ExportAuthorization(
|
||||||
|
dc_id=dc_id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
session = Session(
|
||||||
|
dc_id,
|
||||||
|
self.test_mode,
|
||||||
|
Auth(dc_id, self.test_mode).create(),
|
||||||
|
self.config.api_id
|
||||||
|
)
|
||||||
|
|
||||||
|
session.start()
|
||||||
|
|
||||||
|
session.send(
|
||||||
|
functions.auth.ImportAuthorization(
|
||||||
|
id=exported_auth.id,
|
||||||
|
bytes=exported_auth.bytes
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
session = Session(
|
||||||
|
dc_id,
|
||||||
|
self.test_mode,
|
||||||
|
self.auth_key,
|
||||||
|
self.config.api_id
|
||||||
|
)
|
||||||
|
|
||||||
|
session.start()
|
||||||
|
|
||||||
if volume_id: # Photos are accessed by volume_id, local_id, secret
|
if volume_id: # Photos are accessed by volume_id, local_id, secret
|
||||||
location = types.InputFileLocation(
|
location = types.InputFileLocation(
|
||||||
volume_id=volume_id,
|
volume_id=volume_id,
|
||||||
@ -843,9 +876,6 @@ class Client:
|
|||||||
limit = 512 * 1024
|
limit = 512 * 1024
|
||||||
offset = 0
|
offset = 0
|
||||||
|
|
||||||
session = Session(self.dc_id, self.test_mode, self.auth_key, self.config.api_id)
|
|
||||||
session.start()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = session.send(
|
r = session.send(
|
||||||
functions.upload.GetFile(
|
functions.upload.GetFile(
|
||||||
|
Loading…
Reference in New Issue
Block a user