RequestContext::get_optional_param()

This commit is contained in:
Veloman Yunkan 2021-04-26 02:25:37 +04:00
parent 70d42aec98
commit b60e3ffb26
2 changed files with 11 additions and 8 deletions

View File

@ -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) {

View File

@ -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;