From 42867560c365a25e3977d27574c842d8faa7cae0 Mon Sep 17 00:00:00 2001 From: Alex Bezdieniezhnykh Date: Fri, 30 May 2025 17:18:55 +0300 Subject: [PATCH] fix checking api client to download newest version --- Azaion.Inference/api_client.pyx | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/Azaion.Inference/api_client.pyx b/Azaion.Inference/api_client.pyx index a6ed66b..4227b4f 100644 --- a/Azaion.Inference/api_client.pyx +++ b/Azaion.Inference/api_client.pyx @@ -134,28 +134,32 @@ cdef class ApiClient: constants.log(f'Downloaded file: {filename}, {len(data)} bytes') 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( 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 str big_part = f'{resource_name}.big' 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}') if os.path.exists(os.path.join( folder, big_part)): with open(path.join( 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!') - else: - print(f'downloading file {folder}\\{big_part} from cdn...') - if self.cdn_manager.download(folder, big_part): - with open(path.join( folder, big_part), 'rb') as binary_file: - encrypted_bytes_big = binary_file.read() - else: - return None + try: + return Security.decrypt_to(encrypted_bytes_small + local_bytes_big, key) + except Exception as ex: + print('Local file doesnt match with api file, old version') - encrypted_bytes_small = self.load_bytes(small_part, folder) - - encrypted_bytes = encrypted_bytes_small + encrypted_bytes_big - result = Security.decrypt_to(encrypted_bytes, key) - return result + remote_bytes_big = self.load_big_file_cdn(folder, big_part) + return Security.decrypt_to(encrypted_bytes_small + remote_bytes_big) cdef upload_big_small_resource(self, bytes resource, str resource_name, str folder, str key): cdef str big_part_name = f'{resource_name}.big'