mirror of https://github.com/kiwix/libkiwix.git
Moved taskbarInfo into ContentResponseBlueprint
This commit is contained in:
parent
2da8ea1650
commit
ec2e10b40e
|
@ -115,7 +115,9 @@ std::unique_ptr<ContentResponse> ContentResponseBlueprint::generateResponseObjec
|
|||
{
|
||||
auto r = ContentResponse::build(m_server, m_template, m_data, m_mimeType);
|
||||
r->set_code(m_httpStatusCode);
|
||||
return r;
|
||||
return m_taskbarInfo
|
||||
? withTaskbarInfo(m_taskbarInfo->bookName, m_taskbarInfo->archive, std::move(r))
|
||||
: std::move(r);
|
||||
}
|
||||
|
||||
HTTP404HtmlResponse::HTTP404HtmlResponse(const InternalServer& server,
|
||||
|
@ -143,20 +145,12 @@ HTTP404HtmlResponse& HTTP404HtmlResponse::operator+(const std::string& msg)
|
|||
return *this;
|
||||
}
|
||||
|
||||
HTTP404HtmlResponse& HTTP404HtmlResponse::operator+(const TaskbarInfo& taskbarInfo)
|
||||
ContentResponseBlueprint& ContentResponseBlueprint::operator+(const TaskbarInfo& taskbarInfo)
|
||||
{
|
||||
this->taskbarInfo.reset(new TaskbarInfo(taskbarInfo));
|
||||
this->m_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);
|
||||
|
|
|
@ -129,6 +129,17 @@ class ContentResponse : public Response {
|
|||
std::string m_bookTitle;
|
||||
};
|
||||
|
||||
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)
|
||||
{}
|
||||
};
|
||||
|
||||
std::unique_ptr<ContentResponse> withTaskbarInfo(const std::string& bookName,
|
||||
const zim::Archive* archive,
|
||||
std::unique_ptr<ContentResponse> r);
|
||||
|
@ -166,6 +177,9 @@ public: // functions
|
|||
return operator std::unique_ptr<ContentResponse>();
|
||||
}
|
||||
|
||||
|
||||
ContentResponseBlueprint& operator+(const TaskbarInfo& taskbarInfo);
|
||||
|
||||
protected: // functions
|
||||
virtual std::unique_ptr<ContentResponse> generateResponseObject() const;
|
||||
|
||||
|
@ -176,35 +190,21 @@ public: //data
|
|||
const std::string m_mimeType;
|
||||
const std::string m_template;
|
||||
kainjow::mustache::data m_data;
|
||||
std::unique_ptr<TaskbarInfo> m_taskbarInfo;
|
||||
};
|
||||
|
||||
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,
|
||||
const RequestContext& request);
|
||||
|
||||
using ContentResponseBlueprint::operator+;
|
||||
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