FIX: save the original cloud HMS file

jira: [none]
Change-Id: I1e0987203d06274e4018e4bad12d9d796f3a26a0
This commit is contained in:
xin.zhang 2025-04-01 14:52:39 +08:00 committed by lane.wei
parent f3992d3e94
commit ed9c29d7a5
1 changed files with 18 additions and 34 deletions

View File

@ -74,11 +74,13 @@ int HMSQuery::download_hms_related(const std::string& hms_type, const std::strin
bool to_save_local = false; bool to_save_local = false;
json j;
BOOST_LOG_TRIVIAL(info) << "hms: download url = " << url; BOOST_LOG_TRIVIAL(info) << "hms: download url = " << url;
Slic3r::Http http = Slic3r::Http::get(url); Slic3r::Http http = Slic3r::Http::get(url);
http.on_complete([this, receive_json, hms_type, &to_save_local, &local_version](std::string body, unsigned status) { http.on_complete([this, receive_json, hms_type, &to_save_local, &j, & local_version](std::string body, unsigned status) {
try { try {
json j = json::parse(body); j = json::parse(body);
if (j.contains("result")) { if (j.contains("result")) {
if (j["result"] == 0 && j.contains("data")) { if (j["result"] == 0 && j.contains("data")) {
@ -120,7 +122,7 @@ int HMSQuery::download_hms_related(const std::string& hms_type, const std::strin
}).perform_sync(); }).perform_sync();
if (to_save_local && !receive_json->empty()) { if (to_save_local && !receive_json->empty()) {
save_to_local(lang, hms_type, dev_id_type, *receive_json); save_to_local(lang, hms_type, dev_id_type, j);
} }
return 0; return 0;
} }
@ -191,43 +193,24 @@ int HMSQuery::load_from_local(const std::string& hms_type, const std::string& de
std::ifstream json_file(encode_path(dir_str.c_str())); std::ifstream json_file(encode_path(dir_str.c_str()));
try { try {
if (json_file.is_open()) if (json_file.is_open())
{
if (package_dev_id_types.count(dev_id_type) != 0) /*temp for 094, the local file structure is different from saved cloud file*/
{
if (hms_type == QUERY_HMS_INFO)
{ {
const json &j = json::parse(json_file); const json &j = json::parse(json_file);
if (j.contains("data")) if (hms_type.compare(QUERY_HMS_INFO) == 0) {
{ (*load_json) = j["data"];
*load_json = j["data"]; } else if (hms_type.compare(QUERY_HMS_ACTION) == 0) {
} (*load_json)["data"] = j["data"];
}
else
{
json_file >> (*load_json);
} }
if ((*load_json).contains("ver")) if (j.contains("version")) {
{ load_version = JsonValParser::get_longlong_val(j["version"]);
load_version = JsonValParser::get_longlong_val((*load_json)["ver"]); }
else if (j.contains("ver")) {
load_version = JsonValParser::get_longlong_val(j["ver"]);
} }
else else
{ {
BOOST_LOG_TRIVIAL(warning) << "HMS: load_from_local, no version info"; BOOST_LOG_TRIVIAL(warning) << "HMS: load_from_local, no version info";
} }
}
else
{
json_file >> (*load_json);
if ((*load_json).contains("version"))
{
load_version = JsonValParser::get_longlong_val((*load_json)["version"]);
}
else
{
BOOST_LOG_TRIVIAL(warning) << "HMS: load_from_local, no version info";
}
}
return 0; return 0;
} }
@ -599,6 +582,7 @@ void HMSQuery::clear_hms_info()
std::unique_lock unique_lock(m_hms_mutex); std::unique_lock unique_lock(m_hms_mutex);
m_hms_info_jsons.clear(); m_hms_info_jsons.clear();
m_hms_action_jsons.clear(); m_hms_action_jsons.clear();
m_cloud_hms_last_update_time.clear();
} }
void HMSQuery::init_hms_info(const std::string& dev_type_id) void HMSQuery::init_hms_info(const std::string& dev_type_id)