mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-09 16:51:12 +00:00
fix: handle missing API keys correctly
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include <string>
|
||||
#include "slic3r/GUI/wxExtensions.hpp"
|
||||
#include "libslic3r/AppConfig.hpp"
|
||||
#include "IPrinterAgent.hpp"
|
||||
|
||||
#include "DeviceCore/DevManager.h"
|
||||
|
||||
@@ -169,14 +170,16 @@ void ConnectPrinterDialog::on_input_enter(wxCommandEvent& evt)
|
||||
void ConnectPrinterDialog::on_button_confirm(wxCommandEvent &event)
|
||||
{
|
||||
wxString code = m_textCtrl_code->GetTextCtrl()->GetValue();
|
||||
if (code.empty())
|
||||
code = "88888888";
|
||||
// Validate only what the user typed; the no-key sentinel is applied afterwards (it contains
|
||||
// non-alphanumeric characters, so it must not go through this check).
|
||||
for (char c : code) {
|
||||
if (!(('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))) {
|
||||
show_error(this, _L("Invalid input"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (code.empty())
|
||||
code = NO_API_KEY_SENTINEL;
|
||||
if (m_obj) {
|
||||
m_obj->set_access_code(code.ToStdString());
|
||||
}
|
||||
|
||||
@@ -2681,7 +2681,8 @@ int MachineObject::connect()
|
||||
{
|
||||
if (get_dev_ip().empty()) return -1;
|
||||
std::string username = m_agent ? m_agent->default_lan_username() : std::string();
|
||||
std::string password = get_access_code();
|
||||
// The stored access code may be the "no API key" sentinel; agents expect an empty credential.
|
||||
std::string password = normalize_access_code(get_access_code());
|
||||
|
||||
std::string port;
|
||||
std::string input = get_dev_ip();
|
||||
|
||||
@@ -4263,7 +4263,7 @@ void GUI_App::select_machine(const std::string& agent_id)
|
||||
auto access_code = preset.config.opt_string("printhost_apikey");
|
||||
// Orca expect non empty access code
|
||||
if (access_code.empty()) {
|
||||
access_code = "88888888";
|
||||
access_code = NO_API_KEY_SENTINEL;
|
||||
}
|
||||
|
||||
existing = m_device_manager->insert_local_device(
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "I18N.hpp"
|
||||
|
||||
#include "bambu_networking.hpp"
|
||||
#include "IPrinterAgent.hpp"
|
||||
#include "libslic3r/Utils.hpp"
|
||||
#include "GUI.hpp"
|
||||
#include "GUI_App.hpp"
|
||||
@@ -1903,7 +1904,7 @@ void InputIpAddressDialog::on_ok(wxMouseEvent& evt)
|
||||
std::string str_ip = m_input_ip->GetTextCtrl()->GetValue().ToStdString();
|
||||
std::string str_access_code = m_input_access_code->GetTextCtrl()->GetValue().ToStdString();
|
||||
if (str_access_code.empty())
|
||||
str_access_code = "88888888";
|
||||
str_access_code = NO_API_KEY_SENTINEL;
|
||||
std::string str_name = m_input_printer_name->GetTextCtrl()->GetValue().Strip(wxString::both).ToStdString();
|
||||
// Serial number should not contain lower case letters, and bambu_network plugin crashes
|
||||
// if user entered the wrong serial number, so we call `Upper()` here.
|
||||
@@ -1950,7 +1951,7 @@ void InputIpAddressDialog::on_send_retry()
|
||||
wxString ip = m_input_ip->GetTextCtrl()->GetValue();
|
||||
wxString str_access_code = m_input_access_code->GetTextCtrl()->GetValue();
|
||||
if (str_access_code.IsEmpty())
|
||||
str_access_code = "88888888";
|
||||
str_access_code = NO_API_KEY_SENTINEL;
|
||||
|
||||
// check support function
|
||||
if (!m_obj) return;
|
||||
|
||||
@@ -45,6 +45,17 @@ struct PrinterConnectionParams
|
||||
std::string ca_file;
|
||||
};
|
||||
|
||||
// Sentinel stored as a LAN device's access code when the user has not supplied one, so the device
|
||||
// stays registered (has_access_right() is !access_code.empty()). It is not a real credential: every
|
||||
// printer agent must translate it back to an empty string before using/sending it on the wire.
|
||||
inline constexpr const char* NO_API_KEY_SENTINEL = "*_{NO_API_KEY}_*";
|
||||
|
||||
// Returns an empty string when `code` is the "no API key" sentinel, otherwise `code` unchanged.
|
||||
inline std::string normalize_access_code(const std::string& code)
|
||||
{
|
||||
return code == NO_API_KEY_SENTINEL ? std::string() : code;
|
||||
}
|
||||
|
||||
/**
|
||||
* FilamentSyncMode - Modes for filament data synchronization.
|
||||
*
|
||||
|
||||
@@ -2338,7 +2338,7 @@ void MoonrakerPrinterAgent::announce_printhost_device()
|
||||
const std::string model_id = device_info.model_id;
|
||||
|
||||
if (auto* app_config = GUI::wxGetApp().app_config) {
|
||||
const std::string access_code = device_info.api_key.empty() ? "88888888" : device_info.api_key;
|
||||
const std::string access_code = device_info.api_key.empty() ? NO_API_KEY_SENTINEL : device_info.api_key;
|
||||
app_config->set_str("access_code", device_info.dev_id, access_code);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user