mirror of https://github.com/kiwix/libkiwix.git
RequestContext::get_optional_param()
This commit is contained in:
parent
70d42aec98
commit
b60e3ffb26
|
@ -703,14 +703,8 @@ InternalServer::search_catalog(const RequestContext& request,
|
|||
opdsDumper.setTitle("Search result for " + q);
|
||||
std::vector<std::string> bookIdsToDump = mp_library->filter(filter);
|
||||
const auto totalResults = bookIdsToDump.size();
|
||||
size_t count(10);
|
||||
size_t startIndex(0);
|
||||
try {
|
||||
count = extractFromString<unsigned long>(request.get_argument("count"));
|
||||
} catch (...) {}
|
||||
try {
|
||||
startIndex = extractFromString<unsigned long>(request.get_argument("start"));
|
||||
} catch (...) {}
|
||||
const size_t count = request.get_optional_param("count", 10UL);
|
||||
const size_t startIndex = request.get_optional_param("start", 0UL);
|
||||
const auto s = std::min(startIndex, totalResults);
|
||||
bookIdsToDump.erase(bookIdsToDump.begin(), bookIdsToDump.begin()+s);
|
||||
if (count>0 && bookIdsToDump.size() > count) {
|
||||
|
|
|
@ -74,6 +74,15 @@ class RequestContext {
|
|||
return v;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T get_optional_param(const std::string& name, T default_value) const
|
||||
{
|
||||
try {
|
||||
return get_argument<T>(name);
|
||||
} catch (...) {}
|
||||
return default_value;
|
||||
}
|
||||
|
||||
|
||||
RequestMethod get_method() const;
|
||||
std::string get_url() const;
|
||||
|
|
Loading…
Reference in New Issue