mirror of https://github.com/kiwix/libkiwix.git
Introduced withTaskbarInfo() helper function
This was done in preparation for removing the `bookName` and `bookTitle` parameters from `Response::build_404()`, but since the new function could already be put to some use in this commit that was done too.
This commit is contained in:
parent
d487c78ea4
commit
40e9a19c48
|
@ -519,9 +519,8 @@ std::unique_ptr<Response> InternalServer::handle_search(const RequestContext& re
|
|||
data.set("pattern", encodeDiples(patternString));
|
||||
data.set("root", m_root);
|
||||
auto response = ContentResponse::build(*this, RESOURCE::templates::no_search_result_html, data, "text/html; charset=utf-8");
|
||||
response->set_taskbar(bookName, archive ? getArchiveTitle(*archive) : "");
|
||||
response->set_code(MHD_HTTP_NOT_FOUND);
|
||||
return std::move(response);
|
||||
return withTaskbarInfo(bookName, archive.get(), std::move(response));
|
||||
}
|
||||
|
||||
std::shared_ptr<zim::Searcher> searcher;
|
||||
|
@ -591,9 +590,7 @@ std::unique_ptr<Response> InternalServer::handle_search(const RequestContext& re
|
|||
renderer.setSearchProtocolPrefix(m_root + "/search?");
|
||||
renderer.setPageLength(pageLength);
|
||||
auto response = ContentResponse::build(*this, renderer.getHtml(), "text/html; charset=utf-8");
|
||||
response->set_taskbar(bookName, archive ? getArchiveTitle(*archive) : "");
|
||||
|
||||
return std::move(response);
|
||||
return withTaskbarInfo(bookName, archive.get(), std::move(response));
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
return Response::build_500(*this, e.what());
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "tools/regexTools.h"
|
||||
#include "tools/stringTools.h"
|
||||
#include "tools/otherTools.h"
|
||||
#include "tools/archiveTools.h"
|
||||
|
||||
#include "string.h"
|
||||
#include <mustache.hpp>
|
||||
|
@ -383,6 +384,15 @@ std::unique_ptr<ContentResponse> ContentResponse::build(
|
|||
return ContentResponse::build(server, content, mimetype, isHomePage);
|
||||
}
|
||||
|
||||
std::unique_ptr<ContentResponse> withTaskbarInfo(
|
||||
const std::string& bookName,
|
||||
const zim::Archive* archive,
|
||||
std::unique_ptr<ContentResponse> r)
|
||||
{
|
||||
r->set_taskbar(bookName, archive ? getArchiveTitle(*archive) : "");
|
||||
return r;
|
||||
}
|
||||
|
||||
ItemResponse::ItemResponse(bool verbose, const zim::Item& item, const std::string& mimetype, const ByteRange& byterange) :
|
||||
Response(verbose),
|
||||
m_item(item),
|
||||
|
|
|
@ -33,6 +33,10 @@ extern "C" {
|
|||
#include "microhttpd_wrapper.h"
|
||||
}
|
||||
|
||||
namespace zim {
|
||||
class Archive;
|
||||
} // namespace zim
|
||||
|
||||
namespace kiwix {
|
||||
|
||||
class InternalServer;
|
||||
|
@ -124,6 +128,10 @@ class ContentResponse : public Response {
|
|||
std::string m_bookTitle;
|
||||
};
|
||||
|
||||
std::unique_ptr<ContentResponse> withTaskbarInfo(const std::string& bookName,
|
||||
const zim::Archive* archive,
|
||||
std::unique_ptr<ContentResponse> r);
|
||||
|
||||
class ItemResponse : public Response {
|
||||
public:
|
||||
ItemResponse(bool verbose, const zim::Item& item, const std::string& mimetype, const ByteRange& byterange);
|
||||
|
|
Loading…
Reference in New Issue