mirror of https://github.com/kiwix/libkiwix.git
Handling of /meta?name=Illustration_WxH@1 requests
This commit is contained in:
parent
e5168d8b3d
commit
452283cfe6
|
@ -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()
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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" },
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue