Add download-links to tiles in /nojs

The download-link links to /nojs/download/<bookname> for all 4 types of downloads.
This commit is contained in:
Nikhil Tanwar
2023-02-15 02:43:33 +05:30
parent dbded6eee2
commit 0f7e11bd86
9 changed files with 123 additions and 14 deletions

View File

@ -759,18 +759,51 @@ std::unique_ptr<Response> InternalServer::handle_viewer_settings(const RequestCo
return ContentResponse::build(*this, RESOURCE::templates::viewer_settings_js, data, "application/javascript; charset=utf-8");
}
std::unique_ptr<Response> InternalServer::handle_no_js(const RequestContext& request)
std::string InternalServer::getNoJSDownloadPageHTML(const std::string& bookId) const
{
HTMLDumper htmlDumper(mp_library, mp_nameMapper);
htmlDumper.setRootLocation(m_root);
htmlDumper.setLibraryId(getLibraryId());
return ContentResponse::build(
*this,
htmlDumper.dumpPlainHTML(),
"text/html; charset=utf-8"
const auto book = mp_library->getBookById(bookId);
auto bookUrl = kiwix::stripSuffix(book.getUrl(), ".meta4");
return render_template(
RESOURCE::templates::no_js_download_html,
kainjow::mustache::object{
{"url", bookUrl},
{"bookTitle", book.getTitle()}
}
);
}
std::unique_ptr<Response> InternalServer::handle_no_js(const RequestContext& request)
{
const auto url = request.get_url();
const auto urlParts = kiwix::split(url, "/", true, false);
HTMLDumper htmlDumper(mp_library, mp_nameMapper);
htmlDumper.setRootLocation(m_root);
htmlDumper.setLibraryId(getLibraryId());
std::string content;
if (urlParts.size() == 1) {
content = htmlDumper.dumpPlainHTML();
} else if ((urlParts.size() == 3) && (urlParts[1] == "download")) {
try {
const auto bookId = mp_nameMapper->getIdForName(urlParts[2]);
content = getNoJSDownloadPageHTML(bookId);
} catch (const std::out_of_range&) {
return HTTP404Response(*this, request)
+ urlNotFoundMsg;
}
} else {
return HTTP404Response(*this, request)
+ urlNotFoundMsg;
}
return ContentResponse::build(
*this,
content,
"text/html; charset=utf-8"
);
}
namespace
{

View File

@ -156,6 +156,8 @@ class InternalServer {
std::string getLibraryId() const;
std::string getNoJSDownloadPageHTML(const std::string& bookId) const;
private: // types
class LockableSuggestionSearcher;
typedef ConcurrentCache<SearchInfo, std::shared_ptr<zim::Search>> SearchCache;