/catalog/v2/categories goes through OPDSDumper too

This commit is contained in:
Veloman Yunkan 2021-05-24 12:30:32 +04:00
parent cdacc0caf1
commit 9ca6bd006f
3 changed files with 37 additions and 20 deletions

View File

@ -64,6 +64,14 @@ class OPDSDumper
*/
std::string dumpOPDSFeedV2(const std::vector<std::string>& bookIds, const std::string& query) const;
/**
* Dump the categories OPDS feed.
*
* @param categories list of category names
* @return The OPDS feed.
*/
std::string categoriesOPDSFeed(const std::vector<std::string>& categories) const;
/**
* Set the id of the library.
*

View File

@ -179,4 +179,29 @@ string OPDSDumper::dumpOPDSFeedV2(const std::vector<std::string>& bookIds, const
return render_template(RESOURCE::catalog_v2_entries_xml, template_data);
}
std::string OPDSDumper::categoriesOPDSFeed(const std::vector<std::string>& categories) const
{
const auto now = gen_date_str();
kainjow::mustache::list categoryData;
for ( const auto& category : categories ) {
const auto urlencodedCategoryName = urlEncode(category);
categoryData.push_back(kainjow::mustache::object{
{"name", category},
{"urlencoded_name", urlencodedCategoryName},
{"updated", now},
{"id", gen_uuid(libraryId + "/categories/" + urlencodedCategoryName)}
});
}
return render_template(
RESOURCE::catalog_v2_categories_xml,
kainjow::mustache::object{
{"date", now},
{"endpoint_root", rootLocation + "/catalog/v2"},
{"feed_id", gen_uuid(libraryId + "/categories")},
{"categories", categoryData }
}
);
}
}

View File

@ -779,28 +779,12 @@ std::unique_ptr<Response> InternalServer::handle_catalog_v2_entries(const Reques
std::unique_ptr<Response> InternalServer::handle_catalog_v2_categories(const RequestContext& request)
{
const std::string root_url = normalizeRootUrl(m_root);
const auto now = gen_date_str();
kainjow::mustache::list categoryData;
for ( const auto& category : mp_library->getBooksCategories() ) {
const auto urlencodedCategoryName = urlEncode(category);
categoryData.push_back(kainjow::mustache::object{
{"name", category},
{"urlencoded_name", urlencodedCategoryName},
{"updated", now},
{"id", gen_uuid(m_library_id + "/categories/" + urlencodedCategoryName)}
});
}
OPDSDumper opdsDumper(mp_library);
opdsDumper.setRootLocation(normalizeRootUrl(m_root));
opdsDumper.setLibraryId(m_library_id);
return ContentResponse::build(
*this,
RESOURCE::catalog_v2_categories_xml,
kainjow::mustache::object{
{"date", now},
{"endpoint_root", root_url + "/catalog/v2"},
{"feed_id", gen_uuid(m_library_id + "/categories")},
{"categories", categoryData }
},
opdsDumper.categoriesOPDSFeed(mp_library->getBooksCategories()),
"application/atom+xml;profile=opds-catalog;kind=navigation"
);
}