FIX: [STUDIO-3271] load staff pick model list with network agent

Change-Id: Ie2c36348a32a4cd0c0c1457fd715619b23550794
This commit is contained in:
chunmao.guo 2023-06-16 18:43:41 +08:00 committed by Lane.Wei
parent 739d8c9b28
commit 9b5a86ba01
4 changed files with 50 additions and 14 deletions

View file

@ -5,6 +5,7 @@
#include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/MainFrame.hpp"
#include "libslic3r_version.h"
#include "../Utils/Http.hpp"
#include <wx/sizer.h>
#include <wx/toolbar.h>
@ -427,10 +428,10 @@ void WebViewPanel::SendRecentList(int images)
RunScript(wxString::Format("window.postMessage(%s)", oss.str()));
}
void WebViewPanel::SendDesignStaffpick(NetworkAgent *agent)
void WebViewPanel::SendDesignStaffpick(bool on)
{
if (agent) {
agent->get_design_staffpick(0, 60, [this](std::string body) {
if (on) {
get_design_staffpick(0, 60, [this](std::string body) {
if (body.empty() || body.front() != '{') {
BOOST_LOG_TRIVIAL(warning) << "get_design_staffpick failed " + body;
return;
@ -448,6 +449,13 @@ void WebViewPanel::SendDesignStaffpick(NetworkAgent *agent)
}
}
void WebViewPanel::OpenModelDetail(std::string id, NetworkAgent *agent)
{
std::string url;
if ((agent ? agent->get_model_mall_detail_url(&url, id) : get_model_mall_detail_url(&url, id)) == 0)
wxLaunchDefaultBrowser(url);
}
void WebViewPanel::SendLoginInfo()
{
if (wxGetApp().getAgent()) {
@ -478,6 +486,32 @@ void WebViewPanel::ShowNetpluginTip()
RunScript(strJS);
}
void WebViewPanel::get_design_staffpick(int offset, int limit, std::function<void(std::string)> callback)
{
auto host = wxGetApp().get_http_url(wxGetApp().app_config->get_country_code(), "v1/design-service/design/staffpick");
std::string url = (boost::format("%1%/?offset=%2%&limit=%3%") % host % offset % limit).str();
Http http = Http::get(url);
http.header("accept", "application/json")
.header("Content-Type", "application/json")
.on_complete([this, callback](std::string body, unsigned status) { callback(body); })
.on_error([this, callback](std::string body, std::string error, unsigned status) {
callback(body);
})
.perform();
}
int WebViewPanel::get_model_mall_detail_url(std::string *url, std::string id)
{
// https://makerhub-qa.bambu-lab.com/en/models/2077
std::string h = wxGetApp().get_model_http_url(wxGetApp().app_config->get_country_code());
auto l = wxGetApp().app_config->get("language");
if (auto n = l.find('_'); n != std::string::npos)
l = l.substr(0, n);
*url = (boost::format("%1%%2%/models/%3%") % h % l % id).str();
return 0;
}
void WebViewPanel::update_mode()
{
GetSizer()->Show(size_t(0), wxGetApp().app_config->get("internal_developer_mode") == "true");