Skip to content

Commit

Permalink
New avatar path for download. Get without access token.
Browse files Browse the repository at this point in the history
TODO: using webp as picture format.
  • Loading branch information
kocikdav authored and lukasmatena committed Feb 17, 2025
1 parent 0bd3bfb commit 8c41831
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 18 deletions.
21 changes: 17 additions & 4 deletions src/slic3r/GUI/UserAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,13 @@ void UserAccount::enqueue_connect_status_action()
{
m_communication->enqueue_connect_status_action();
}
void UserAccount::enqueue_avatar_action()
void UserAccount::enqueue_avatar_old_action()
{
m_communication->enqueue_avatar_action(m_account_user_data["avatar"]);
m_communication->enqueue_avatar_old_action(m_account_user_data["avatar"]);
}
void UserAccount::enqueue_avatar_new_action(const std::string& url)
{
m_communication->enqueue_avatar_new_action(url);
}
void UserAccount::enqueue_printer_data_action(const std::string& uuid)
{
Expand Down Expand Up @@ -145,10 +149,19 @@ bool UserAccount::on_user_id_success(const std::string data, std::string& out_us
set_username(public_username);
out_username = public_username;
// enqueue GET with avatar url
if (m_account_user_data.find("avatar") != m_account_user_data.end()) {

if (m_account_user_data.find("avatar_small") != m_account_user_data.end()) {
const boost::filesystem::path server_file(m_account_user_data["avatar_small"]);
m_avatar_extension = server_file.extension().string();
enqueue_avatar_new_action(m_account_user_data["avatar_small"]);
} else if (m_account_user_data.find("avatar_large") != m_account_user_data.end()) {
const boost::filesystem::path server_file(m_account_user_data["avatar_large"]);
m_avatar_extension = server_file.extension().string();
enqueue_avatar_new_action(m_account_user_data["avatar_large"]);
} else if (m_account_user_data.find("avatar") != m_account_user_data.end()) {
const boost::filesystem::path server_file(m_account_user_data["avatar"]);
m_avatar_extension = server_file.extension().string();
enqueue_avatar_action();
enqueue_avatar_old_action();
}
else {
BOOST_LOG_TRIVIAL(error) << "User ID message from PrusaAuth did not contain avatar.";
Expand Down
3 changes: 2 additions & 1 deletion src/slic3r/GUI/UserAccount.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class UserAccount {
bool get_remember_session();
void enqueue_connect_status_action();
void enqueue_connect_printer_models_action();
void enqueue_avatar_action();
void enqueue_avatar_old_action();
void enqueue_avatar_new_action(const std::string& url);
void enqueue_printer_data_action(const std::string& uuid);
void request_refresh();
// Clears all data and connections, called on logout or EVT_UA_RESET
Expand Down
14 changes: 12 additions & 2 deletions src/slic3r/GUI/UserAccountCommunication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,23 @@ void UserAccountCommunication::enqueue_test_connection()
wakeup_session_thread();
}

void UserAccountCommunication::enqueue_avatar_action(const std::string& url)
void UserAccountCommunication::enqueue_avatar_old_action(const std::string& url)
{
if (!m_session->is_initialized()) {
BOOST_LOG_TRIVIAL(error) << "Connect Printers endpoint connection failed - Not Logged in.";
return;
}
m_session->enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR, nullptr, nullptr, url);
m_session->enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR_OLD, nullptr, nullptr, url);
wakeup_session_thread();
}

void UserAccountCommunication::enqueue_avatar_new_action(const std::string& url)
{
if (!m_session->is_initialized()) {
BOOST_LOG_TRIVIAL(error) << "Connect Printers endpoint connection failed - Not Logged in.";
return;
}
m_session->enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR_NEW, nullptr, nullptr, url);
wakeup_session_thread();
}

Expand Down
3 changes: 2 additions & 1 deletion src/slic3r/GUI/UserAccountCommunication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class UserAccountCommunication : public wxEvtHandler
// Trigger function starts various remote operations
void enqueue_connect_status_action();
void enqueue_connect_printer_models_action();
void enqueue_avatar_action(const std::string& url);
void enqueue_avatar_old_action(const std::string& url);
void enqueue_avatar_new_action(const std::string& url);
void enqueue_test_connection();
void enqueue_printer_data_action(const std::string& uuid);
void enqueue_refresh();
Expand Down
3 changes: 2 additions & 1 deletion src/slic3r/GUI/UserAccountSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ void UserAccountSession::process_action_queue_inner()
}
}
if (call_priority || call_standard) {
m_actions[selected_data.action_id]->perform(p_evt_handler, get_access_token(), selected_data.success_callback, selected_data.fail_callback, selected_data.input);
bool use_token = m_actions[selected_data.action_id]->get_requires_auth_token();
m_actions[selected_data.action_id]->perform(p_evt_handler, use_token ? get_access_token() : std::string(), selected_data.success_callback, selected_data.fail_callback, selected_data.input);
process_action_queue_inner();
}
}
Expand Down
22 changes: 13 additions & 9 deletions src/slic3r/GUI/UserAccountSession.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,30 @@ enum class UserAccountActionID {
USER_ACCOUNT_ACTION_TEST_CONNECTION,
USER_ACCOUNT_ACTION_CONNECT_STATUS, // status of all printers by UUID
USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS, // status of all printers by UUID with printer_model. Should be called once to save printer models.
USER_ACCOUNT_ACTION_AVATAR,
USER_ACCOUNT_ACTION_AVATAR_OLD,
USER_ACCOUNT_ACTION_AVATAR_NEW,
USER_ACCOUNT_ACTION_CONNECT_DATA_FROM_UUID,
};
class UserAction
{
public:
UserAction(const std::string name, const std::string url) : m_action_name(name), m_url(url){}
UserAction(const std::string name, const std::string url, bool requires_auth_token) : m_action_name(name), m_url(url), m_requires_auth_token(requires_auth_token){}
virtual ~UserAction() = default;
virtual void perform(wxEvtHandler* evt_handler, const std::string& access_token, UserActionSuccessFn success_callback, UserActionFailFn fail_callback, const std::string& input) const = 0;

bool get_requires_auth_token() { return m_requires_auth_token; }
protected:
std::string m_action_name;
std::string m_url;
bool m_requires_auth_token;
};

