-
-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OPDS name mapper #830
base: main
Are you sure you want to change the base?
OPDS name mapper #830
Changes from 6 commits
cc849b3
96fb423
24472e0
85f58b8
5896691
0bd5a5e
4842fa0
3d75f24
92c0e14
422e71a
3e54e56
6815a4c
37ccfb5
7d83127
1fcc2ad
d112470
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,8 +30,9 @@ namespace kiwix | |
{ | ||
|
||
/* Constructor */ | ||
OPDSDumper::OPDSDumper(Library* library) | ||
: library(library) | ||
OPDSDumper::OPDSDumper(std::shared_ptr<Library> library, NameMapper* nameMapper) | ||
: library(library), | ||
nameMapper(nameMapper) | ||
{ | ||
} | ||
/* Destructor */ | ||
|
@@ -71,7 +72,7 @@ IllustrationInfo getBookIllustrationInfo(const Book& book) | |
return illustrations; | ||
} | ||
|
||
std::string fullEntryXML(const Book& book, const std::string& rootLocation) | ||
std::string fullEntryXML(const Book& book, const std::string& rootLocation, const std::string& bookName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I would convert There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update: I see that this concern was later on addressed in a slightly different way. |
||
{ | ||
const auto bookDate = book.getDate() + "T00:00:00Z"; | ||
const kainjow::mustache::object data{ | ||
|
@@ -81,7 +82,7 @@ std::string fullEntryXML(const Book& book, const std::string& rootLocation) | |
{"title", book.getTitle()}, | ||
{"description", book.getDescription()}, | ||
{"language", book.getLanguage()}, | ||
{"content_id", urlEncode(book.getHumanReadableIdFromPath(), true)}, | ||
{"content_id", urlEncode(bookName, true)}, | ||
{"updated", bookDate}, // XXX: this should be the entry update datetime | ||
{"book_date", bookDate}, | ||
{"category", book.getCategory()}, | ||
|
@@ -112,15 +113,16 @@ std::string partialEntryXML(const Book& book, const std::string& rootLocation) | |
return render_template(xmlTemplate, data); | ||
} | ||
|
||
BooksData getBooksData(const Library* library, const std::vector<std::string>& bookIds, const std::string& rootLocation, bool partial) | ||
BooksData getBooksData(const Library& library, const NameMapper& nameMapper, const std::vector<std::string>& bookIds, const std::string& rootLocation, bool partial) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The count of function parameters is a code smell. Update: I wrote this comment before getting to the commit where a similar refactoring was done with the help of |
||
BooksData booksData; | ||
for ( const auto& bookId : bookIds ) { | ||
try { | ||
const Book book = library->getBookByIdThreadSafe(bookId); | ||
const Book book = library.getBookByIdThreadSafe(bookId); | ||
const std::string bookName = nameMapper.getNameForId(bookId); | ||
const auto entryXML = partial | ||
? partialEntryXML(book, rootLocation) | ||
: fullEntryXML(book, rootLocation); | ||
: fullEntryXML(book, rootLocation, bookName); | ||
booksData.push_back(kainjow::mustache::object{ {"entry", entryXML} }); | ||
} catch ( const std::out_of_range& ) { | ||
// the book was removed from the library since its id was obtained | ||
|
@@ -188,7 +190,7 @@ std::string getLanguageSelfName(const std::string& lang) { | |
|
||
string OPDSDumper::dumpOPDSFeed(const std::vector<std::string>& bookIds, const std::string& query) const | ||
{ | ||
const auto booksData = getBooksData(library, bookIds, rootLocation, false); | ||
const auto booksData = getBooksData(*library, *nameMapper, bookIds, rootLocation, false); | ||
const kainjow::mustache::object template_data{ | ||
{"date", gen_date_str()}, | ||
{"root", rootLocation}, | ||
|
@@ -206,7 +208,7 @@ string OPDSDumper::dumpOPDSFeed(const std::vector<std::string>& bookIds, const s | |
string OPDSDumper::dumpOPDSFeedV2(const std::vector<std::string>& bookIds, const std::string& query, bool partial) const | ||
{ | ||
const auto endpointRoot = rootLocation + "/catalog/v2"; | ||
const auto booksData = getBooksData(library, bookIds, rootLocation, partial); | ||
const auto booksData = getBooksData(*library, *nameMapper, bookIds, rootLocation, partial); | ||
|
||
const char* const endpoint = partial ? "/partial_entries" : "/entries"; | ||
const kainjow::mustache::object template_data{ | ||
|
@@ -228,9 +230,10 @@ string OPDSDumper::dumpOPDSFeedV2(const std::vector<std::string>& bookIds, const | |
std::string OPDSDumper::dumpOPDSCompleteEntry(const std::string& bookId) const | ||
{ | ||
const auto book = library->getBookById(bookId); | ||
const std::string bookName = nameMapper->getNameForId(bookId); | ||
return XML_HEADER | ||
+ "\n" | ||
+ fullEntryXML(book, rootLocation); | ||
+ fullEntryXML(book, rootLocation, bookName); | ||
} | ||
|
||
std::string OPDSDumper::categoriesOPDSFeed() const | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OPDSDumper
shouldn't need non-const access to library.