summaryrefslogtreecommitdiffhomepage
path: root/whiteboard.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2023-02-10 18:02:40 +0100
committerRoland Reichwein <mail@reichwein.it>2023-02-10 18:02:40 +0100
commit40506bc32efca98b43a72202d0823cdd3c8b2c05 (patch)
tree11f3c81f774362a40a069ad6f9c8d208984b5bd8 /whiteboard.cpp
parent87c11f835502c97b4f54d4d73f55eef496e67103 (diff)
Add download Markdown as PDFv1.7
Diffstat (limited to 'whiteboard.cpp')
-rw-r--r--whiteboard.cpp13
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);
}