mirror of https://github.com/kiwix/libkiwix.git
/catalog/v2/entry/<entry_id> OPDS API endpoint
This commit is contained in:
parent
12d9b69806
commit
e15a0f4338
|
@ -75,7 +75,7 @@ kainjow::mustache::object getSingleBookData(const Book& book)
|
|||
? MustacheData(false)
|
||||
: MustacheData(book.getUrl());
|
||||
return kainjow::mustache::object{
|
||||
{"id", "urn:uuid:"+book.getId()},
|
||||
{"id", book.getId()},
|
||||
{"name", book.getName()},
|
||||
{"title", book.getTitle()},
|
||||
{"description", book.getDescription()},
|
||||
|
|
|
@ -76,6 +76,7 @@ class InternalServer {
|
|||
std::unique_ptr<Response> handle_catalog_v2(const RequestContext& request);
|
||||
std::unique_ptr<Response> handle_catalog_v2_root(const RequestContext& request);
|
||||
std::unique_ptr<Response> handle_catalog_v2_entries(const RequestContext& request);
|
||||
std::unique_ptr<Response> handle_catalog_v2_complete_entry(const RequestContext& request, const std::string& entryId);
|
||||
std::unique_ptr<Response> handle_catalog_v2_categories(const RequestContext& request);
|
||||
std::unique_ptr<Response> handle_catalog_v2_languages(const RequestContext& request);
|
||||
std::unique_ptr<Response> handle_meta(const RequestContext& request);
|
||||
|
|
|
@ -55,6 +55,9 @@ std::unique_ptr<Response> InternalServer::handle_catalog_v2(const RequestContext
|
|||
kainjow::mustache::object({{"endpoint_root", endpoint_root}}),
|
||||
"application/opensearchdescription+xml"
|
||||
);
|
||||
} else if (url == "entry") {
|
||||
const std::string entryId = request.get_url_part(3);
|
||||
return handle_catalog_v2_complete_entry(request, entryId);
|
||||
} else if (url == "entries") {
|
||||
return handle_catalog_v2_entries(request);
|
||||
} else if (url == "categories") {
|
||||
|
@ -97,6 +100,25 @@ std::unique_ptr<Response> InternalServer::handle_catalog_v2_entries(const Reques
|
|||
);
|
||||
}
|
||||
|
||||
std::unique_ptr<Response> InternalServer::handle_catalog_v2_complete_entry(const RequestContext& request, const std::string& entryId)
|
||||
{
|
||||
try {
|
||||
mp_library->getBookById(entryId);
|
||||
} catch (const std::out_of_range&) {
|
||||
return Response::build_404(*this, request, "", "");
|
||||
}
|
||||
|
||||
OPDSDumper opdsDumper(mp_library);
|
||||
opdsDumper.setRootLocation(m_root);
|
||||
opdsDumper.setLibraryId(m_library_id);
|
||||
const auto opdsFeed = opdsDumper.dumpOPDSCompleteEntry(entryId);
|
||||
return ContentResponse::build(
|
||||
*this,
|
||||
opdsFeed,
|
||||
"application/atom+xml;type=entry;profile=opds-catalog"
|
||||
);
|
||||
}
|
||||
|
||||
std::unique_ptr<Response> InternalServer::handle_catalog_v2_categories(const RequestContext& request)
|
||||
{
|
||||
OPDSDumper opdsDumper(mp_library);
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<link rel="search" type="application/opensearchdescription+xml" href="{{root}}/catalog/searchdescription.xml" />
|
||||
{{#books}}
|
||||
<entry>
|
||||
<id>{{id}}</id>
|
||||
<id>urn:uuid:{{id}}</id>
|
||||
<title>{{title}}</title>
|
||||
<summary>{{description}}</summary>
|
||||
<language>{{language}}</language>
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
{{/filter}}
|
||||
{{#books}}
|
||||
<entry>
|
||||
<id>{{id}}</id>
|
||||
<id>urn:uuid:{{id}}</id>
|
||||
<title>{{title}}</title>
|
||||
<summary>{{description}}</summary>
|
||||
<language>{{language}}</language>
|
||||
|
|
|
@ -1240,3 +1240,16 @@ TEST_F(LibraryServerTest, suggestions_in_range)
|
|||
ASSERT_EQ(currCount, 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(LibraryServerTest, catalog_v2_individual_entry_access)
|
||||
{
|
||||
const auto r = zfs1_->GET("/catalog/v2/entry/raycharles");
|
||||
EXPECT_EQ(r->status, 200);
|
||||
EXPECT_EQ(maskVariableOPDSFeedData(r->body),
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
RAY_CHARLES_CATALOG_ENTRY
|
||||
);
|
||||
|
||||
const auto r1 = zfs1_->GET("/catalog/v2/entry/non-existent-entry");
|
||||
EXPECT_EQ(r1->status, 404);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue