mirror of
https://github.com/KingDuckZ/kamokan.git
synced 2024-12-27 21:35:41 +00:00
Don't redirect after submitting a self-destructing token.
This commit is contained in:
parent
86a576985e
commit
61170dc371
2 changed files with 17 additions and 5 deletions
|
@ -29,6 +29,7 @@
|
|||
#include <boost/lexical_cast.hpp>
|
||||
#include <cstdint>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <utility>
|
||||
|
||||
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<uint32_t>(duration)), 2628000U), 1U);
|
||||
StringOrHeader submit_result = submit_to_storage(pastie, duration_int, lang, self_destruct);
|
||||
const auto& token = submit_result.first;
|
||||
const boost::optional<std::string>& 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
|
||||
|
|
|
@ -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<boost::optional<std::string>, 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
|
||||
|
|
Loading…
Reference in a new issue