mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-12 17:27:52 -06:00
Added possibility for upload to Duet
Further changes: - Added new configuration option Host Type - Added abstract base class for future printer hosts - Moved location of upload dialog (also made it a little bit more configureable) - added possibility to send file via postfield instead a new frame
This commit is contained in:
parent
3433e8e374
commit
dd1fd66a47
29 changed files with 699 additions and 128 deletions
|
@ -4,6 +4,7 @@
|
|||
#include <functional>
|
||||
#include <thread>
|
||||
#include <deque>
|
||||
#include <sstream>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/format.hpp>
|
||||
|
||||
|
@ -42,6 +43,7 @@ struct Http::priv
|
|||
// Used for storing file streams added as multipart form parts
|
||||
// Using a deque here because unlike vector it doesn't ivalidate pointers on insertion
|
||||
std::deque<fs::ifstream> form_files;
|
||||
std::string postfields;
|
||||
size_t limit;
|
||||
bool cancel;
|
||||
|
||||
|
@ -60,6 +62,7 @@ struct Http::priv
|
|||
static size_t form_file_read_cb(char *buffer, size_t size, size_t nitems, void *userp);
|
||||
|
||||
void form_add_file(const char *name, const fs::path &path, const char* filename);
|
||||
void postfield_add_file(const fs::path &path);
|
||||
|
||||
std::string curl_error(CURLcode curlcode);
|
||||
std::string body_size_error();
|
||||
|
@ -187,6 +190,16 @@ void Http::priv::form_add_file(const char *name, const fs::path &path, const cha
|
|||
}
|
||||
}
|
||||
|
||||
void Http::priv::postfield_add_file(const fs::path &path)
|
||||
{
|
||||
std::ifstream f (path.string());
|
||||
std::string file_content { std::istreambuf_iterator<char>(f), std::istreambuf_iterator<char>() };
|
||||
if (!postfields.empty()) {
|
||||
postfields += "&";
|
||||
}
|
||||
postfields += file_content;
|
||||
}
|
||||
|
||||
std::string Http::priv::curl_error(CURLcode curlcode)
|
||||
{
|
||||
return (boost::format("%1% (%2%)")
|
||||
|
@ -229,6 +242,11 @@ void Http::priv::http_perform()
|
|||
::curl_easy_setopt(curl, CURLOPT_HTTPPOST, form);
|
||||
}
|
||||
|
||||
if (!postfields.empty()) {
|
||||
::curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postfields.c_str());
|
||||
::curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, postfields.size());
|
||||
}
|
||||
|
||||
CURLcode res = ::curl_easy_perform(curl);
|
||||
|
||||
if (res != CURLE_OK) {
|
||||
|
@ -338,6 +356,12 @@ Http& Http::form_add_file(const std::string &name, const fs::path &path, const s
|
|||
return *this;
|
||||
}
|
||||
|
||||
Http& Http::postfield_add_file(const fs::path &path)
|
||||
{
|
||||
if (p) { p->postfield_add_file(path);}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Http& Http::on_complete(CompleteFn fn)
|
||||
{
|
||||
if (p) { p->completefn = std::move(fn); }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue