diff --git a/src/kamokan_impl/submit_paste_response.cpp b/src/kamokan_impl/submit_paste_response.cpp index 8bbb063..bf8dac4 100644 --- a/src/kamokan_impl/submit_paste_response.cpp +++ b/src/kamokan_impl/submit_paste_response.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace kamokan { namespace { @@ -144,18 +145,22 @@ namespace kamokan { //over invalid inputs const uint32_t duration_int = std::max(std::min((duration.empty() ? 86400U : boost::lexical_cast(duration)), 2628000U), 1U); StringOrHeader submit_result = submit_to_storage(pastie, duration_int, lang, self_destruct); - const auto& token = submit_result.first; + const boost::optional& token = submit_result.first; if (token) { + m_pastie_token = std::move(*token); std::ostringstream oss; - oss << *token; + oss << m_pastie_token; if (not lang.empty()) oss << '?' << lang; std::string redirect = oss.str(); - statuslog->info("Pastie token=\"{}\" redirect=\"{}\"", *token, redirect); + statuslog->info("Pastie token=\"{}\" redirect=\"{}\"", m_pastie_token, redirect); - return this->make_success_response(std::move(redirect)); + if (self_destruct) + return tawashi::make_header_type_html(); + else + return this->make_success_response(std::move(redirect)); } else { statuslog->info("Empty pastie token (possibly due to a previous failure)"); @@ -182,4 +187,8 @@ namespace kamokan { using tawashi::HttpStatusCodes; return this->make_redirect(HttpStatusCodes::Code303_SeeOther, std::move(parPastieParam)); } + + void SubmitPasteResponse::on_mustache_prepare (mstch::map& parContext) { + parContext["pastie_token"] = std::move(m_pastie_token); + } } //namespace kamokan diff --git a/src/kamokan_impl/submit_paste_response.hpp b/src/kamokan_impl/submit_paste_response.hpp index d8a8768..9b8a2ce 100644 --- a/src/kamokan_impl/submit_paste_response.hpp +++ b/src/kamokan_impl/submit_paste_response.hpp @@ -43,18 +43,21 @@ namespace kamokan { ); protected: - virtual boost::string_view page_basename() const override { assert(false); return boost::string_view(""); } + virtual boost::string_view page_basename() const override { return boost::string_view("saved"); } virtual tawashi::HttpHeader make_success_response (std::string&& parPastieParam); private: typedef std::pair, tawashi::HttpHeader> StringOrHeader; virtual tawashi::HttpHeader on_process() override; + virtual void on_mustache_prepare (mstch::map& parContext) override; StringOrHeader submit_to_storage ( const boost::string_view& parText, uint32_t parExpiry, const boost::string_view& parLang, bool parSelfDestruct ); + + std::string m_pastie_token; }; } //namespace kamokan