fix checking api client to download newest version

This commit is contained in:
Alex Bezdieniezhnykh
2025-05-30 17:18:55 +03:00
parent b5f2a75b86
commit 42867560c3
+17 -13
View File
@@ -134,28 +134,32 @@ cdef class ApiClient:
constants.log(<str>f'Downloaded file: {filename}, {len(data)} bytes') constants.log(<str>f'Downloaded file: {filename}, {len(data)} bytes')
return data return data
cdef load_big_file_cdn(self, str folder, str big_part):
print(f'downloading file {folder}\\{big_part} from cdn...')
if self.cdn_manager.download(folder, big_part):
with open(path.join(<str> folder, big_part), 'rb') as binary_file:
encrypted_bytes_big = binary_file.read()
else:
return None
cdef load_big_small_resource(self, str resource_name, str folder, str key): cdef load_big_small_resource(self, str resource_name, str folder, str key):
cdef str big_part = f'{resource_name}.big' cdef str big_part = f'{resource_name}.big'
cdef str small_part = f'{resource_name}.small' cdef str small_part = f'{resource_name}.small'
encrypted_bytes_small = self.load_bytes(small_part, folder)
print(f'checking on existence for {folder}\\{big_part}') print(f'checking on existence for {folder}\\{big_part}')
if os.path.exists(os.path.join(<str> folder, big_part)): if os.path.exists(os.path.join(<str> folder, big_part)):
with open(path.join(<str> folder, big_part), 'rb') as binary_file: with open(path.join(<str> folder, big_part), 'rb') as binary_file:
encrypted_bytes_big = binary_file.read() local_bytes_big = binary_file.read()
print(f'local file {folder}\\{big_part} is found!') print(f'local file {folder}\\{big_part} is found!')
else: try:
print(f'downloading file {folder}\\{big_part} from cdn...') return Security.decrypt_to(encrypted_bytes_small + local_bytes_big, key)
if self.cdn_manager.download(folder, big_part): except Exception as ex:
with open(path.join(<str> folder, big_part), 'rb') as binary_file: print('Local file doesnt match with api file, old version')
encrypted_bytes_big = binary_file.read()
else:
return None
encrypted_bytes_small = self.load_bytes(small_part, folder) remote_bytes_big = self.load_big_file_cdn(folder, big_part)
return Security.decrypt_to(encrypted_bytes_small + remote_bytes_big)
encrypted_bytes = encrypted_bytes_small + encrypted_bytes_big
result = Security.decrypt_to(encrypted_bytes, key)
return result
cdef upload_big_small_resource(self, bytes resource, str resource_name, str folder, str key): cdef upload_big_small_resource(self, bytes resource, str resource_name, str folder, str key):
cdef str big_part_name = f'{resource_name}.big' cdef str big_part_name = f'{resource_name}.big'