Reduce complexity of handle_catalog.

This commit is contained in:
Matthieu Gautier 2019-08-10 17:29:46 +02:00
parent d90f8b0f05
commit fae0918f49
1 changed files with 61 additions and 60 deletions

View File

@ -702,11 +702,18 @@ Response InternalServer::handle_catalog(const RequestContext& request)
return build_404(request, "");
}
if (url != "searchdescription.xml" && url != "root.xml" && url != "search") {
return build_404(request, "");
}
auto response = get_default_response();
response.set_compress(true);
if (url == "searchdescription.xml") {
response.set_template(RESOURCE::opensearchdescription_xml, get_default_data());
response.set_mimeType("application/opensearchdescription+xml");
} else {
return response;
}
zim::Uuid uuid;
kiwix::OPDSDumper opdsDumper;
opdsDumper.setRootLocation(m_root);
@ -718,7 +725,6 @@ Response InternalServer::handle_catalog(const RequestContext& request)
if (url == "root.xml") {
opdsDumper.setTitle("All zims");
uuid = zim::Uuid::generate(host);
bookIdsToDump = m_library.filter(kiwix::Filter().valid(true).local(true).remote(true));
} else if (url == "search") {
std::string query;
@ -760,14 +766,9 @@ Response InternalServer::handle_catalog(const RequestContext& request)
bookIdsToDump.resize(count);
}
opdsDumper.setOpenSearchInfo(totalResults, startIndex, bookIdsToDump.size());
} else {
return build_404(request, "");
}
response.set_content(opdsDumper.dumpOPDSFeed(bookIdsToDump));
}
response.set_compress(true);
return response;
}