class UserActionGetWithEvent : public UserAction
{
public:
UserActionGetWithEvent(const std::string name, const std::string url, wxEventType succ_event_type, wxEventType fail_event_type)
UserActionGetWithEvent(const std::string name, const std::string url, wxEventType succ_event_type, wxEventType fail_event_type, bool requires_auth_token = true)
: m_succ_evt_type(succ_event_type)
, m_fail_evt_type(fail_event_type)
, UserAction(name, url)
, UserAction(name, url, requires_auth_token)
{}
~UserActionGetWithEvent() {}
void perform(wxEvtHandler* evt_handler, const std::string& access_token, UserActionSuccessFn success_callback, UserActionFailFn fail_callback, const std::string& input) const override;
Expand All @@ -78,15 +80,15 @@ class UserActionGetWithEvent : public UserAction
class UserActionPost : public UserAction
{
public:
UserActionPost(const std::string name, const std::string url) : UserAction(name, url) {}
UserActionPost(const std::string name, const std::string url, bool requires_auth_token = true) : UserAction(name, url, requires_auth_token) {}
~UserActionPost() {}
void perform(wxEvtHandler* evt_handler, const std::string& access_token, UserActionSuccessFn success_callback, UserActionFailFn fail_callback, const std::string& input) const override;
};

class DummyUserAction : public UserAction
{
public:
DummyUserAction() : UserAction("Dummy", {}) {}
DummyUserAction() : UserAction("Dummy", {}, false) {}
~DummyUserAction() {}
void perform(wxEvtHandler* evt_handler, const std::string& access_token, UserActionSuccessFn success_callback, UserActionFailFn fail_callback, const std::string& input) const override { }
};
Expand Down Expand Up @@ -121,7 +123,8 @@ class UserAccountSession
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_TEST_CONNECTION] = std::make_unique<UserActionGetWithEvent>("TEST_CONNECTION", sc.account_me_url(), wxEVT_NULL, EVT_UA_RESET);
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_STATUS] = std::make_unique<UserActionGetWithEvent>("CONNECT_STATUS", sc.connect_status_url(), EVT_UA_PRUSACONNECT_STATUS_SUCCESS, EVT_UA_FAIL);
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS] = std::make_unique<UserActionGetWithEvent>("CONNECT_PRINTER_MODELS", sc.connect_printer_list_url(), EVT_UA_PRUSACONNECT_PRINTER_MODELS_SUCCESS, EVT_UA_FAIL);
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR] = std::make_unique<UserActionGetWithEvent>("AVATAR", sc.media_url(), EVT_UA_AVATAR_SUCCESS, EVT_UA_FAIL);
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR_OLD] = std::make_unique<UserActionGetWithEvent>("AVATAR", sc.media_url(), EVT_UA_AVATAR_SUCCESS, EVT_UA_FAIL, false);
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR_NEW] = std::make_unique<UserActionGetWithEvent>("AVATAR", std::string(), EVT_UA_AVATAR_SUCCESS, EVT_UA_FAIL, false);
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_DATA_FROM_UUID] = std::make_unique<UserActionGetWithEvent>("USER_ACCOUNT_ACTION_CONNECT_DATA_FROM_UUID", sc.connect_printers_url(), EVT_UA_PRUSACONNECT_PRINTER_DATA_SUCCESS, EVT_UA_PRUSACONNECT_PRINTER_DATA_FAIL);
}
~UserAccountSession()
Expand All @@ -133,7 +136,8 @@ class UserAccountSession
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_TEST_ACCESS_TOKEN].reset(nullptr);
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_TEST_CONNECTION].reset(nullptr);
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_STATUS].reset(nullptr);
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR].reset(nullptr);
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR_OLD].reset(nullptr);
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR_NEW].reset(nullptr);
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_DATA_FROM_UUID].reset(nullptr);
}
void clear() {
Expand Down

0 comments on commit 8c41831

Please sign in to comment.