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,16 +134,7 @@ 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_small_resource(self, str resource_name, str folder, str key): cdef load_big_file_cdn(self, str folder, str big_part):
cdef str big_part = f'{resource_name}.big'
cdef str small_part = f'{resource_name}.small'
print(f'checking on existence for {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:
encrypted_bytes_big = binary_file.read()
print(f'local file {folder}\\{big_part} is found!')
else:
print(f'downloading file {folder}\\{big_part} from cdn...') print(f'downloading file {folder}\\{big_part} from cdn...')
if self.cdn_manager.download(folder, big_part): if self.cdn_manager.download(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:
@@ -151,11 +142,24 @@ cdef class ApiClient:
else: else:
return None 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) encrypted_bytes_small = self.load_bytes(small_part, folder)
encrypted_bytes = encrypted_bytes_small + encrypted_bytes_big print(f'checking on existence for {folder}\\{big_part}')
result = Security.decrypt_to(encrypted_bytes, key) if os.path.exists(os.path.join(<str> folder, big_part)):
return result with open(path.join(<str> folder, big_part), 'rb') as binary_file:
local_bytes_big = binary_file.read()
print(f'local file {folder}\\{big_part} is found!')
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')
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 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'