Repetier validation using 'software' value if present #7807

This commit is contained in:
Lukas Matena 2022-09-02 11:29:58 +02:00
parent 4e315bcf27
commit 39af553c2a
2 changed files with 23 additions and 10 deletions

View file

@ -35,6 +35,24 @@ Repetier::Repetier(DynamicPrintConfig *config) :
const char* Repetier::get_name() const { return "Repetier"; }
static bool validate_repetier(const boost::optional<std::string>& name,
const boost::optional<std::string>& soft)
{
if (soft) {
// See https://github.com/prusa3d/PrusaSlicer/issues/7807:
// Repetier allows "rebranding", so the "name" value is not reliable when detecting
// server type. Newer Repetier versions send "software", which should be invariant.
return ((*soft) == "Repetier-Server");
} else {
// If there is no "software" value, validate as we did before:
return name ? boost::starts_with(*name, "Repetier") : true;
}
}
bool Repetier::test(wxString &msg) const
{
// Since the request is performed synchronously here,
@ -62,11 +80,12 @@ bool Repetier::test(wxString &msg) const
std::stringstream ss(body);
pt::ptree ptree;
pt::read_json(ss, ptree);
const auto text = ptree.get_optional<std::string>("name");
res = validate_version_text(text);
const auto soft = ptree.get_optional<std::string>("software");
res = validate_repetier(text, soft);
if (! res) {
msg = GUI::from_u8((boost::format(_utf8(L("Mismatched type of print host: %s"))) % (text ? *text : "Repetier")).str());
msg = GUI::from_u8((boost::format(_utf8(L("Mismatched type of print host: %s"))) % (soft ? *soft : (text ? *text : "Repetier"))).str());
}
}
catch (const std::exception &) {
@ -154,10 +173,7 @@ bool Repetier::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, Error
return res;
}
bool Repetier::validate_version_text(const boost::optional<std::string> &version_text) const
{
return version_text ? boost::starts_with(*version_text, "Repetier") : true;
}
void Repetier::set_auth(Http &http) const
{

View file

@ -33,9 +33,6 @@ public:
bool get_groups(wxArrayString &groups) const override;
bool get_printers(wxArrayString &printers) const override;
protected:
virtual bool validate_version_text(const boost::optional<std::string> &version_text) const;
private:
std::string host;
std::string apikey;