Skip to content

Commit

Permalink
Handling of /meta?name=Illustration_WxH@1 requests
Browse files Browse the repository at this point in the history
  • Loading branch information
veloman-yunkan committed Jul 27, 2021
1 parent a9e4b7e commit fcc88f8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Entry Reader::getMainPage() 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
Expand Down
14 changes: 13 additions & 1 deletion src/server/internalServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ inline std::string normalizeRootUrl(std::string 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

static IdNameMapper defaultNameMapper;
Expand Down Expand Up @@ -408,7 +418,9 @@ std::unique_ptr<Response> InternalServer::handle_meta(const RequestContext& requ
} else if (meta_name == "publisher") {
content = getMetaPublisher(*archive);
} 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 {
return Response::build_404(*this, request, bookName, "");
}
Expand Down
4 changes: 2 additions & 2 deletions src/tools/archiveTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ std::string getMetaTags(const zim::Archive& archive, bool original) {
return join(tags, ";");
}

bool getArchiveFavicon(const zim::Archive& archive,
bool getArchiveFavicon(const zim::Archive& archive, unsigned size,
std::string& content, std::string& mimeType){
try {
auto item = archive.getIllustrationItem();
auto item = archive.getIllustrationItem(size);
content = item.getData();
mimeType = item.getMimetype();
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/archiveTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace kiwix
std::string getArchiveTitle(const zim::Archive& archive);
std::string getMetaDescription(const zim::Archive& archive);
std::string getMetaTags(const zim::Archive& archive, bool original = false);
bool getArchiveFavicon(const zim::Archive& archive,
bool getArchiveFavicon(const zim::Archive& archive, unsigned size,
std::string& content, std::string& mimeType);
std::string getMetaLanguage(const zim::Archive& archive);
std::string getMetaName(const zim::Archive& archive);
Expand Down
1 change: 1 addition & 0 deletions test/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ const ResourceCollection resources200Uncompressible{
{ WITH_ETAG, "/meta?content=zimfile&name=creator" },
{ WITH_ETAG, "/meta?content=zimfile&name=publisher" },
{ 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" },

Expand Down

0 comments on commit fcc88f8

Please sign in to comment.