mirror of https://github.com/kiwix/libkiwix.git
Enter TaskbarInfo
After this change it's time to say thank you and good-bye to `withTaskbarInfo()`. But it will take a while.
This commit is contained in:
parent
9bc09a815c
commit
0ecbdbcf63
|
@ -627,9 +627,9 @@ std::unique_ptr<Response> InternalServer::handle_random(const RequestContext& re
|
|||
}
|
||||
|
||||
if (archive == nullptr) {
|
||||
const std::string error_details = noSuchBookErrorMsg(bookName);
|
||||
auto response = Response::build_404(*this, "", error_details);
|
||||
return withTaskbarInfo(bookName, nullptr, std::move(response));
|
||||
return HTTP404HtmlResponse(*this, request)
|
||||
+ noSuchBookErrorMsg(bookName)
|
||||
+ TaskbarInfo(bookName);
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
@ -136,6 +136,20 @@ HTTP404HtmlResponse& HTTP404HtmlResponse::operator+(const std::string& msg)
|
|||
return *this;
|
||||
}
|
||||
|
||||
HTTP404HtmlResponse& HTTP404HtmlResponse::operator+(const TaskbarInfo& taskbarInfo)
|
||||
{
|
||||
this->taskbarInfo.reset(new TaskbarInfo(taskbarInfo));
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::unique_ptr<ContentResponse> HTTP404HtmlResponse::generateResponseObject() const
|
||||
{
|
||||
auto r = ContentResponseBlueprint::generateResponseObject();
|
||||
return taskbarInfo
|
||||
? withTaskbarInfo(taskbarInfo->bookName, taskbarInfo->archive, std::move(r))
|
||||
: std::move(r);
|
||||
}
|
||||
|
||||
std::unique_ptr<Response> Response::build_416(const InternalServer& server, size_t resourceLength)
|
||||
{
|
||||
auto response = Response::build(server);
|
||||
|
|
|
@ -148,6 +148,8 @@ public: // functions
|
|||
, m_template(templateStr)
|
||||
{}
|
||||
|
||||
virtual ~ContentResponseBlueprint() = default;
|
||||
|
||||
ContentResponseBlueprint& operator+(kainjow::mustache::data&& data)
|
||||
{
|
||||
this->m_data = std::move(data);
|
||||
|
@ -155,6 +157,11 @@ public: // functions
|
|||
}
|
||||
|
||||
operator std::unique_ptr<ContentResponse>() const
|
||||
{
|
||||
return generateResponseObject();
|
||||
}
|
||||
|
||||
virtual std::unique_ptr<ContentResponse> generateResponseObject() const
|
||||
{
|
||||
auto r = ContentResponse::build(m_server, m_template, m_data, m_mimeType);
|
||||
r->set_code(m_httpStatusCode);
|
||||
|
@ -179,6 +186,17 @@ class UrlNotFoundMsg {};
|
|||
|
||||
extern const UrlNotFoundMsg urlNotFoundMsg;
|
||||
|
||||
struct TaskbarInfo
|
||||
{
|
||||
const std::string bookName;
|
||||
const zim::Archive* const archive;
|
||||
|
||||
TaskbarInfo(const std::string& bookName, const zim::Archive* a = nullptr)
|
||||
: bookName(bookName)
|
||||
, archive(a)
|
||||
{}
|
||||
};
|
||||
|
||||
struct HTTP404HtmlResponse : ContentResponseBlueprint
|
||||
{
|
||||
HTTP404HtmlResponse(const InternalServer& server,
|
||||
|
@ -186,6 +204,11 @@ struct HTTP404HtmlResponse : ContentResponseBlueprint
|
|||
|
||||
HTTP404HtmlResponse& operator+(UrlNotFoundMsg /*unused*/);
|
||||
HTTP404HtmlResponse& operator+(const std::string& errorDetails);
|
||||
HTTP404HtmlResponse& operator+(const TaskbarInfo& taskbarInfo);
|
||||
|
||||
std::unique_ptr<ContentResponse> generateResponseObject() const override;
|
||||
|
||||
std::unique_ptr<TaskbarInfo> taskbarInfo;
|
||||
};
|
||||
|
||||
class ItemResponse : public Response {
|
||||
|
|
Loading…
Reference in New Issue