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);
|
opdsDumper.setTitle("Search result for " + q);
|
||||||
std::vector<std::string> bookIdsToDump = mp_library->filter(filter);
|
std::vector<std::string> bookIdsToDump = mp_library->filter(filter);
|
||||||
const auto totalResults = bookIdsToDump.size();
|
const auto totalResults = bookIdsToDump.size();
|
||||||
size_t count(10);
|
const size_t count = request.get_optional_param("count", 10UL);
|
||||||
size_t startIndex(0);
|
const size_t startIndex = request.get_optional_param("start", 0UL);
|
||||||
try {
|
|
||||||
count = extractFromString<unsigned long>(request.get_argument("count"));
|
|
||||||
} catch (...) {}
|
|
||||||
try {
|
|
||||||
startIndex = extractFromString<unsigned long>(request.get_argument("start"));
|
|
||||||
} catch (...) {}
|
|
||||||
const auto s = std::min(startIndex, totalResults);
|
const auto s = std::min(startIndex, totalResults);
|
||||||
bookIdsToDump.erase(bookIdsToDump.begin(), bookIdsToDump.begin()+s);
|
bookIdsToDump.erase(bookIdsToDump.begin(), bookIdsToDump.begin()+s);
|
||||||
if (count>0 && bookIdsToDump.size() > count) {
|
if (count>0 && bookIdsToDump.size() > count) {
|
||||||
|
|
|
@ -74,6 +74,15 @@ class RequestContext {
|
||||||
return v;
|
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;
|
RequestMethod get_method() const;
|
||||||
std::string get_url() const;
|
std::string get_url() const;
|
||||||
|
|
Loading…
Reference in New Issue