Move cloud transfer helpers to legacy cloud services

This commit is contained in:
2026-06-15 20:05:46 +02:00
parent 1a5868376b
commit ccde4d69f4
6 changed files with 183 additions and 130 deletions

View File

@@ -226,77 +226,6 @@ void App::initLog()
LOG("load preferences failed");
}
#if WITH_CURL
int progress_callback_download(void *clientp, curl_off_t dltotal,
curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
{
(void)ultotal;
(void)ulnow;
auto* progress = static_cast<std::function<void(float)>*>(clientp);
const auto plan = pp::app::plan_cloud_transfer_progress(
static_cast<std::int64_t>(dltotal),
static_cast<std::int64_t>(dlnow));
if (progress != nullptr && *progress && plan.notify)
(*progress)(plan.fraction);
return 0;
}
int progress_callback_upload(void *clientp, curl_off_t dltotal,
curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
{
(void)dltotal;
(void)dlnow;
auto* progress = static_cast<std::function<void(float)>*>(clientp);
const auto plan = pp::app::plan_cloud_transfer_progress(
static_cast<std::int64_t>(ultotal),
static_cast<std::int64_t>(ulnow));
if (progress != nullptr && *progress && plan.notify)
(*progress)(plan.fraction);
return 0;
}
#endif //CURL
void App::download(std::string url, std::string dest_filepath, std::function<void(float)> progress)
{
#if WITH_CURL
const auto plan = pp::app::plan_cloud_download_transfer(
url,
dest_filepath,
progress != nullptr,
disables_network_tls_verification());
if (plan.action != pp::app::CloudTransferAction::start_transfer) {
LOG("download skipped: invalid transfer request");
return;
}
CURL *curl = curl_easy_init();
if (curl)
{
FILE* fp = fopen(dest_filepath.c_str(), "wb");
if (fp == nullptr) {
LOG("download failed to open destination %s", dest_filepath.c_str());
curl_easy_cleanup(curl);
return;
}
LOG("download %s to %s", url.c_str(), dest_filepath.c_str());
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_data_write);
if (plan.disable_tls_verification)
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
if (plan.enable_progress)
{
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback_download);
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &progress);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
}
auto err = curl_easy_perform(curl);
curl_easy_cleanup(curl);
fclose(fp);
}
#endif //CURL
}
bool App::check_license()
{
return true; // TODO: for distribuiton only
@@ -331,56 +260,6 @@ bool App::check_license()
return false;
}
void App::upload(std::string filename, std::string name, std::function<void(float)> progress)
{
#if WITH_CURL
const auto plan = pp::app::plan_cloud_upload_transfer(
filename,
progress != nullptr,
disables_network_tls_verification());
if (plan.action != pp::app::CloudTransferAction::start_transfer) {
LOG("upload skipped: invalid transfer request");
return;
}
CURL *curl;
struct curl_httppost *formpost = NULL;
struct curl_httppost *lastptr = NULL;
//curl_global_init(CURL_GLOBAL_ALL);
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "fileToUpload",
CURLFORM_FILE, filename.c_str(),
CURLFORM_END);
curl = curl_easy_init();
std::string res;
if (curl)
{
std::string url = "https://panopainter.com/cloud/cloud-upl.php?name=" + name;
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &res);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_data_handler);
if (plan.disable_tls_verification)
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
if (plan.enable_progress)
{
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback_upload);
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &progress);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
}
auto err = curl_easy_perform(curl);
std::cout << "\n\nUPLOAD RESULT\n" << res << "\n\n\n";
curl_easy_cleanup(curl);
}
#endif //CURL
}
void App::init()
{
LOG("Screen Resolution: %dx%d", (int)width, (int)height);