Merge pull request #936 from kiwix/opds_xml_fix

This commit is contained in:
Matthieu Gautier 2023-04-18 14:07:31 +02:00 committed by GitHub
commit bf1d207651
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 6 deletions

View File

@ -150,17 +150,17 @@ string OPDSDumper::dumpOPDSFeedV2(const std::vector<std::string>& bookIds, const
const auto booksData = getBooksData(library, nameMapper, bookIds, rootLocation, partial); const auto booksData = getBooksData(library, nameMapper, bookIds, rootLocation, partial);
const char* const endpoint = partial ? "/partial_entries" : "/entries"; const char* const endpoint = partial ? "/partial_entries" : "/entries";
const std::string url = endpoint + (query.empty() ? "" : "?" + query);
const kainjow::mustache::object template_data{ const kainjow::mustache::object template_data{
{"date", gen_date_str()}, {"date", gen_date_str()},
{"endpoint_root", endpointRoot}, {"endpoint_root", endpointRoot},
{"feed_id", gen_uuid(libraryId + endpoint + "?" + query)}, {"feed_id", gen_uuid(libraryId + endpoint + "?" + query)},
{"filter", onlyAsNonEmptyMustacheValue(query)}, {"filter", onlyAsNonEmptyMustacheValue(query)},
{"query", query.empty() ? "" : "?" + query}, {"self_url", url},
{"totalResults", to_string(m_totalResults)}, {"totalResults", to_string(m_totalResults)},
{"startIndex", to_string(m_startIndex)}, {"startIndex", to_string(m_startIndex)},
{"itemsPerPage", to_string(m_count)}, {"itemsPerPage", to_string(m_count)},
{"books", booksData }, {"books", booksData }
{"dump_partial_entries", MustacheData(partial)}
}; };
return render_template(RESOURCE::templates::catalog_v2_entries_xml, template_data); return render_template(RESOURCE::templates::catalog_v2_entries_xml, template_data);

View File

@ -6,7 +6,7 @@
<id>{{feed_id}}</id> <id>{{feed_id}}</id>
<link rel="self" <link rel="self"
href="{{endpoint_root}}/{{#dump_partial_entries}}partial_{{/dump_partial_entries}}entries{{{query}}}" href="{{endpoint_root}}{{self_url}}"
type="application/atom+xml;profile=opds-catalog;kind=acquisition"/> type="application/atom+xml;profile=opds-catalog;kind=acquisition"/>
<link rel="start" <link rel="start"
href="{{endpoint_root}}/root.xml" href="{{endpoint_root}}/root.xml"

View File

@ -728,7 +728,7 @@ TEST_F(LibraryServerTest, catalog_v2_entries_filtered_by_range)
const auto r = zfs1_->GET("/ROOT%23%3F/catalog/v2/entries?start=1&count=1"); const auto r = zfs1_->GET("/ROOT%23%3F/catalog/v2/entries?start=1&count=1");
EXPECT_EQ(r->status, 200); EXPECT_EQ(r->status, 200);
EXPECT_EQ(maskVariableOPDSFeedData(r->body), EXPECT_EQ(maskVariableOPDSFeedData(r->body),
CATALOG_V2_ENTRIES_PREAMBLE("?start=1&count=1") CATALOG_V2_ENTRIES_PREAMBLE("?start=1&amp;count=1")
" <title>Filtered Entries (start=1&amp;count=1)</title>\n" " <title>Filtered Entries (start=1&amp;count=1)</title>\n"
" <updated>YYYY-MM-DDThh:mm:ssZ</updated>\n" " <updated>YYYY-MM-DDThh:mm:ssZ</updated>\n"
" <totalResults>3</totalResults>\n" " <totalResults>3</totalResults>\n"
@ -793,6 +793,24 @@ TEST_F(LibraryServerTest, catalog_v2_entries_filtered_by_language)
} }
} }
TEST_F(LibraryServerTest, catalog_v2_entries_multiple_filters)
{
{
const auto r = zfs1_->GET("/ROOT%23%3F/catalog/v2/entries?lang=fra&category=jazz");
EXPECT_EQ(r->status, 200);
EXPECT_EQ(maskVariableOPDSFeedData(r->body),
CATALOG_V2_ENTRIES_PREAMBLE("?lang=fra&amp;category=jazz")
" <title>Filtered Entries (lang=fra&amp;category=jazz)</title>\n"
" <updated>YYYY-MM-DDThh:mm:ssZ</updated>\n"
" <totalResults>1</totalResults>\n"
" <startIndex>0</startIndex>\n"
" <itemsPerPage>1</itemsPerPage>\n"
CHARLES_RAY_CATALOG_ENTRY
"</feed>\n"
);
}
}
TEST_F(LibraryServerTest, catalog_v2_individual_entry_access) TEST_F(LibraryServerTest, catalog_v2_individual_entry_access)
{ {
const auto r = zfs1_->GET("/ROOT%23%3F/catalog/v2/entry/raycharles"); const auto r = zfs1_->GET("/ROOT%23%3F/catalog/v2/entry/raycharles");