Remove the meta endpoint in the server.

Now we have `/raw` and `catalog/v2/illustration` endpoints we don't need
to keep the meta endpoint.
This commit is contained in:
Matthieu Gautier 2022-01-05 15:34:28 +01:00
parent e4d99f0374
commit 0112e6102d
3 changed files with 13 additions and 78 deletions

View File

@ -96,16 +96,6 @@ 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;
@ -288,9 +278,6 @@ std::unique_ptr<Response> InternalServer::handle_request(const RequestContext& r
if (startsWith(request.get_url(), "/raw/"))
return handle_raw(request);
if (request.get_url() == "/meta")
return handle_meta(request);
if (request.get_url() == "/search")
return handle_search(request);
@ -383,60 +370,6 @@ SuggestionsList_t getSuggestions(const zim::Archive* const archive,
return suggestions;
}
/**
* Archive and Zim handlers end
**/
std::unique_ptr<Response> InternalServer::handle_meta(const RequestContext& request)
{
std::string bookName;
std::shared_ptr<zim::Archive> archive;
try {
bookName = request.get_argument("content");
const std::string bookId = mp_nameMapper->getIdForName(bookName);
archive = mp_library->getArchiveById(bookId);
} catch (const std::out_of_range& e) {
// error handled by the archive == nullptr check below
}
if (archive == nullptr) {
const std::string error_details = "No such book: " + bookName;
return Response::build_404(*this, "", bookName, "", error_details);
}
std::string content;
std::string mimeType = "text";
const auto meta_name = request.get_optional_param("name", std::string());
if (meta_name == "title") {
content = getArchiveTitle(*archive);
} else if (meta_name == "description") {
content = getMetaDescription(*archive);
} else if (meta_name == "language") {
content = getMetaLanguage(*archive);
} else if (meta_name == "name") {
content = getMetaName(*archive);
} else if (meta_name == "tags") {
content = getMetaTags(*archive);
} else if (meta_name == "date") {
content = getMetaDate(*archive);
} else if (meta_name == "creator") {
content = getMetaCreator(*archive);
} else if (meta_name == "publisher") {
content = getMetaPublisher(*archive);
} else if (meta_name == "favicon") {
getArchiveFavicon(*archive, 48, content, mimeType);
} else if (const unsigned illustrationSize = parseIllustration(meta_name)) {
getArchiveFavicon(*archive, illustrationSize, content, mimeType);
} else {
const std::string error_details = "No such metadata item: " + meta_name;
return Response::build_404(*this, "", bookName, "", error_details);
}
auto response = ContentResponse::build(*this, content, mimeType);
response->set_cacheable();
return std::move(response);
}
std::unique_ptr<Response> InternalServer::handle_suggest(const RequestContext& request)
{

View File

@ -83,7 +83,6 @@ class InternalServer {
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_catalog_v2_illustration(const RequestContext& request);
std::unique_ptr<Response> handle_meta(const RequestContext& request);
std::unique_ptr<Response> handle_search(const RequestContext& request);
std::unique_ptr<Response> handle_suggest(const RequestContext& request);
std::unique_ptr<Response> handle_random(const RequestContext& request);

View File

@ -194,16 +194,15 @@ const ResourceCollection resources200Uncompressible{
{ WITH_ETAG, "/ROOT/skin/jquery-ui/images/animated-overlay.gif" },
{ WITH_ETAG, "/ROOT/skin/caret.png" },
{ WITH_ETAG, "/ROOT/meta?content=zimfile&name=title" },
{ WITH_ETAG, "/ROOT/meta?content=zimfile&name=description" },
{ WITH_ETAG, "/ROOT/meta?content=zimfile&name=language" },
{ WITH_ETAG, "/ROOT/meta?content=zimfile&name=name" },
{ WITH_ETAG, "/ROOT/meta?content=zimfile&name=tags" },
{ WITH_ETAG, "/ROOT/meta?content=zimfile&name=date" },
{ WITH_ETAG, "/ROOT/meta?content=zimfile&name=creator" },
{ WITH_ETAG, "/ROOT/meta?content=zimfile&name=publisher" },
{ WITH_ETAG, "/ROOT/meta?content=zimfile&name=favicon" },
{ WITH_ETAG, "/ROOT/meta?content=zimfile&name=Illustration_48x48@1" },
{ WITH_ETAG, "/ROOT/raw/zimfile/meta/Title" },
{ WITH_ETAG, "/ROOT/raw/zimfile/meta/Description" },
{ WITH_ETAG, "/ROOT/raw/zimfile/meta/Language" },
{ WITH_ETAG, "/ROOT/raw/zimfile/meta/Name" },
{ WITH_ETAG, "/ROOT/raw/zimfile/meta/Tags" },
{ WITH_ETAG, "/ROOT/raw/zimfile/meta/Date" },
{ WITH_ETAG, "/ROOT/raw/zimfile/meta/Creator" },
{ WITH_ETAG, "/ROOT/raw/zimfile/meta/Publisher" },
{ NO_ETAG, "/ROOT/catalog/v2/illustration/zimfile?size=48" },
{ WITH_ETAG, "/ROOT/zimfile/I/m/Ray_Charles_classic_piano_pose.jpg" },
@ -296,6 +295,10 @@ const char* urls404[] = {
"/ROOT/suggest?content=non-existent-book&term=abcd",
"/ROOT/catch/external",
"/ROOT/zimfile/A/non-existent-article",
// zimfile has no Favicon nor Illustration_48x48@1 meta item
"/ROOT/raw/zimfile/meta/Favicon",
"/ROOT/raw/zimfile/meta/Illustration_48x48@1",
};
TEST_F(ServerTest, 404)