mirror of https://github.com/kiwix/libkiwix.git
Merge pull request #577 from kiwix/opds_multiple_icons
Support for multiple illustrations in OPDS entry
This commit is contained in:
commit
6e26c5aa75
|
@ -104,7 +104,7 @@ void Book::update(const zim::Archive& archive) {
|
||||||
m_mediaCount = getArchiveMediaCount(archive);
|
m_mediaCount = getArchiveMediaCount(archive);
|
||||||
m_size = static_cast<uint64_t>(getArchiveFileSize(archive)) << 10;
|
m_size = static_cast<uint64_t>(getArchiveFileSize(archive)) << 10;
|
||||||
|
|
||||||
getArchiveFavicon(archive, m_favicon, m_faviconMimeType);
|
getArchiveFavicon(archive, 48, m_favicon, m_faviconMimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ATTR(name) node.attribute(name).value()
|
#define ATTR(name) node.attribute(name).value()
|
||||||
|
|
|
@ -52,6 +52,22 @@ namespace
|
||||||
|
|
||||||
typedef kainjow::mustache::data MustacheData;
|
typedef kainjow::mustache::data MustacheData;
|
||||||
typedef kainjow::mustache::list BookData;
|
typedef kainjow::mustache::list BookData;
|
||||||
|
typedef kainjow::mustache::list IllustrationInfo;
|
||||||
|
|
||||||
|
IllustrationInfo getBookIllustrationInfo(const Book& book)
|
||||||
|
{
|
||||||
|
kainjow::mustache::list illustrations;
|
||||||
|
if ( book.isPathValid() ) {
|
||||||
|
for ( auto illustration_size : zim::Archive(book.getPath()).getIllustrationSizes() ) {
|
||||||
|
illustrations.push_back(kainjow::mustache::object{
|
||||||
|
{"icon_width", to_string(illustration_size)},
|
||||||
|
{"icon_height", to_string(illustration_size)},
|
||||||
|
{"icon_scale", "1"},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return illustrations;
|
||||||
|
}
|
||||||
|
|
||||||
BookData getBookData(const Library* library, const std::vector<std::string>& bookIds)
|
BookData getBookData(const Library* library, const std::vector<std::string>& bookIds)
|
||||||
{
|
{
|
||||||
|
@ -78,6 +94,7 @@ BookData getBookData(const Library* library, const std::vector<std::string>& boo
|
||||||
{"publisher_name", book.getPublisher()},
|
{"publisher_name", book.getPublisher()},
|
||||||
{"url", bookUrl},
|
{"url", bookUrl},
|
||||||
{"size", to_string(book.getSize())},
|
{"size", to_string(book.getSize())},
|
||||||
|
{"icons", getBookIllustrationInfo(book)},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,7 @@ Entry Reader::getMainPage() const
|
||||||
|
|
||||||
bool Reader::getFavicon(string& content, string& mimeType) const
|
bool Reader::getFavicon(string& content, string& mimeType) const
|
||||||
{
|
{
|
||||||
return kiwix::getArchiveFavicon(*zimArchive, content, mimeType);
|
return kiwix::getArchiveFavicon(*zimArchive, 48, content, mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
string Reader::getZimFilePath() const
|
string Reader::getZimFilePath() const
|
||||||
|
|
|
@ -94,6 +94,16 @@ inline std::string normalizeRootUrl(std::string rootUrl)
|
||||||
return rootUrl.empty() ? rootUrl : "/" + rootUrl;
|
return rootUrl.empty() ? rootUrl : "/" + rootUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned parseIllustration(const std::string& s)
|
||||||
|
{
|
||||||
|
int nw(0), nh(0), nEnd(0);
|
||||||
|
long int w(-1), h(-1);
|
||||||
|
if ( sscanf(s.c_str(), "Illustration_%n%ldx%n%ld@1%n)", &nw, &w, &nh, &h, &nEnd) == 2
|
||||||
|
&& nEnd == (int)s.size() && !isspace(s[nw]) && !isspace(s[nh]) && w == h && w >= 0) {
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
} // unnamed namespace
|
} // unnamed namespace
|
||||||
|
|
||||||
static IdNameMapper defaultNameMapper;
|
static IdNameMapper defaultNameMapper;
|
||||||
|
@ -408,7 +418,9 @@ std::unique_ptr<Response> InternalServer::handle_meta(const RequestContext& requ
|
||||||
} else if (meta_name == "publisher") {
|
} else if (meta_name == "publisher") {
|
||||||
content = getMetaPublisher(*archive);
|
content = getMetaPublisher(*archive);
|
||||||
} else if (meta_name == "favicon") {
|
} else if (meta_name == "favicon") {
|
||||||
getArchiveFavicon(*archive, content, mimeType);
|
getArchiveFavicon(*archive, 48, content, mimeType);
|
||||||
|
} else if (const unsigned illustrationSize = parseIllustration(meta_name)) {
|
||||||
|
getArchiveFavicon(*archive, illustrationSize, content, mimeType);
|
||||||
} else {
|
} else {
|
||||||
return Response::build_404(*this, request, bookName, "");
|
return Response::build_404(*this, request, bookName, "");
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,10 +97,10 @@ std::string getArchiveId(const zim::Archive& archive) {
|
||||||
return (std::string) archive.getUuid();
|
return (std::string) archive.getUuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getArchiveFavicon(const zim::Archive& archive,
|
bool getArchiveFavicon(const zim::Archive& archive, unsigned size,
|
||||||
std::string& content, std::string& mimeType){
|
std::string& content, std::string& mimeType){
|
||||||
try {
|
try {
|
||||||
auto item = archive.getIllustrationItem();
|
auto item = archive.getIllustrationItem(size);
|
||||||
content = item.getData();
|
content = item.getData();
|
||||||
mimeType = item.getMimetype();
|
mimeType = item.getMimetype();
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -42,7 +42,7 @@ namespace kiwix
|
||||||
std::string getMetaFlavour(const zim::Archive& archive);
|
std::string getMetaFlavour(const zim::Archive& archive);
|
||||||
std::string getArchiveId(const zim::Archive& archive);
|
std::string getArchiveId(const zim::Archive& archive);
|
||||||
|
|
||||||
bool getArchiveFavicon(const zim::Archive& archive,
|
bool getArchiveFavicon(const zim::Archive& archive, unsigned size,
|
||||||
std::string& content, std::string& mimeType);
|
std::string& content, std::string& mimeType);
|
||||||
|
|
||||||
unsigned int getArchiveMediaCount(const zim::Archive& archive);
|
unsigned int getArchiveMediaCount(const zim::Archive& archive);
|
||||||
|
|
|
@ -22,7 +22,11 @@
|
||||||
<tags>{{tags}}</tags>
|
<tags>{{tags}}</tags>
|
||||||
<articleCount>{{article_count}}</articleCount>
|
<articleCount>{{article_count}}</articleCount>
|
||||||
<mediaCount>{{media_count}}</mediaCount>
|
<mediaCount>{{media_count}}</mediaCount>
|
||||||
<icon>/meta?name=favicon&content={{{content_id}}}</icon>
|
{{#icons}}
|
||||||
|
<link rel="http://opds-spec.org/image/thumbnail"
|
||||||
|
href="/meta?name=Illustration_{{icon_width}}x{{icon_height}}@{{icon_scale}}&content={{{content_id}}}"
|
||||||
|
type="image/png;width={{icon_width}};height={{icon_height}};scale={{icon_scale}}"/>
|
||||||
|
{{/icons}}
|
||||||
<link type="text/html" href="/{{{content_id}}}" />
|
<link type="text/html" href="/{{{content_id}}}" />
|
||||||
<author>
|
<author>
|
||||||
<name>{{author_name}}</name>
|
<name>{{author_name}}</name>
|
||||||
|
|
|
@ -34,7 +34,11 @@
|
||||||
<tags>{{tags}}</tags>
|
<tags>{{tags}}</tags>
|
||||||
<articleCount>{{article_count}}</articleCount>
|
<articleCount>{{article_count}}</articleCount>
|
||||||
<mediaCount>{{media_count}}</mediaCount>
|
<mediaCount>{{media_count}}</mediaCount>
|
||||||
<icon>/meta?name=favicon&content={{{content_id}}}</icon>
|
{{#icons}}
|
||||||
|
<link rel="http://opds-spec.org/image/thumbnail"
|
||||||
|
href="/meta?name=Illustration_{{icon_width}}x{{icon_height}}@{{icon_scale}}&content={{{content_id}}}"
|
||||||
|
type="image/png;width={{icon_width}};height={{icon_height}};scale={{icon_scale}}"/>
|
||||||
|
{{/icons}}
|
||||||
<link type="text/html" href="/{{{content_id}}}" />
|
<link type="text/html" href="/{{{content_id}}}" />
|
||||||
<author>
|
<author>
|
||||||
<name>{{author_name}}</name>
|
<name>{{author_name}}</name>
|
||||||
|
|
|
@ -197,6 +197,7 @@ const ResourceCollection resources200Uncompressible{
|
||||||
{ WITH_ETAG, "/meta?content=zimfile&name=creator" },
|
{ WITH_ETAG, "/meta?content=zimfile&name=creator" },
|
||||||
{ WITH_ETAG, "/meta?content=zimfile&name=publisher" },
|
{ WITH_ETAG, "/meta?content=zimfile&name=publisher" },
|
||||||
{ WITH_ETAG, "/meta?content=zimfile&name=favicon" },
|
{ WITH_ETAG, "/meta?content=zimfile&name=favicon" },
|
||||||
|
{ WITH_ETAG, "/meta?content=zimfile&name=Illustration_48x48@1" },
|
||||||
|
|
||||||
{ WITH_ETAG, "/zimfile/I/m/Ray_Charles_classic_piano_pose.jpg" },
|
{ WITH_ETAG, "/zimfile/I/m/Ray_Charles_classic_piano_pose.jpg" },
|
||||||
|
|
||||||
|
@ -626,7 +627,9 @@ std::string maskVariableOPDSFeedData(std::string s)
|
||||||
" <tags>unittest;wikipedia;_category:jazz;_pictures:no;_videos:no;_details:no;_ftindex:yes</tags>\n" \
|
" <tags>unittest;wikipedia;_category:jazz;_pictures:no;_videos:no;_details:no;_ftindex:yes</tags>\n" \
|
||||||
" <articleCount>284</articleCount>\n" \
|
" <articleCount>284</articleCount>\n" \
|
||||||
" <mediaCount>2</mediaCount>\n" \
|
" <mediaCount>2</mediaCount>\n" \
|
||||||
" <icon>/meta?name=favicon&content=zimfile</icon>\n" \
|
" <link rel=\"http://opds-spec.org/image/thumbnail\"\n" \
|
||||||
|
" href=\"/meta?name=Illustration_48x48@1&content=zimfile\"\n" \
|
||||||
|
" type=\"image/png;width=48;height=48;scale=1\"/>\n" \
|
||||||
" <link type=\"text/html\" href=\"/zimfile\" />\n" \
|
" <link type=\"text/html\" href=\"/zimfile\" />\n" \
|
||||||
" <author>\n" \
|
" <author>\n" \
|
||||||
" <name>Wikipedia</name>\n" \
|
" <name>Wikipedia</name>\n" \
|
||||||
|
@ -650,7 +653,9 @@ std::string maskVariableOPDSFeedData(std::string s)
|
||||||
" <tags>unittest;wikipedia;_category:wikipedia;_pictures:no;_videos:no;_details:no;_ftindex:yes</tags>\n" \
|
" <tags>unittest;wikipedia;_category:wikipedia;_pictures:no;_videos:no;_details:no;_ftindex:yes</tags>\n" \
|
||||||
" <articleCount>284</articleCount>\n" \
|
" <articleCount>284</articleCount>\n" \
|
||||||
" <mediaCount>2</mediaCount>\n" \
|
" <mediaCount>2</mediaCount>\n" \
|
||||||
" <icon>/meta?name=favicon&content=zimfile</icon>\n" \
|
" <link rel=\"http://opds-spec.org/image/thumbnail\"\n" \
|
||||||
|
" href=\"/meta?name=Illustration_48x48@1&content=zimfile\"\n" \
|
||||||
|
" type=\"image/png;width=48;height=48;scale=1\"/>\n" \
|
||||||
" <link type=\"text/html\" href=\"/zimfile\" />\n" \
|
" <link type=\"text/html\" href=\"/zimfile\" />\n" \
|
||||||
" <author>\n" \
|
" <author>\n" \
|
||||||
" <name>Wikipedia</name>\n" \
|
" <name>Wikipedia</name>\n" \
|
||||||
|
@ -674,7 +679,9 @@ std::string maskVariableOPDSFeedData(std::string s)
|
||||||
" <tags>unittest;wikipedia;_pictures:no;_videos:no;_details:no</tags>\n" \
|
" <tags>unittest;wikipedia;_pictures:no;_videos:no;_details:no</tags>\n" \
|
||||||
" <articleCount>284</articleCount>\n" \
|
" <articleCount>284</articleCount>\n" \
|
||||||
" <mediaCount>2</mediaCount>\n" \
|
" <mediaCount>2</mediaCount>\n" \
|
||||||
" <icon>/meta?name=favicon&content=zimfile</icon>\n" \
|
" <link rel=\"http://opds-spec.org/image/thumbnail\"\n" \
|
||||||
|
" href=\"/meta?name=Illustration_48x48@1&content=zimfile\"\n" \
|
||||||
|
" type=\"image/png;width=48;height=48;scale=1\"/>\n" \
|
||||||
" <link type=\"text/html\" href=\"/zimfile\" />\n" \
|
" <link type=\"text/html\" href=\"/zimfile\" />\n" \
|
||||||
" <author>\n" \
|
" <author>\n" \
|
||||||
" <name>Wikipedia</name>\n" \
|
" <name>Wikipedia</name>\n" \
|
||||||
|
|
Loading…
Reference in New Issue