mirror of
https://github.com/kiwix/libkiwix.git
synced 2025-09-22 03:33:41 -04:00
Empty root isn't confused with missing contentServerURL
Running kiwix-serve without --catalogOnly and --urlRootLocation resulted in non-clickable book tiles since empty root was confused with empty contentServerURL which controlled whether book preview links should be activated. This commit fixes that bug and adds respective unit-tests.
This commit is contained in:
parent
2b4b90f8a3
commit
67b7e25494
@ -858,9 +858,9 @@ std::unique_ptr<Response> InternalServer::handle_no_js(const RequestContext& req
|
||||
htmlDumper.setRootLocation(m_root);
|
||||
htmlDumper.setLibraryId(getLibraryId());
|
||||
if ( !m_contentServerUrl.empty() ) {
|
||||
htmlDumper.setContentServerUrl(m_contentServerUrl);
|
||||
htmlDumper.setContentServerUrl(m_contentServerUrl + "/content");
|
||||
} else if ( !m_catalogOnlyMode ) {
|
||||
htmlDumper.setContentServerUrl(m_root);
|
||||
htmlDumper.setContentServerUrl(m_root + "/content");
|
||||
}
|
||||
auto userLang = request.get_user_language();
|
||||
htmlDumper.setUserLanguage(userLang);
|
||||
|
@ -57,9 +57,9 @@ OPDSDumper InternalServer::getOPDSDumper() const
|
||||
opdsDumper.setRootLocation(m_root);
|
||||
opdsDumper.setLibraryId(getLibraryId());
|
||||
if ( !m_contentServerUrl.empty() ) {
|
||||
opdsDumper.setContentServerUrl(m_contentServerUrl);
|
||||
opdsDumper.setContentServerUrl(m_contentServerUrl + "/content");
|
||||
} else if ( !m_catalogOnlyMode ) {
|
||||
opdsDumper.setContentServerUrl(m_root);
|
||||
opdsDumper.setContentServerUrl(m_root + "/content");
|
||||
}
|
||||
return opdsDumper;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
{{#icons}}<link rel="http://opds-spec.org/image/thumbnail"
|
||||
href="{{root}}/catalog/v2/illustration/{{{id}}}/?size={{icon_size}}"
|
||||
type="{{icon_mimetype}};width={{icon_size}};height={{icon_size}};scale=1"/>
|
||||
{{/icons}}{{#contentServerUrl}}<link type="text/html" href="{{contentServerUrl}}/content/{{{content_id}}}" />
|
||||
{{/icons}}{{#contentServerUrl}}<link type="text/html" href="{{contentServerUrl}}/{{{content_id}}}" />
|
||||
{{/contentServerUrl}}
|
||||
<author>
|
||||
<name>{{author_name}}</name>
|
||||
|
@ -3,7 +3,6 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<link type="root" href="{{root}}">
|
||||
<title>{{translations.welcome-to-kiwix-server}}</title>
|
||||
<link
|
||||
type="text/css"
|
||||
@ -108,7 +107,7 @@
|
||||
<h3 class="kiwixHomeBody__results">{{translations.count-of-matching-books}}</h3>
|
||||
{{#books}}
|
||||
<div class="book__wrapper">
|
||||
{{#contentServerUrl}}<a class="book__link" href="{{contentServerUrl}}/content/{{id}}" title="{{translations.preview-book}}" aria-label="{{translations.preview-book}}">{{/contentServerUrl}}
|
||||
{{#contentServerUrl}}<a class="book__link" href="{{contentServerUrl}}/{{id}}" title="{{translations.preview-book}}" aria-label="{{translations.preview-book}}">{{/contentServerUrl}}
|
||||
<div class="book__link__wrapper">
|
||||
<div class="book__icon" {{faviconAttr}}></div>
|
||||
<div class="book__header">
|
||||
|
@ -18,11 +18,15 @@ protected:
|
||||
const int PORT = 8002;
|
||||
|
||||
protected:
|
||||
void resetServer(ZimFileServer::Cfg cfg) {
|
||||
zfs1_.reset();
|
||||
zfs1_.reset(new ZimFileServer(PORT, cfg, "./test/library.xml"));
|
||||
}
|
||||
|
||||
void resetServer(ZimFileServer::Options options, std::string contentServerUrl="") {
|
||||
ZimFileServer::Cfg cfg(options);
|
||||
cfg.contentServerUrl = contentServerUrl;
|
||||
zfs1_.reset();
|
||||
zfs1_.reset(new ZimFileServer(PORT, cfg, "./test/library.xml"));
|
||||
resetServer(cfg);
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
@ -733,7 +737,8 @@ TEST_F(LibraryServerTest, catalog_v2_entries_catalog_only_mode)
|
||||
resetServer(ZimFileServer::CATALOG_ONLY_MODE, contentServerUrl);
|
||||
const auto r = zfs1_->GET("/ROOT%23%3F/catalog/v2/entries");
|
||||
EXPECT_EQ(r->status, 200);
|
||||
EXPECT_EQ(maskVariableOPDSFeedData(r->body),
|
||||
|
||||
const std::string expectedOPDS =
|
||||
CATALOG_V2_ENTRIES_PREAMBLE("")
|
||||
" <title>All Entries</title>\n"
|
||||
" <updated>YYYY-MM-DDThh:mm:ssZ</updated>\n"
|
||||
@ -742,8 +747,27 @@ TEST_F(LibraryServerTest, catalog_v2_entries_catalog_only_mode)
|
||||
+ fixContentLinks(INACCESSIBLEZIMFILE_CATALOG_ENTRY)
|
||||
+ fixContentLinks(RAY_CHARLES_CATALOG_ENTRY)
|
||||
+ fixContentLinks(UNCATEGORIZED_RAY_CHARLES_CATALOG_ENTRY) +
|
||||
"</feed>\n"
|
||||
);
|
||||
"</feed>\n";
|
||||
|
||||
EXPECT_EQ(maskVariableOPDSFeedData(r->body), expectedOPDS);
|
||||
|
||||
{ // test with empty rootLocation
|
||||
const auto fixRoot = [=](std::string s) -> std::string {
|
||||
s = replace(s, "/ROOT%23%3F/", "/");
|
||||
s = replace(s, "/ROOT%23%3F/", "/");
|
||||
return s;
|
||||
};
|
||||
|
||||
ZimFileServer::Cfg serverCfg;
|
||||
serverCfg.root = "";
|
||||
serverCfg.options = ZimFileServer::CATALOG_ONLY_MODE;
|
||||
serverCfg.contentServerUrl = contentServerUrl;
|
||||
resetServer(serverCfg);
|
||||
|
||||
const auto r = zfs1_->GET("/catalog/v2/entries");
|
||||
EXPECT_EQ(r->status, 200);
|
||||
EXPECT_EQ(maskVariableOPDSFeedData(r->body), fixRoot(expectedOPDS));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(LibraryServerTest, catalog_v2_entries_filtered_by_range)
|
||||
@ -1253,7 +1277,6 @@ TEST_F(LibraryServerTest, no_name_mapper_catalog_v2_individual_entry_access)
|
||||
" <head>\n" \
|
||||
" <meta charset=\"UTF-8\" />\n" \
|
||||
" <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\" />\n" \
|
||||
" <link type=\"root\" href=\"/ROOT%23%3F\">\n" \
|
||||
" <title>Welcome to Kiwix Server</title>\n" \
|
||||
" <link\n" \
|
||||
" type=\"text/css\"\n" \
|
||||
@ -1555,11 +1578,13 @@ TEST_F(LibraryServerTest, noJS_catalogOnlyMode) {
|
||||
s = replace(s, "/ROOT%23%3F/content", contentServerUrl + "/content");
|
||||
return s;
|
||||
};
|
||||
|
||||
resetServer(ZimFileServer::CATALOG_ONLY_MODE, contentServerUrl);
|
||||
|
||||
auto r = zfs1_->GET("/ROOT%23%3F/nojs");
|
||||
EXPECT_EQ(r->status, 200);
|
||||
EXPECT_EQ(r->body,
|
||||
|
||||
const std::string expectedHTML =
|
||||
HTML_PREAMBLE
|
||||
FILTERS_HTML("")
|
||||
HOME_BODY_TEXT("4")
|
||||
@ -1567,7 +1592,27 @@ TEST_F(LibraryServerTest, noJS_catalogOnlyMode) {
|
||||
+ fixContentLinks(INACCESSIBLEZIMFILE_BOOK_HTML)
|
||||
+ fixContentLinks(RAY_CHARLES_BOOK_HTML)
|
||||
+ fixContentLinks(RAY_CHARLES_UNCTZ_BOOK_HTML)
|
||||
+ FINAL_HTML_TEXT);
|
||||
+ FINAL_HTML_TEXT;
|
||||
|
||||
EXPECT_EQ(r->body, expectedHTML);
|
||||
|
||||
{ // test with empty rootLocation
|
||||
const auto fixRoot = [=](std::string s) -> std::string {
|
||||
s = replace(s, "/ROOT%23%3F/", "/");
|
||||
return s;
|
||||
};
|
||||
|
||||
ZimFileServer::Cfg serverCfg;
|
||||
serverCfg.root = "";
|
||||
serverCfg.options = ZimFileServer::CATALOG_ONLY_MODE;
|
||||
serverCfg.contentServerUrl = contentServerUrl;
|
||||
|
||||
resetServer(serverCfg);
|
||||
|
||||
auto r = zfs1_->GET("/nojs");
|
||||
EXPECT_EQ(r->status, 200);
|
||||
EXPECT_EQ(r->body, fixRoot(expectedHTML));
|
||||
}
|
||||
}
|
||||
|
||||
#undef EXPECT_SEARCH_RESULTS
|
||||
|
Loading…
x
Reference in New Issue
Block a user