fix curl requirement

main
Brett 2025-04-17 02:18:49 -04:00
parent 6cdfab39cf
commit 90cf177c57
2 changed files with 69 additions and 64 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20)
include(cmake/color.cmake)
set(BLT_VERSION 5.3.3)
set(BLT_VERSION 5.3.4)
set(BLT_TARGET BLT)

View File

@ -29,7 +29,7 @@
namespace blt::requests
{
#ifdef BLT_HAS_CURL
#ifdef BLT_HAS_CURL
struct curl_init_t
{
curl_init_t()
@ -75,16 +75,17 @@ namespace blt::requests
return curl_easy_init_obj.curl;
}
size_t write_to_string_func(const void* data, const size_t size, const size_t nmemb, void* user_data) {
size_t write_to_string_func(const void* data, const size_t size, const size_t nmemb, void* user_data)
{
auto& str = *static_cast<std::string*>(user_data);
str.append(static_cast<const char*>(data), size * nmemb);
return size * nmemb;
};
#endif
#endif
std::string send_get_request(const std::string& url)
{
#ifdef __EMSCRIPTEN__
#ifdef __EMSCRIPTEN__
auto* str = static_cast<char*>(EM_ASM_PTR({
var xhr = new XMLHttpRequest();
xhr.open("GET", $0);
@ -94,7 +95,8 @@ namespace blt::requests
std::string str_obj{str};
free(str);
return str_obj;
#else
#else
#ifdef BLT_HAS_CURL
init();
auto curl = easy_init();
if (!curl)
@ -107,10 +109,13 @@ namespace blt::requests
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_to_string_func);
const auto res = curl_easy_perform(curl);
if(res != CURLE_OK)
if (res != CURLE_OK)
throw std::runtime_error(curl_easy_strerror(res));
return response_string;
#endif
#else
return "Missing cURL! Unable to fetch URL: '" + url + "'";
#endif
#endif
}
}