mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 10:36:30 +00:00
add list files for autoupdate feature
put new Versioning fix bugs
This commit is contained in:
@@ -14,6 +14,8 @@ cdef class ApiClient:
|
||||
cdef set_token(self, str token)
|
||||
cdef get_user(self)
|
||||
|
||||
cdef post(self, url, json)
|
||||
cdef list_files(self, str folder, str search_file)
|
||||
cdef load_bytes(self, str filename, str folder)
|
||||
cdef upload_file(self, str filename, bytes resource, str folder)
|
||||
cdef load_big_file_cdn(self, str folder, str big_part)
|
||||
|
||||
@@ -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!')
|
||||
|
||||
|
||||
@@ -49,6 +49,6 @@ robocopy "dist\azaion-loader\_internal" "..\dist-azaion\_internal" "hardware_ser
|
||||
robocopy "dist\azaion-loader\_internal" "..\dist-azaion\_internal" "main_loader.cp312-win_amd64.pyd"
|
||||
|
||||
robocopy "dist\azaion-loader\_internal" "..\dist-dlls\_internal" /E
|
||||
robocopy "dist\azaion-loader" "..\dist-azaion" "azaion-loader.exe" /E
|
||||
robocopy "dist\azaion-loader" "..\dist-azaion" "azaion-loader.exe"
|
||||
|
||||
cd /d %CURRENT_DIR%
|
||||
@@ -1,6 +1,6 @@
|
||||
import io
|
||||
import os
|
||||
|
||||
cimport constants
|
||||
import boto3
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ cdef class CDNManager:
|
||||
cdef upload(self, str bucket, str filename, bytes file_bytes):
|
||||
try:
|
||||
self.upload_client.upload_fileobj(io.BytesIO(file_bytes), bucket, filename)
|
||||
print(f'uploaded {filename} ({len(file_bytes)} bytes) to the {bucket}')
|
||||
constants.log(f'uploaded {filename} ({len(file_bytes)} bytes) to the {bucket}')
|
||||
return True
|
||||
except Exception as e:
|
||||
print(e)
|
||||
@@ -37,7 +37,7 @@ cdef class CDNManager:
|
||||
try:
|
||||
os.makedirs(folder, exist_ok=True)
|
||||
self.download_client.download_file(folder, filename, f'{folder}\\{filename}')
|
||||
print(f'downloaded {filename} from the {folder}')
|
||||
constants.log(f'downloaded {filename} from the {folder}')
|
||||
return True
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
@@ -13,4 +13,12 @@ cdef class UploadFileData(FileData):
|
||||
@staticmethod
|
||||
cdef from_msgpack(bytes data)
|
||||
|
||||
cdef bytes serialize(self)
|
||||
|
||||
cdef class FileList:
|
||||
cdef public list[str] files
|
||||
|
||||
@staticmethod
|
||||
cdef from_msgpack(bytes data)
|
||||
|
||||
cdef bytes serialize(self)
|
||||
@@ -37,4 +37,16 @@ cdef class UploadFileData(FileData):
|
||||
"Resource": self.resource,
|
||||
"Folder": self.folder,
|
||||
"Filename": self.filename
|
||||
})
|
||||
})
|
||||
|
||||
cdef class FileList:
|
||||
def __init__(self, list[str] files):
|
||||
self.files = files
|
||||
|
||||
@staticmethod
|
||||
cdef from_msgpack(bytes data):
|
||||
unpacked = unpackb(data, strict_map_key=False)
|
||||
return FileList(unpacked.get("files"))
|
||||
|
||||
cdef bytes serialize(self):
|
||||
return packb({ "files": self.files })
|
||||
|
||||
@@ -4,7 +4,7 @@ import traceback
|
||||
from credentials cimport Credentials
|
||||
from remote_command cimport RemoteCommand, CommandType
|
||||
from remote_command_handler cimport RemoteCommandHandler
|
||||
from file_data cimport FileData, UploadFileData
|
||||
from file_data cimport FileData, UploadFileData, FileList
|
||||
from api_client cimport ApiClient
|
||||
|
||||
cdef class CommandProcessor:
|
||||
@@ -47,6 +47,11 @@ cdef class CommandProcessor:
|
||||
file_data = FileData.from_msgpack(command.data)
|
||||
file_bytes = self.api_client.load_bytes(file_data.filename, file_data.folder)
|
||||
self.remote_handler.send(command.client_id, RemoteCommand(CommandType.DATA_BYTES, file_bytes).serialize())
|
||||
elif command.command_type == CommandType.LIST_REQUEST:
|
||||
search_data = FileData.from_msgpack(command.data)
|
||||
list_files = self.api_client.load_bytes(search_data.folder, search_data.filename)
|
||||
file_list_bytes = FileList(list_files).serialize()
|
||||
self.remote_handler.send(command.client_id, RemoteCommand(CommandType.LIST_FILES, file_list_bytes).serialize())
|
||||
elif command.command_type == CommandType.LOAD_BIG_SMALL:
|
||||
data = FileData.from_msgpack(command.data)
|
||||
file_bytes = self.api_client.load_big_small_resource(data.filename, data.folder)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
cdef enum CommandType:
|
||||
OK = 3
|
||||
LOGIN = 10
|
||||
LIST_REQUEST = 15
|
||||
LIST_FILES = 18
|
||||
LOAD = 20
|
||||
LOAD_BIG_SMALL = 22
|
||||
UPLOAD_BIG_SMALL = 24
|
||||
|
||||
@@ -10,6 +10,8 @@ cdef class RemoteCommand:
|
||||
command_type_names = {
|
||||
3: "OK",
|
||||
10: "LOGIN",
|
||||
15: "LIST_REQUEST",
|
||||
18: "LIST_FILES",
|
||||
20: "LOAD",
|
||||
22: "LOAD_BIG_SMALL",
|
||||
24: "UPLOAD_BIG_SMALL",
|
||||
|
||||
Reference in New Issue
Block a user