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) { if (archive == nullptr) {
return HTTP404Response(*this, request) return HTTP404Response(*this, request)
+ noSuchBookErrorMsg(bookName) + noSuchBookErrorMsg(bookName);
+ TaskbarInfo(bookName);
} }
const auto queryString = request.get_optional_param("term", std::string()); 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", "404-page-heading",
cssUrl); cssUrl);
response += nonParameterizedMessage("no-search-results"); 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) { if(bookIds.size() == 1) {
auto bookId = *bookIds.begin(); auto bookId = *bookIds.begin();
auto bookName = mp_nameMapper->getNameForId(bookId); auto bookName = mp_nameMapper->getNameForId(bookId);
response += TaskbarInfo(bookName, mp_library->getArchiveById(bookId).get()); response += TaskbarInfo(bookName, mp_library->getArchiveById(bookId).get());
} }
*/
return response; return response;
} }
@ -821,11 +824,15 @@ std::unique_ptr<Response> InternalServer::handle_search(const RequestContext& re
/*raw =*/true); /*raw =*/true);
} }
auto response = ContentResponse::build(*this, renderer.getHtml(), "text/html; charset=utf-8"); 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) { if(bookIds.size() == 1) {
auto bookId = *bookIds.begin(); auto bookId = *bookIds.begin();
auto bookName = mp_nameMapper->getNameForId(bookId); auto bookName = mp_nameMapper->getNameForId(bookId);
response->set_taskbar(bookName, mp_library->getArchiveById(bookId).get()); response->set_taskbar(bookName, mp_library->getArchiveById(bookId).get());
} }
*/
return std::move(response); return std::move(response);
} catch (const Error& e) { } catch (const Error& e) {
return HTTP400Response(*this, request) return HTTP400Response(*this, request)
@ -857,8 +864,7 @@ std::unique_ptr<Response> InternalServer::handle_random(const RequestContext& re
if (archive == nullptr) { if (archive == nullptr) {
return HTTP404Response(*this, request) return HTTP404Response(*this, request)
+ noSuchBookErrorMsg(bookName) + noSuchBookErrorMsg(bookName);
+ TaskbarInfo(bookName);
} }
try { try {
@ -866,8 +872,7 @@ std::unique_ptr<Response> InternalServer::handle_random(const RequestContext& re
return build_redirect(bookName, getFinalItem(*archive, entry)); return build_redirect(bookName, getFinalItem(*archive, entry));
} catch(zim::EntryNotFound& e) { } catch(zim::EntryNotFound& e) {
return HTTP404Response(*this, request) return HTTP404Response(*this, request)
+ nonParameterizedMessage("random-article-failure") + nonParameterizedMessage("random-article-failure");
+ TaskbarInfo(bookName, archive.get());
} }
} }
@ -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); const std::string searchURL = m_root + "/search?pattern=" + kiwix::urlEncode(pattern, true);
return HTTP404Response(*this, request) return HTTP404Response(*this, request)
+ urlNotFoundMsg + urlNotFoundMsg
+ suggestSearchMsg(searchURL, kiwix::urlDecode(pattern)) + suggestSearchMsg(searchURL, kiwix::urlDecode(pattern));
+ TaskbarInfo(bookName);
} }
auto urlStr = url.substr(prefixLength + bookName.size()); 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)); return build_redirect(bookName, getFinalItem(*archive, entry));
} }
auto response = ItemResponse::build(*this, request, entry.getItem()); 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()) { if (m_verbose.load()) {
printf("Found %s\n", entry.getPath().c_str()); 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); std::string searchURL = m_root + "/search?content=" + bookName + "&pattern=" + kiwix::urlEncode(pattern, true);
return HTTP404Response(*this, request) return HTTP404Response(*this, request)
+ urlNotFoundMsg + urlNotFoundMsg
+ suggestSearchMsg(searchURL, kiwix::urlDecode(pattern)) + suggestSearchMsg(searchURL, kiwix::urlDecode(pattern));
+ TaskbarInfo(bookName, archive.get());
} }
} }

View File

@ -140,9 +140,6 @@ std::unique_ptr<ContentResponse> ContentResponseBlueprint::generateResponseObjec
{ {
auto r = ContentResponse::build(m_server, m_template, m_data, m_mimeType); auto r = ContentResponse::build(m_server, m_template, m_data, m_mimeType);
r->set_code(m_httpStatusCode); r->set_code(m_httpStatusCode);
if ( m_taskbarInfo ) {
r->set_taskbar(m_taskbarInfo->bookName, m_taskbarInfo->archive);
}
return r; return r;
} }
@ -246,19 +243,6 @@ std::unique_ptr<ContentResponse> HTTP500Response::generateResponseObject() const
return r; 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) std::unique_ptr<Response> Response::build_416(const InternalServer& server, size_t resourceLength)
{ {
auto response = Response::build(server); auto response = Response::build(server);
@ -430,22 +414,13 @@ MHD_Result Response::send(const RequestContext& request, MHD_Connection* connect
return ret; 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) : 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), Response(verbose),
m_root(root), m_root(root),
m_content(content), m_content(content),
m_mimeType(mimetype), m_mimeType(mimetype),
m_raw(raw), m_raw(raw),
m_blockExternalLinks(blockExternalLinks), m_blockExternalLinks(blockExternalLinks)
m_bookName(""),
m_bookTitle("")
{ {
add_header(MHD_HTTP_HEADER_CONTENT_TYPE, m_mimeType); add_header(MHD_HTTP_HEADER_CONTENT_TYPE, m_mimeType);
} }

View File

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