mirror of
https://github.com/QIDITECH/QIDISlicer.git
synced 2026-02-02 00:48:43 +03:00
update to latest version
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include "Mainsail.hpp"
|
||||
#include "Moonraker.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
@@ -63,28 +63,28 @@ std::string substitute_host(const std::string& orig_addr, std::string sub_addr)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Mainsail::Mainsail(DynamicPrintConfig *config) :
|
||||
Moonraker::Moonraker(DynamicPrintConfig *config) :
|
||||
m_host(config->opt_string("print_host")),
|
||||
m_apikey(config->opt_string("printhost_apikey")),
|
||||
m_cafile(config->opt_string("printhost_cafile")),
|
||||
m_ssl_revoke_best_effort(config->opt_bool("printhost_ssl_ignore_revoke"))
|
||||
{}
|
||||
|
||||
const char* Mainsail::get_name() const { return "Mainsail"; }
|
||||
const char* Moonraker::get_name() const { return "Moonraker"; }
|
||||
|
||||
wxString Mainsail::get_test_ok_msg () const
|
||||
wxString Moonraker::get_test_ok_msg () const
|
||||
{
|
||||
return _(L("Connection to Mainsail works correctly."));
|
||||
return _(L("Connection to Moonraker works correctly."));
|
||||
}
|
||||
|
||||
wxString Mainsail::get_test_failed_msg (wxString &msg) const
|
||||
wxString Moonraker::get_test_failed_msg (wxString &msg) const
|
||||
{
|
||||
return GUI::format_wxstr("%s: %s"
|
||||
, _L("Could not connect to Mainsail")
|
||||
, _L("Could not connect to Moonraker")
|
||||
, msg);
|
||||
}
|
||||
|
||||
bool Mainsail::test(wxString& msg) const
|
||||
bool Moonraker::test(wxString& msg) const
|
||||
{
|
||||
// GET /server/info
|
||||
|
||||
@@ -142,7 +142,7 @@ bool Mainsail::test(wxString& msg) const
|
||||
return res;
|
||||
}
|
||||
|
||||
bool Mainsail::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, InfoFn info_fn) const
|
||||
bool Moonraker::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, InfoFn info_fn) const
|
||||
{
|
||||
// POST /server/files/upload
|
||||
|
||||
@@ -232,15 +232,20 @@ bool Mainsail::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, Error
|
||||
return res;
|
||||
}
|
||||
|
||||
void Mainsail::set_auth(Http &http) const
|
||||
void Moonraker::set_auth(Http &http) const
|
||||
{
|
||||
if (!m_apikey.empty())
|
||||
http.header("X-Api-Key", m_apikey);
|
||||
if (!m_cafile.empty())
|
||||
http.ca_file(m_cafile);
|
||||
}
|
||||
<<<<<<< Updated upstream:src/slic3r/Utils/Mainsail.cpp
|
||||
//B4
|
||||
std::string Mainsail::make_url(const std::string &path) const
|
||||
=======
|
||||
|
||||
std::string Moonraker::make_url(const std::string &path) const
|
||||
>>>>>>> Stashed changes:src/slic3r/Utils/Moonraker.cpp
|
||||
{
|
||||
std::string m_host_add = m_host + ":10088";
|
||||
if (m_host_add.find("http://") == 0 || m_host_add.find("https://") == 0) {
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef slic3r_Mainsail_hpp_
|
||||
#define slic3r_Mainsail_hpp_
|
||||
#ifndef slic3r_Moonraker_hpp_
|
||||
#define slic3r_Moonraker_hpp_
|
||||
|
||||
#include <string>
|
||||
#include <wx/string.h>
|
||||
@@ -16,11 +16,11 @@ class DynamicPrintConfig;
|
||||
class Http;
|
||||
|
||||
// https://moonraker.readthedocs.io/en/latest/web_api
|
||||
class Mainsail : public PrintHost
|
||||
class Moonraker : public PrintHost
|
||||
{
|
||||
public:
|
||||
Mainsail(DynamicPrintConfig *config);
|
||||
~Mainsail() override = default;
|
||||
Moonraker(DynamicPrintConfig *config);
|
||||
~Moonraker() override = default;
|
||||
|
||||
const char* get_name() const override;
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace pt = boost::property_tree;
|
||||
namespace Slic3r {
|
||||
|
||||
namespace {
|
||||
#ifdef WIN32
|
||||
std::string get_host_from_url(const std::string& url_in)
|
||||
{
|
||||
std::string url = url_in;
|
||||
@@ -63,7 +64,7 @@ std::string get_host_from_url(const std::string& url_in)
|
||||
BOOST_LOG_TRIVIAL(error) << "OctoPrint get_host_from_url: failed to allocate curl_url";
|
||||
return out;
|
||||
}
|
||||
#ifdef WIN32
|
||||
|
||||
// Workaround for Windows 10/11 mDNS resolve issue, where two mDNS resolves in succession fail.
|
||||
std::string substitute_host(const std::string& orig_addr, std::string sub_addr)
|
||||
{
|
||||
@@ -470,15 +471,17 @@ bool OctoPrint::upload_inner_with_host(PrintHostUpload upload_data, ProgressFn p
|
||||
% upload_parent_path.string()
|
||||
% (upload_data.post_action == PrintHostPostUploadAction::StartPrint ? "true" : "false");
|
||||
|
||||
std::string host = get_host_from_url(m_host);
|
||||
auto http = Http::post(std::move(url));
|
||||
#ifdef WIN32
|
||||
// "Host" header is necessary here. In the workaround above (two mDNS..) we have got IP address from test connection and subsituted it into "url" variable.
|
||||
// And when creating Http object above, libcurl automatically includes "Host" header from address it got.
|
||||
// Thus "Host" is set to the resolved IP instead of host filled by user. We need to change it back.
|
||||
// Not changing the host would work on the most cases (where there is 1 service on 1 hostname) but would break when f.e. reverse proxy is used (issue #9734).
|
||||
// Also when allow_ip_resolve = 0, this is not needed, but it should not break anything if it stays.
|
||||
// https://www.rfc-editor.org/rfc/rfc7230#section-5.4
|
||||
std::string host = get_host_from_url(m_host);
|
||||
http.header("Host", host);
|
||||
#endif // _WIN32
|
||||
set_auth(http);
|
||||
http.form_add("print", upload_data.post_action == PrintHostPostUploadAction::StartPrint ? "true" : "false")
|
||||
.form_add("path", upload_parent_path.string()) // XXX: slashes on windows ???
|
||||
@@ -1036,14 +1039,16 @@ bool QIDILink::put_inner(PrintHostUpload upload_data, std::string url, const std
|
||||
bool res = true;
|
||||
// Percent escape all filenames in on path and add it to the url. This is different from POST.
|
||||
url += "/" + escape_path_by_element(upload_data.upload_path);
|
||||
std::string host = get_host_from_url(m_host);
|
||||
Http http = Http::put(std::move(url));
|
||||
#ifdef WIN32
|
||||
// "Host" header is necessary here. We have resolved IP address and subsituted it into "url" variable.
|
||||
// And when creating Http object above, libcurl automatically includes "Host" header from address it got.
|
||||
// Thus "Host" is set to the resolved IP instead of host filled by user. We need to change it back.
|
||||
// Not changing the host would work on the most cases (where there is 1 service on 1 hostname) but would break when f.e. reverse proxy is used (issue #9734).
|
||||
// https://www.rfc-editor.org/rfc/rfc7230#section-5.4
|
||||
std::string host = get_host_from_url(m_host);
|
||||
http.header("Host", host);
|
||||
#endif // _WIN32
|
||||
set_auth(http);
|
||||
// This is ugly, but works. There was an error at QIDILink side that accepts any string at Print-After-Upload as true, thus False was also triggering print after upload.
|
||||
if (upload_data.post_action == PrintHostPostUploadAction::StartPrint)
|
||||
@@ -1083,15 +1088,17 @@ bool QIDILink::post_inner(PrintHostUpload upload_data, std::string url, const st
|
||||
bool res = true;
|
||||
const auto upload_filename = upload_data.upload_path.filename();
|
||||
const auto upload_parent_path = upload_data.upload_path.parent_path();
|
||||
std::string host = get_host_from_url(m_host);
|
||||
|
||||
Http http = Http::post(std::move(url));
|
||||
#ifdef WIN32
|
||||
// "Host" header is necessary here. We have resolved IP address and subsituted it into "url" variable.
|
||||
// And when creating Http object above, libcurl automatically includes "Host" header from address it got.
|
||||
// Thus "Host" is set to the resolved IP instead of host filled by user. We need to change it back.
|
||||
// Not changing the host would work on the most cases (where there is 1 service on 1 hostname) but would break when f.e. reverse proxy is used (issue #9734).
|
||||
// https://www.rfc-editor.org/rfc/rfc7230#section-5.4
|
||||
std::string host = get_host_from_url(m_host);
|
||||
http.header("Host", host);
|
||||
#endif // _WIN32
|
||||
set_auth(http);
|
||||
set_http_post_header_args(http, upload_data.post_action);
|
||||
http.form_add("path", upload_parent_path.string()) // XXX: slashes on windows ???
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "AstroBox.hpp"
|
||||
#include "Repetier.hpp"
|
||||
#include "MKS.hpp"
|
||||
#include "Mainsail.hpp"
|
||||
#include "Moonraker.hpp"
|
||||
#include "../GUI/PrintHostDialogs.hpp"
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
@@ -55,7 +55,7 @@ PrintHost* PrintHost::get_print_host(DynamicPrintConfig *config)
|
||||
case htQIDILink: return new QIDILink(config);
|
||||
case htQIDIConnect: return new QIDIConnect(config);
|
||||
case htMKS: return new MKS(config);
|
||||
case htMainSail: return new Mainsail(config);
|
||||
case htMoonraker: return new Moonraker(config);
|
||||
default: return nullptr;
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user