1
0
mirror of synced 2024-11-12 10:10:53 +01:00

net: Increase store load timeout to 30 seconds

This commit is contained in:
WerWolv 2022-02-21 18:57:53 +01:00
parent a8e83154f0
commit 7d9c24ff51
4 changed files with 13 additions and 9 deletions

View File

@ -35,11 +35,13 @@ namespace hex {
Net(); Net();
~Net(); ~Net();
std::future<Response<std::string>> getString(const std::string &url, u32 timeout = 2000); static constexpr u32 DefaultTimeout = 2'000;
std::future<Response<nlohmann::json>> getJson(const std::string &url, u32 timeout = 2000);
std::future<Response<std::string>> uploadFile(const std::string &url, const fs::path &filePath, u32 timeout = 2000); std::future<Response<std::string>> getString(const std::string &url, u32 timeout = DefaultTimeout);
std::future<Response<void>> downloadFile(const std::string &url, const fs::path &filePath, u32 timeout = 2000); std::future<Response<nlohmann::json>> getJson(const std::string &url, u32 timeout = DefaultTimeout);
std::future<Response<std::string>> uploadFile(const std::string &url, const fs::path &filePath, u32 timeout = DefaultTimeout);
std::future<Response<void>> downloadFile(const std::string &url, const fs::path &filePath, u32 timeout = DefaultTimeout);
[[nodiscard]] std::string encode(const std::string &input); [[nodiscard]] std::string encode(const std::string &input);

View File

@ -121,7 +121,7 @@ namespace hex {
std::optional<i32> Net::execute() { std::optional<i32> Net::execute() {
CURLcode result = curl_easy_perform(this->m_ctx); CURLcode result = curl_easy_perform(this->m_ctx);
if (result != CURLE_OK) if (result != CURLE_OK)
log::error("Net request failed with error {}!", curl_easy_strerror(result)); log::error("Net request failed with error {0}: '{1}'", result, curl_easy_strerror(result));
i32 responseCode = 0; i32 responseCode = 0;
curl_easy_getinfo(this->m_ctx, CURLINFO_RESPONSE_CODE, &responseCode); curl_easy_getinfo(this->m_ctx, CURLINFO_RESPONSE_CODE, &responseCode);

View File

@ -37,6 +37,9 @@ namespace hex::plugin::builtin {
[[nodiscard]] bool isAvailable() const override { return true; } [[nodiscard]] bool isAvailable() const override { return true; }
[[nodiscard]] bool hasViewMenuItemEntry() const override { return false; } [[nodiscard]] bool hasViewMenuItemEntry() const override { return false; }
[[nodiscard]] ImVec2 getMinSize() const override { return { 500, 400 }; }
[[nodiscard]] ImVec2 getMaxSize() const override { return { 500, 400 }; }
private: private:
Net m_net; Net m_net;
std::future<Response<std::string>> m_apiRequest; std::future<Response<std::string>> m_apiRequest;

View File

@ -161,7 +161,7 @@ namespace hex::plugin::builtin {
this->m_yara.clear(); this->m_yara.clear();
this->m_encodings.clear(); this->m_encodings.clear();
this->m_apiRequest = this->m_net.getString(ImHexApiURL + "/store"s); this->m_apiRequest = this->m_net.getString(ImHexApiURL + "/store"s, 30'0000);
} }
void ViewStore::parseResponse() { void ViewStore::parseResponse() {
@ -218,8 +218,7 @@ namespace hex::plugin::builtin {
} }
void ViewStore::drawContent() { void ViewStore::drawContent() {
ImGui::SetNextWindowSizeConstraints(scaled(ImVec2(600, 400)), ImVec2(FLT_MAX, FLT_MAX)); if (ImGui::BeginPopupModal(View::toWindowName("hex.builtin.view.store.name").c_str(), &this->getWindowOpenState())) {
if (ImGui::BeginPopupModal(View::toWindowName("hex.builtin.view.store.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_AlwaysAutoResize)) {
if (this->m_apiRequest.valid()) { if (this->m_apiRequest.valid()) {
if (this->m_apiRequest.wait_for(0s) != std::future_status::ready) if (this->m_apiRequest.wait_for(0s) != std::future_status::ready)
ImGui::TextSpinner("hex.builtin.view.store.loading"_lang); ImGui::TextSpinner("hex.builtin.view.store.loading"_lang);
@ -242,7 +241,7 @@ namespace hex::plugin::builtin {
if (!update || fs::exists(fullPath)) { if (!update || fs::exists(fullPath)) {
downloading = true; downloading = true;
this->m_downloadPath = fullPath; this->m_downloadPath = fullPath;
this->m_download = this->m_net.downloadFile(url, fullPath); this->m_download = this->m_net.downloadFile(url, fullPath, 30'0000);
break; break;
} }
} }