mirror of https://github.com/kiwix/libkiwix.git
/catalog/v2/categories goes through OPDSDumper too
This commit is contained in:
parent
cdacc0caf1
commit
9ca6bd006f
|
@ -64,6 +64,14 @@ class OPDSDumper
|
||||||
*/
|
*/
|
||||||
std::string dumpOPDSFeedV2(const std::vector<std::string>& bookIds, const std::string& query) const;
|
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.
|
* Set the id of the library.
|
||||||
*
|
*
|
||||||
|
|
|
@ -179,4 +179,29 @@ string OPDSDumper::dumpOPDSFeedV2(const std::vector<std::string>& bookIds, const
|
||||||
return render_template(RESOURCE::catalog_v2_entries_xml, template_data);
|
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 }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
std::unique_ptr<Response> InternalServer::handle_catalog_v2_categories(const RequestContext& request)
|
||||||
{
|
{
|
||||||
const std::string root_url = normalizeRootUrl(m_root);
|
OPDSDumper opdsDumper(mp_library);
|
||||||
const auto now = gen_date_str();
|
opdsDumper.setRootLocation(normalizeRootUrl(m_root));
|
||||||
kainjow::mustache::list categoryData;
|
opdsDumper.setLibraryId(m_library_id);
|
||||||
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)}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return ContentResponse::build(
|
return ContentResponse::build(
|
||||||
*this,
|
*this,
|
||||||
RESOURCE::catalog_v2_categories_xml,
|
opdsDumper.categoriesOPDSFeed(mp_library->getBooksCategories()),
|
||||||
kainjow::mustache::object{
|
|
||||||
{"date", now},
|
|
||||||
{"endpoint_root", root_url + "/catalog/v2"},
|
|
||||||
{"feed_id", gen_uuid(m_library_id + "/categories")},
|
|
||||||
{"categories", categoryData }
|
|
||||||
},
|
|
||||||
"application/atom+xml;profile=opds-catalog;kind=navigation"
|
"application/atom+xml;profile=opds-catalog;kind=navigation"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue