Dropped TaskbarInfo

This commit is contained in:
Veloman Yunkan 2022-06-26 13:28:30 +04:00
parent 40c496d401
commit 0cf4850a9b
3 changed files with 14 additions and 60 deletions

View File

@ -653,8 +653,7 @@ std::unique_ptr<Response> InternalServer::handle_suggest(const RequestContext& r
if (archive == nullptr) {
return HTTP404Response(*this, request)
+ noSuchBookErrorMsg(bookName)
+ TaskbarInfo(bookName);
+ noSuchBookErrorMsg(bookName);
}
const auto queryString = request.get_optional_param("term", std::string());
@ -782,11 +781,15 @@ std::unique_ptr<Response> InternalServer::handle_search(const RequestContext& re
"404-page-heading",
cssUrl);
response += nonParameterizedMessage("no-search-results");
// XXX: Now this has to be handled by the iframe-based viewer which
// XXX: has to resolve if the book selection resulted in a single book.
/*
if(bookIds.size() == 1) {
auto bookId = *bookIds.begin();
auto bookName = mp_nameMapper->getNameForId(bookId);
response += TaskbarInfo(bookName, mp_library->getArchiveById(bookId).get());
}
*/
return response;
}
@ -821,11 +824,15 @@ std::unique_ptr<Response> InternalServer::handle_search(const RequestContext& re
/*raw =*/true);
}
auto response = ContentResponse::build(*this, renderer.getHtml(), "text/html; charset=utf-8");
// XXX: Now this has to be handled by the iframe-based viewer which
// XXX: has to resolve if the book selection resulted in a single book.
/*
if(bookIds.size() == 1) {
auto bookId = *bookIds.begin();
auto bookName = mp_nameMapper->getNameForId(bookId);
response->set_taskbar(bookName, mp_library->getArchiveById(bookId).get());
}
*/
return std::move(response);
} catch (const Error& e) {
return HTTP400Response(*this, request)
@ -857,8 +864,7 @@ std::unique_ptr<Response> InternalServer::handle_random(const RequestContext& re
if (archive == nullptr) {
return HTTP404Response(*this, request)
+ noSuchBookErrorMsg(bookName)
+ TaskbarInfo(bookName);
+ noSuchBookErrorMsg(bookName);
}
try {
@ -866,8 +872,7 @@ std::unique_ptr<Response> InternalServer::handle_random(const RequestContext& re
return build_redirect(bookName, getFinalItem(*archive, entry));
} catch(zim::EntryNotFound& e) {
return HTTP404Response(*this, request)
+ nonParameterizedMessage("random-article-failure")
+ TaskbarInfo(bookName, archive.get());
+ nonParameterizedMessage("random-article-failure");
}
}
@ -1015,8 +1020,7 @@ std::unique_ptr<Response> InternalServer::handle_content(const RequestContext& r
const std::string searchURL = m_root + "/search?pattern=" + kiwix::urlEncode(pattern, true);
return HTTP404Response(*this, request)
+ urlNotFoundMsg
+ suggestSearchMsg(searchURL, kiwix::urlDecode(pattern))
+ TaskbarInfo(bookName);
+ suggestSearchMsg(searchURL, kiwix::urlDecode(pattern));
}
auto urlStr = url.substr(prefixLength + bookName.size());
@ -1032,9 +1036,6 @@ std::unique_ptr<Response> InternalServer::handle_content(const RequestContext& r
return build_redirect(bookName, getFinalItem(*archive, entry));
}
auto response = ItemResponse::build(*this, request, entry.getItem());
try {
dynamic_cast<ContentResponse&>(*response).set_taskbar(bookName, archive.get());
} catch (std::bad_cast& e) {}
if (m_verbose.load()) {
printf("Found %s\n", entry.getPath().c_str());
@ -1049,8 +1050,7 @@ std::unique_ptr<Response> InternalServer::handle_content(const RequestContext& r
std::string searchURL = m_root + "/search?content=" + bookName + "&pattern=" + kiwix::urlEncode(pattern, true);
return HTTP404Response(*this, request)
+ urlNotFoundMsg
+ suggestSearchMsg(searchURL, kiwix::urlDecode(pattern))
+ TaskbarInfo(bookName, archive.get());
+ suggestSearchMsg(searchURL, kiwix::urlDecode(pattern));
}
}

View File

@ -140,9 +140,6 @@ std::unique_ptr<ContentResponse> ContentResponseBlueprint::generateResponseObjec
{
auto r = ContentResponse::build(m_server, m_template, m_data, m_mimeType);
r->set_code(m_httpStatusCode);
if ( m_taskbarInfo ) {
r->set_taskbar(m_taskbarInfo->bookName, m_taskbarInfo->archive);
}
return r;
}
@ -246,19 +243,6 @@ std::unique_ptr<ContentResponse> HTTP500Response::generateResponseObject() const
return r;
}
ContentResponseBlueprint& ContentResponseBlueprint::operator+(const TaskbarInfo& taskbarInfo)
{
this->m_taskbarInfo.reset(new TaskbarInfo(taskbarInfo));
return *this;
}
ContentResponseBlueprint& ContentResponseBlueprint::operator+=(const TaskbarInfo& taskbarInfo)
{
// operator+() is already a state-modifying operator (akin to operator+=)
return *this + taskbarInfo;
}
std::unique_ptr<Response> Response::build_416(const InternalServer& server, size_t resourceLength)
{
auto response = Response::build(server);
@ -430,22 +414,13 @@ MHD_Result Response::send(const RequestContext& request, MHD_Connection* connect
return ret;
}
void ContentResponse::set_taskbar(const std::string& bookName, const zim::Archive* archive)
{
m_bookName = bookName;
m_bookTitle = archive ? getArchiveTitle(*archive) : "";
}
ContentResponse::ContentResponse(const std::string& root, bool verbose, bool raw, bool /*withTaskbar*/, bool /*withLibraryButton*/, bool blockExternalLinks, const std::string& content, const std::string& mimetype) :
Response(verbose),
m_root(root),
m_content(content),
m_mimeType(mimetype),
m_raw(raw),
m_blockExternalLinks(blockExternalLinks),
m_bookName(""),
m_bookTitle("")
m_blockExternalLinks(blockExternalLinks)
{
add_header(MHD_HTTP_HEADER_CONTENT_TYPE, m_mimeType);
}

View File

@ -102,8 +102,6 @@ class ContentResponse : public Response {
const std::string& mimetype,
bool isHomePage = false);
void set_taskbar(const std::string& bookName, const zim::Archive* archive);
private:
MHD_Response* create_mhd_response(const RequestContext& request);
@ -119,21 +117,8 @@ class ContentResponse : public Response {
std::string m_mimeType;
bool m_raw;
bool m_blockExternalLinks;
std::string m_bookName;
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)
{}
};
class ContentResponseBlueprint
{
public: // functions
@ -162,9 +147,6 @@ public: // functions
}
ContentResponseBlueprint& operator+(const TaskbarInfo& taskbarInfo);
ContentResponseBlueprint& operator+=(const TaskbarInfo& taskbarInfo);
protected: // functions
std::string getMessage(const std::string& msgId) const;
virtual std::unique_ptr<ContentResponse> generateResponseObject() const;
@ -176,7 +158,6 @@ public: //data
const std::string m_mimeType;
const std::string m_template;
kainjow::mustache::data m_data;
std::unique_ptr<TaskbarInfo> m_taskbarInfo;
};
struct HTTPErrorResponse : ContentResponseBlueprint
@ -188,8 +169,6 @@ struct HTTPErrorResponse : ContentResponseBlueprint
const std::string& headingMsgId,
const std::string& cssUrl = "");
using ContentResponseBlueprint::operator+;
using ContentResponseBlueprint::operator+=;
HTTPErrorResponse& operator+(const std::string& msg);
HTTPErrorResponse& operator+(const ParameterizedMessage& errorDetails);
HTTPErrorResponse& operator+=(const ParameterizedMessage& errorDetails);