diff options
Diffstat (limited to 'whiteboard.cpp')
-rw-r--r-- | whiteboard.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/whiteboard.cpp b/whiteboard.cpp index 88f4f3b..220d85e 100644 --- a/whiteboard.cpp +++ b/whiteboard.cpp @@ -34,11 +34,13 @@ #include <boost/asio/ip/tcp.hpp> #include <boost/asio/signal_set.hpp> #include <boost/asio/strand.hpp> +#include <boost/process.hpp> #include <fmt/core.h> #include "libreichwein/base64.h" #include "libreichwein/file.h" +#include "libreichwein/tempfile.h" #include "libreichwein/xml.h" #include "config.h" @@ -50,6 +52,7 @@ namespace pt = boost::property_tree; using namespace std::string_literals; using namespace std::placeholders; namespace fs = std::filesystem; +namespace bp = boost::process; namespace { @@ -389,6 +392,16 @@ public: } else if (command == "getstats") { setup_stats_timer(); return stats_xml(); + } else if (command == "pdf") { + std::string id {xml.get<std::string>("request.id")}; + Reichwein::Tempfile mdFilePath{".md"}; + Reichwein::File::setFile(mdFilePath.getPath(), m_storage.getDocument(id)); + Reichwein::Tempfile pdfFilePath{".pdf"}; + int system_result{bp::system("/usr/bin/pandoc", mdFilePath.getPath().generic_string(), "-o", pdfFilePath.getPath().generic_string())}; + if (system_result) + throw std::runtime_error("pandoc returned: "s + std::to_string(system_result)); + std::string pdfdata{Reichwein::File::getFile(pdfFilePath.getPath())}; + return make_xml({{"type", "pdf"}, {"pdf", Reichwein::Base64::encode64(pdfdata)}}); } else { throw std::runtime_error("Bad command: "s + command); } |