mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 12:26:30 +00:00
add list files for autoupdate feature
put new Versioning fix bugs
This commit is contained in:
@@ -97,25 +97,38 @@ cdef class ApiClient:
|
||||
except Exception as e:
|
||||
constants.log(f"Upload fail: {e}")
|
||||
|
||||
cdef list_files(self, str folder, str search_file):
|
||||
response = self.post(f'{self.api_url}/resources/list/{folder}', {
|
||||
"search": search_file
|
||||
})
|
||||
constants.log(<str> f'Get files list by {folder}')
|
||||
return response.json()
|
||||
|
||||
cdef load_bytes(self, str filename, str folder):
|
||||
cdef str hardware = HardwareService.get_hardware_info()
|
||||
hw_hash = Security.get_hw_hash(hardware)
|
||||
key = Security.get_api_encryption_key(self.credentials, hw_hash)
|
||||
payload = json.dumps(
|
||||
{
|
||||
"password": self.credentials.password,
|
||||
"hardware": hardware,
|
||||
"fileName": filename
|
||||
}, indent=4)
|
||||
response = self.post(f'{self.api_url}/resources/get/{folder}', payload)
|
||||
|
||||
resp_bytes = response.raw.read()
|
||||
data = Security.decrypt_to(resp_bytes, key)
|
||||
constants.log(<str>f'Downloaded file: {filename}, {len(data)} bytes')
|
||||
return data
|
||||
|
||||
cdef post(self, url, payload):
|
||||
if self.token is None:
|
||||
self.login()
|
||||
url = f"{self.api_url}/resources/get/{folder}"
|
||||
headers = {
|
||||
"Authorization": f"Bearer {self.token}",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
payload = json.dumps(
|
||||
{
|
||||
"password": self.credentials.password,
|
||||
"hardware": hardware,
|
||||
"fileName": filename
|
||||
}, indent=4)
|
||||
response = requests.post(url, data=payload, headers=headers, stream=True)
|
||||
if response.status_code == HTTPStatus.UNAUTHORIZED or response.status_code == HTTPStatus.FORBIDDEN:
|
||||
self.login()
|
||||
@@ -132,18 +145,14 @@ cdef class ApiClient:
|
||||
err_code = res['ErrorCode']
|
||||
err_msg = res['Message']
|
||||
raise Exception(f"Error {err_code}: {err_msg}")
|
||||
|
||||
resp_bytes = response.raw.read()
|
||||
data = Security.decrypt_to(resp_bytes, key)
|
||||
constants.log(<str>f'Downloaded file: {filename}, {len(data)} bytes')
|
||||
return data
|
||||
return response
|
||||
|
||||
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()
|
||||
# return encrypted_bytes_big
|
||||
return encrypted_bytes_big
|
||||
else:
|
||||
raise Exception(f'Cannot download file {folder}\\{big_part} from CDN!')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user