diff --git a/src/httpfetch.cpp b/src/httpfetch.cpp
index 1f9f9b96d..2e1dd54da 100644
--- a/src/httpfetch.cpp
+++ b/src/httpfetch.cpp
@@ -20,6 +20,10 @@ You should have received a copy of the GNU General Public License
along with Freeminer. If not, see .
*/
+#if defined(__EMSCRIPTEN__)
+#include
+#endif
+
#include "httpfetch.h"
#include "porting.h" // for sleep_ms(), get_sysinfo(), secure_rand_fill_buf()
#include
@@ -810,6 +814,19 @@ static void httpfetch_request_clear(u64 caller)
void httpfetch_sync(const HTTPFetchRequest &fetch_request,
HTTPFetchResult &fetch_result)
{
+// https://github.com/emscripten-core/emscripten/issues/4906
+#if defined(__EMSCRIPTEN__)
+ emscripten_fetch_attr_t attr;
+ emscripten_fetch_attr_init(&attr);
+ strcpy(attr.requestMethod, "GET");
+ attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY | EMSCRIPTEN_FETCH_SYNCHRONOUS;
+ auto *fetch = emscripten_fetch(&attr, fetch_request.url.c_str());
+ fetch_result.response_code = fetch->status;
+ fetch_result.succeeded = fetch_result.response_code == 200;
+ fetch_result.data = std::string((const char *)fetch->data, fetch->numBytes);
+ // errorstream << "emsfetch=" << fetch_result.response_code << " " << fetch_result.succeeded << " : " << readBuffer.size() << "\n";
+ emscripten_fetch_close(fetch);
+#else
// Create ongoing fetch data and make a cURL handle
// Set cURL options based on HTTPFetchRequest
CurlHandlePool pool;
@@ -818,6 +835,7 @@ void httpfetch_sync(const HTTPFetchRequest &fetch_request,
CURLcode res = ongoing.start(NULL);
// Update fetch result
fetch_result = *ongoing.complete(res);
+#endif
}
#else // USE_CURL
diff --git a/src/mapgen/earth/hgt.cpp b/src/mapgen/earth/hgt.cpp
index ff2f1c2c1..03655f819 100644
--- a/src/mapgen/earth/hgt.cpp
+++ b/src/mapgen/earth/hgt.cpp
@@ -227,15 +227,18 @@ const auto http_to_file = [](const std::string &url, const std::string &zipfull)
actionstream << req.url << " " << res.succeeded << " " << res.response_code << " "
<< res.data.size() << "\n";
- if (!res.succeeded || res.response_code >= 300)
+ if (!res.succeeded || res.response_code >= 300) {
return uintmax_t{0};
+ }
- if (!res.data.size())
+ if (!res.data.size()) {
return uintmax_t{0};
+ }
std::ofstream(zipfull) << res.data;
- if (!std::filesystem::exists(zipfull))
+ if (!std::filesystem::exists(zipfull)) {
return uintmax_t{0};
+ }
return std::filesystem::file_size(zipfull);
};
@@ -394,7 +397,13 @@ bool height_hgt::load(ll_t lat, ll_t lon)
fs::CreateAllDirs(ffolder);
multi_http_to_file(zstfile,
{
- "http://cdn.freeminer.org/earth/" + zstfile,
+#if defined(__EMSCRIPTEN__)
+ "/"
+#else
+ "http://cdn.freeminer.org/"
+#endif
+ "earth/" +
+ zstfile,
},
zstdfull);
if (std::filesystem::exists(zstdfull) && std::filesystem::file_size(zstdfull)) {
@@ -438,6 +447,7 @@ bool height_hgt::load(ll_t lat, ll_t lon)
//#if 1 //!defined(_WIN32)
// DUMP(filefull, zipfull);
+#if !defined(_WIN32) && !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
if (srtmTile.empty() && !std::filesystem::exists(filefull)) {
// TODO: https://viewfinderpanoramas.org/Coverage%20map%20viewfinderpanoramas_org15.htm
@@ -466,7 +476,7 @@ bool height_hgt::load(ll_t lat, ll_t lon)
set_ratio(filesize);
}
}
- //#endif
+#endif
// TODO: first try load unpached file, then unpack zip
if (srtmTile.empty()) {