add resource check

incorrect pass / hw handling in a loader
This commit is contained in:
Alex Bezdieniezhnykh
2025-06-15 15:01:55 +03:00
parent c0f8dd792d
commit def7aad833
14 changed files with 193 additions and 16 deletions
+1
View File
@@ -16,6 +16,7 @@ cdef class ApiClient:
cdef request(self, str method, str url, object payload, bint is_stream)
cdef list_files(self, str folder, str search_file)
cdef check_resource(self)
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)
+8 -3
View File
@@ -47,10 +47,10 @@ cdef class ApiClient:
token = response.json()["token"]
self.set_token(token)
except HTTPError as e:
constants.logerror(response.json())
res = response.json()
constants.logerror(str(res))
if response.status_code == HTTPStatus.CONFLICT:
res = response.json()
raise Exception(res['Message'])
raise Exception(f"Error {res['ErrorCode']}: {res['Message']}")
cdef set_token(self, str token):
@@ -104,6 +104,11 @@ cdef class ApiClient:
constants.log(<str> f'Get files list by {folder}')
return response.json()
cdef check_resource(self):
cdef str hardware = HardwareService.get_hardware_info()
payload = json.dumps({ "hardware": hardware }, indent=4)
response = self.request('post', f'{self.api_url}/resources/check', payload, is_stream=False)
cdef load_bytes(self, str filename, str folder):
cdef str hardware = HardwareService.get_hardware_info()
hw_hash = Security.get_hw_hash(hardware)
+3 -3
View File
@@ -44,6 +44,9 @@ cdef class CommandProcessor:
if command.command_type == CommandType.LOGIN:
self.api_client.set_credentials(Credentials.from_msgpack(command.data))
self.remote_handler.send(command.client_id, self.ok_response.serialize())
elif command.command_type == CommandType.CHECK_RESOURCE:
self.api_client.check_resource()
self.remote_handler.send(command.client_id, RemoteCommand(CommandType.OK).serialize())
elif command.command_type == CommandType.LOAD:
file_data = FileData.from_msgpack(command.data)
file_bytes = self.api_client.load_bytes(file_data.filename, file_data.folder)
@@ -61,9 +64,6 @@ cdef class CommandProcessor:
data = UploadFileData.from_msgpack(command.data)
file_bytes = self.api_client.upload_big_small_resource(data.resource, data.filename, data.folder)
self.remote_handler.send(command.client_id, RemoteCommand(CommandType.OK).serialize())
elif command.command_type == CommandType.EXIT:
t = Thread(target=self.stop) # non-block worker:
t.start()
else:
pass
except Exception as e:
+1
View File
@@ -1,6 +1,7 @@
cdef enum CommandType:
OK = 3
LOGIN = 10
CHECK_RESOURCE = 12
LIST_REQUEST = 15
LIST_FILES = 18
LOAD = 20
+1
View File
@@ -10,6 +10,7 @@ cdef class RemoteCommand:
command_type_names = {
3: "OK",
10: "LOGIN",
12: "CHECK_RESOURCE",
15: "LIST_REQUEST",
18: "LIST_FILES",
20: "LOAD",