ENH: get thumbnail from task info
JIRA: STUDIO-3975 Change-Id: Ic9ae120673098a4b62c4a00b515558fbef630890 Signed-off-by: Stone Li <stone.li@bambulab.com>
This commit is contained in:
parent
fbd70b13a3
commit
98a7a10ce5
|
@ -4424,7 +4424,35 @@ void MachineObject::update_slice_info(std::string project_id, std::string profil
|
|||
} else {
|
||||
if (subtask_id.compare("0") == 0)
|
||||
return;
|
||||
m_agent->get_task_plate_index(subtask_id, &plate_index);
|
||||
|
||||
std::string subtask_json;
|
||||
unsigned http_code = 0;
|
||||
std::string http_body;
|
||||
if (m_agent->get_subtask_info(subtask_id, &subtask_json, &http_code, &http_body) == 0) {
|
||||
try {
|
||||
json task_j = json::parse(subtask_json);
|
||||
if (task_j.contains("content")) {
|
||||
std::string content_str = task_j["content"].get<std::string>();
|
||||
json content_j = json::parse(content_str);
|
||||
plate_index = content_j["info"]["plate_idx"].get<int>();
|
||||
}
|
||||
|
||||
if (task_j.contains("context") && task_j["context"].contains("plates")) {
|
||||
for (int i = 0; i < task_j["context"]["plates"].size(); i++) {
|
||||
if (task_j["context"]["plates"][i].contains("index") && task_j["context"]["plates"][i]["index"].get<int>() == plate_index) {
|
||||
slice_info->thumbnail_url = task_j["context"]["plates"][i]["thumbnail"]["url"].get<std::string>();
|
||||
BOOST_LOG_TRIVIAL(trace) << "task_info: thumbnail url=" << slice_info->thumbnail_url;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
BOOST_LOG_TRIVIAL(error) << "task_info: no context or plates";
|
||||
}
|
||||
}
|
||||
catch(...) {
|
||||
}
|
||||
} else {
|
||||
BOOST_LOG_TRIVIAL(error) << "task_info: get subtask id failed!";
|
||||
}
|
||||
}
|
||||
|
||||
if (plate_index >= 0) {
|
||||
|
@ -4439,7 +4467,7 @@ void MachineObject::update_slice_info(std::string project_id, std::string profil
|
|||
if (!j["weight"].is_null())
|
||||
slice_info->weight = j["weight"].get<float>();
|
||||
if (!j["thumbnail"].is_null()) {
|
||||
slice_info->thumbnail_url = j["thumbnail"]["url"].get<std::string>();
|
||||
//slice_info->thumbnail_url = j["thumbnail"]["url"].get<std::string>();
|
||||
BOOST_LOG_TRIVIAL(trace) << "slice_info: thumbnail url=" << slice_info->thumbnail_url;
|
||||
}
|
||||
if (!j["filaments"].is_null()) {
|
||||
|
|
|
@ -90,6 +90,7 @@ func_get_printer_firmware NetworkAgent::get_printer_firmware_ptr = nul
|
|||
func_get_task_plate_index NetworkAgent::get_task_plate_index_ptr = nullptr;
|
||||
func_get_user_info NetworkAgent::get_user_info_ptr = nullptr;
|
||||
func_request_bind_ticket NetworkAgent::request_bind_ticket_ptr = nullptr;
|
||||
func_get_subtask_info NetworkAgent::get_subtask_info_ptr = nullptr;
|
||||
func_get_slice_info NetworkAgent::get_slice_info_ptr = nullptr;
|
||||
func_query_bind_status NetworkAgent::query_bind_status_ptr = nullptr;
|
||||
func_modify_printer_name NetworkAgent::modify_printer_name_ptr = nullptr;
|
||||
|
@ -246,6 +247,7 @@ int NetworkAgent::initialize_network_module(bool using_backup)
|
|||
get_task_plate_index_ptr = reinterpret_cast<func_get_task_plate_index>(get_network_function("bambu_network_get_task_plate_index"));
|
||||
get_user_info_ptr = reinterpret_cast<func_get_user_info>(get_network_function("bambu_network_get_user_info"));
|
||||
request_bind_ticket_ptr = reinterpret_cast<func_request_bind_ticket>(get_network_function("bambu_network_request_bind_ticket"));
|
||||
get_subtask_info_ptr = reinterpret_cast<func_get_subtask_info>(get_network_function("bambu_network_get_subtask_info"));
|
||||
get_slice_info_ptr = reinterpret_cast<func_get_slice_info>(get_network_function("bambu_network_get_slice_info"));
|
||||
query_bind_status_ptr = reinterpret_cast<func_query_bind_status>(get_network_function("bambu_network_query_bind_status"));
|
||||
modify_printer_name_ptr = reinterpret_cast<func_modify_printer_name>(get_network_function("bambu_network_modify_printer_name"));
|
||||
|
@ -355,11 +357,12 @@ int NetworkAgent::unload_network_module()
|
|||
get_printer_firmware_ptr = nullptr;
|
||||
get_task_plate_index_ptr = nullptr;
|
||||
get_user_info_ptr = nullptr;
|
||||
get_subtask_info_ptr = nullptr;
|
||||
get_slice_info_ptr = nullptr;
|
||||
query_bind_status_ptr = nullptr;
|
||||
modify_printer_name_ptr = nullptr;
|
||||
get_camera_url_ptr = nullptr;
|
||||
get_design_staffpick_ptr = nullptr;
|
||||
get_design_staffpick_ptr = nullptr;
|
||||
start_publish_ptr = nullptr;
|
||||
get_profile_3mf_ptr = nullptr;
|
||||
get_model_publish_url_ptr = nullptr;
|
||||
|
@ -1093,6 +1096,17 @@ int NetworkAgent::request_bind_ticket(std::string* ticket)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int NetworkAgent::get_subtask_info(std::string subtask_id, std::string* task_json, unsigned int* http_code, std::string* http_body)
|
||||
{
|
||||
int ret = 0;
|
||||
if (network_agent && get_subtask_info_ptr) {
|
||||
ret = get_subtask_info_ptr(network_agent, subtask_id, task_json, http_code, http_body);
|
||||
if (ret)
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format("error: network_agent=%1%, ret=%2%") % network_agent % ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int NetworkAgent::get_slice_info(std::string project_id, std::string profile_id, int plate_index, std::string* slice_json)
|
||||
{
|
||||
int ret;
|
||||
|
|
|
@ -70,6 +70,7 @@ typedef int (*func_get_printer_firmware)(void *agent, std::string dev_id, unsign
|
|||
typedef int (*func_get_task_plate_index)(void *agent, std::string task_id, int* plate_index);
|
||||
typedef int (*func_get_user_info)(void *agent, int* identifier);
|
||||
typedef int (*func_request_bind_ticket)(void *agent, std::string* ticket);
|
||||
typedef int (*func_get_subtask_info)(void *agent, std::string subtask_id, std::string* task_json, unsigned int* http_code, std::string *http_body);
|
||||
typedef int (*func_get_slice_info)(void *agent, std::string project_id, std::string profile_id, int plate_index, std::string* slice_json);
|
||||
typedef int (*func_query_bind_status)(void *agent, std::vector<std::string> query_list, unsigned int* http_code, std::string* http_body);
|
||||
typedef int (*func_modify_printer_name)(void *agent, std::string dev_id, std::string dev_name);
|
||||
|
@ -170,6 +171,7 @@ public:
|
|||
int get_task_plate_index(std::string task_id, int* plate_index);
|
||||
int get_user_info(int* identifier);
|
||||
int request_bind_ticket(std::string* ticket);
|
||||
int get_subtask_info(std::string subtask_id, std::string* task_json, unsigned int* http_code, std::string* http_body);
|
||||
int get_slice_info(std::string project_id, std::string profile_id, int plate_index, std::string* slice_json);
|
||||
int query_bind_status(std::vector<std::string> query_list, unsigned int* http_code, std::string* http_body);
|
||||
int modify_printer_name(std::string dev_id, std::string dev_name);
|
||||
|
@ -258,6 +260,7 @@ private:
|
|||
static func_get_task_plate_index get_task_plate_index_ptr;
|
||||
static func_get_user_info get_user_info_ptr;
|
||||
static func_request_bind_ticket request_bind_ticket_ptr;
|
||||
static func_get_subtask_info get_subtask_info_ptr;
|
||||
static func_get_slice_info get_slice_info_ptr;
|
||||
static func_query_bind_status query_bind_status_ptr;
|
||||
static func_modify_printer_name modify_printer_name_ptr;
|
||||
|
|
Loading…
Reference in New Issue