Extract cloud browser thumbnail helper
This commit is contained in:
@@ -10,6 +10,41 @@
|
||||
#include "legacy_ui_overlay_services.h"
|
||||
#include "platform_api/network_tls_policy.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
bool load_cloud_thumb(CURL* curl, const std::string& name, NodeDialogCloudItem* node, std::string& response)
|
||||
{
|
||||
response.clear();
|
||||
char* url_escaped = curl_easy_escape(curl, name.c_str(), (int)name.size());
|
||||
std::string url = std::string("https://panopainter.com/cloud/cloud-info.php?file=") + url_escaped;
|
||||
delete url_escaped;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
LOG("%s", url.c_str());
|
||||
auto err = curl_easy_perform(curl);
|
||||
if (err != CURLE_OK)
|
||||
return false; // TODO: handle this error with a message or something
|
||||
|
||||
auto info = split(response, ',', 3);
|
||||
int width = atoi(info[0].c_str());
|
||||
int height = atoi(info[1].c_str());
|
||||
int comp = atoi(info[2].c_str());
|
||||
assert(comp == 4);
|
||||
std::string rgb;
|
||||
rgb.resize(Base64::DecodedLength(info[3]));
|
||||
Base64::Decode(info[3], &rgb);
|
||||
Image thumb;
|
||||
thumb.create(width, height);
|
||||
thumb.copy_from((uint8_t*)rgb.data());
|
||||
|
||||
auto image_tex = node->find<NodeImageTexture>("thumb-tex");
|
||||
image_tex->tex = std::make_shared<Texture2D>();
|
||||
image_tex->tex->create(thumb);
|
||||
|
||||
node->app_redraw();
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Node* NodeDialogCloud::clone_instantiate() const
|
||||
{
|
||||
return new NodeDialogCloud();
|
||||
@@ -138,33 +173,9 @@ void NodeDialogCloud::load_thumbs_thread()
|
||||
auto* node = nodes[i];
|
||||
if (closed)
|
||||
break;
|
||||
|
||||
res.clear();
|
||||
char* url_escaped = curl_easy_escape(curl, n.c_str(), (int)n.size());
|
||||
std::string url = std::string("https://panopainter.com/cloud/cloud-info.php?file=") + url_escaped;
|
||||
delete url_escaped;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
LOG("%s", url.c_str());
|
||||
auto err = curl_easy_perform(curl);
|
||||
if (err != CURLE_OK)
|
||||
break; // TODO: handle this error with a message or something
|
||||
auto info = split(res, ',', 3);
|
||||
int width = atoi(info[0].c_str());
|
||||
int height = atoi(info[1].c_str());
|
||||
int comp = atoi(info[2].c_str());
|
||||
assert(comp == 4);
|
||||
std::string rgb;
|
||||
rgb.resize(Base64::DecodedLength(info[3]));
|
||||
Base64::Decode(info[3], &rgb);
|
||||
Image thumb;
|
||||
thumb.create(width, height);
|
||||
thumb.copy_from((uint8_t*)rgb.data());
|
||||
|
||||
auto image_tex = node->find<NodeImageTexture>("thumb-tex");
|
||||
image_tex->tex = std::make_shared<Texture2D>();
|
||||
image_tex->tex->create(thumb);
|
||||
|
||||
app_redraw();
|
||||
if (!load_cloud_thumb(curl, n, node, res))
|
||||
break;
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user