diff --git a/src/opds_dumper.cpp b/src/opds_dumper.cpp index ddf2e83d..6897b314 100644 --- a/src/opds_dumper.cpp +++ b/src/opds_dumper.cpp @@ -51,7 +51,7 @@ namespace { typedef kainjow::mustache::data MustacheData; -typedef kainjow::mustache::list BookData; +typedef kainjow::mustache::list BooksData; typedef kainjow::mustache::list IllustrationInfo; IllustrationInfo getBookIllustrationInfo(const Book& book) @@ -95,15 +95,26 @@ kainjow::mustache::object getSingleBookData(const Book& book) }; } -BookData getBookData(const Library* library, const std::vector& bookIds) +std::string getSingleBookEntryXML(const Book& book, bool withXMLHeader, const std::string& endpointRoot, bool partial) { - BookData bookData; + auto data = getSingleBookData(book); + data["with_xml_header"] = MustacheData(withXMLHeader); + data["dump_partial_entries"] = MustacheData(partial); + data["endpoint_root"] = endpointRoot; + return render_template(RESOURCE::templates::catalog_v2_entry_xml, data); +} + +BooksData getBooksData(const Library* library, const std::vector& bookIds, const std::string& endpointRoot, bool partial) +{ + BooksData booksData; for ( const auto& bookId : bookIds ) { const Book& book = library->getBookById(bookId); - bookData.push_back(getSingleBookData(book)); + booksData.push_back(kainjow::mustache::object{ + {"entry", getSingleBookEntryXML(book, false, endpointRoot, partial)} + }); } - return bookData; + return booksData; } std::string getLanguageSelfName(const std::string& lang) { @@ -119,7 +130,7 @@ std::string getLanguageSelfName(const std::string& lang) { string OPDSDumper::dumpOPDSFeed(const std::vector& bookIds, const std::string& query) const { - const auto bookData = getBookData(library, bookIds); + const auto booksData = getBooksData(library, bookIds, "", false); const kainjow::mustache::object template_data{ {"date", gen_date_str()}, {"root", rootLocation}, @@ -128,7 +139,7 @@ string OPDSDumper::dumpOPDSFeed(const std::vector& bookIds, const s {"totalResults", to_string(m_totalResults)}, {"startIndex", to_string(m_startIndex)}, {"itemsPerPage", to_string(m_count)}, - {"books", bookData } + {"books", booksData } }; return render_template(RESOURCE::templates::catalog_entries_xml, template_data); @@ -136,19 +147,20 @@ string OPDSDumper::dumpOPDSFeed(const std::vector& bookIds, const s string OPDSDumper::dumpOPDSFeedV2(const std::vector& bookIds, const std::string& query, bool partial) const { - const auto bookData = getBookData(library, bookIds); + const auto endpointRoot = rootLocation + "/catalog/v2"; + const auto booksData = getBooksData(library, bookIds, endpointRoot, partial); const char* const endpoint = partial ? "/partial_entries" : "/entries"; const kainjow::mustache::object template_data{ {"date", gen_date_str()}, - {"endpoint_root", rootLocation + "/catalog/v2"}, + {"endpoint_root", endpointRoot}, {"feed_id", gen_uuid(libraryId + endpoint + "?" + query)}, {"filter", query.empty() ? MustacheData(false) : MustacheData(query)}, {"query", query.empty() ? "" : "?" + urlEncode(query)}, {"totalResults", to_string(m_totalResults)}, {"startIndex", to_string(m_startIndex)}, {"itemsPerPage", to_string(m_count)}, - {"books", bookData }, + {"books", booksData }, {"dump_partial_entries", MustacheData(partial)} }; @@ -157,9 +169,7 @@ string OPDSDumper::dumpOPDSFeedV2(const std::vector& bookIds, const std::string OPDSDumper::dumpOPDSCompleteEntry(const std::string& bookId) const { - const auto bookData = getSingleBookData(library->getBookById(bookId)); - - return render_template(RESOURCE::templates::catalog_v2_complete_entry_xml, bookData); + return getSingleBookEntryXML(library->getBookById(bookId), true, "", false); } std::string OPDSDumper::categoriesOPDSFeed() const diff --git a/static/resources_list.txt b/static/resources_list.txt index 9ace25b1..eb65b9db 100644 --- a/static/resources_list.txt +++ b/static/resources_list.txt @@ -45,7 +45,7 @@ templates/captured_external.html templates/catalog_entries.xml templates/catalog_v2_root.xml templates/catalog_v2_entries.xml -templates/catalog_v2_complete_entry.xml +templates/catalog_v2_entry.xml templates/catalog_v2_categories.xml templates/catalog_v2_languages.xml opensearchdescription.xml diff --git a/static/templates/catalog_entries.xml b/static/templates/catalog_entries.xml index 144f68bf..40cbfccd 100644 --- a/static/templates/catalog_entries.xml +++ b/static/templates/catalog_entries.xml @@ -9,34 +9,4 @@ {{/filter}} - {{#books}} - - urn:uuid:{{id}} - {{title}} - {{updated}} - {{description}} - {{language}} - {{name}} - {{flavour}} - {{category}} - {{tags}} - {{article_count}} - {{media_count}} - {{#icons}} - - {{/icons}} - - - {{author_name}} - - - {{publisher_name}} - - {{#url}} - - {{/url}} - - {{/books}} - +{{#books}}{{{entry}}}{{/books}} diff --git a/static/templates/catalog_v2_entries.xml b/static/templates/catalog_v2_entries.xml index 36e59a85..2df9523d 100644 --- a/static/templates/catalog_v2_entries.xml +++ b/static/templates/catalog_v2_entries.xml @@ -21,39 +21,4 @@ {{startIndex}} {{itemsPerPage}} {{/filter}} - {{#books}} - - urn:uuid:{{id}} - {{title}} - {{updated}} -{{#dump_partial_entries}} - -{{/dump_partial_entries}}{{^dump_partial_entries}} {{description}} - {{language}} - {{name}} - {{flavour}} - {{category}} - {{tags}} - {{article_count}} - {{media_count}} - {{#icons}} - - {{/icons}} - - - {{author_name}} - - - {{publisher_name}} - - {{#url}} - - {{/url}} -{{/dump_partial_entries}} - - {{/books}} - +{{#books}}{{{entry}}}{{/books}} diff --git a/static/templates/catalog_v2_complete_entry.xml b/static/templates/catalog_v2_entry.xml similarity index 72% rename from static/templates/catalog_v2_complete_entry.xml rename to static/templates/catalog_v2_entry.xml index 76335a3f..33abd56d 100644 --- a/static/templates/catalog_v2_complete_entry.xml +++ b/static/templates/catalog_v2_entry.xml @@ -1,9 +1,13 @@ - - +{{#with_xml_header}} +{{/with_xml_header}} urn:uuid:{{id}} {{title}} {{updated}} - {{description}} +{{#dump_partial_entries}} + +{{/dump_partial_entries}}{{^dump_partial_entries}} {{description}} {{language}} {{name}} {{flavour}} @@ -26,4 +30,5 @@ {{#url}} {{/url}} +{{/dump_partial_entries}} diff --git a/test/server.cpp b/test/server.cpp index ad543853..85f553ce 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -905,7 +905,6 @@ TEST_F(LibraryServerTest, catalog_search_results_pagination) " 100\n" " 0\n" CATALOG_LINK_TAGS - " \n" "\n" ); }