mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-27 07:47:03 -05:00
Disable limit to 20 entries in JSON API pagination
This commit is contained in:
parent
abe84a4f81
commit
f12cc9ca68
@ -1,4 +1,22 @@
|
||||
#pragma once
|
||||
/*
|
||||
* libresapi
|
||||
* Copyright (C) 2015 electron128 <electron128@yahoo.com>
|
||||
* Copyright (C) 2017 Gioacchino Mazzurco <gio@eigenlab.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ApiTypes.h"
|
||||
|
||||
@ -13,13 +31,6 @@ namespace resource_api
|
||||
template<class C>
|
||||
void handlePaginationRequest(Request& req, Response& resp, C& data)
|
||||
{
|
||||
/*
|
||||
if(!req.isGet()){
|
||||
resp.mDebug << "unsupported method. only GET is allowed." << std::endl;
|
||||
resp.setFail();
|
||||
return;
|
||||
}
|
||||
*/
|
||||
if(data.begin() == data.end()){
|
||||
// set result type to list
|
||||
resp.mDataStream.getStreamToMember();
|
||||
@ -30,7 +41,8 @@ void handlePaginationRequest(Request& req, Response& resp, C& data)
|
||||
|
||||
std::string begin_after;
|
||||
std::string last;
|
||||
req.mStream << makeKeyValueReference("begin_after", begin_after) << makeKeyValueReference("last", last);
|
||||
req.mStream << makeKeyValueReference("begin_after", begin_after)
|
||||
<< makeKeyValueReference("last", last);
|
||||
|
||||
typename C::iterator it_first = data.begin();
|
||||
if(begin_after != "begin" && begin_after != "")
|
||||
@ -62,7 +74,17 @@ void handlePaginationRequest(Request& req, Response& resp, C& data)
|
||||
++it_last; // increment to get iterator to element after the last wanted element
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
/* G10h4ck: Guarded message count limitation with
|
||||
* JSON_API_LIMIT_CHAT_MSG_COUNT_BY_DEFAULT as ATM it seems that handling a
|
||||
* big bunch of messages hasn't been a problem for client apps, and even in
|
||||
* that case the client can specify +begin_after+ and +last+ in the request,
|
||||
* this way we don't make more difficult the life of those who just want get
|
||||
* the whole list of chat messages that seems to be a common usecase
|
||||
*/
|
||||
#ifdef JSON_API_LIMIT_CHAT_MSG_COUNT_BY_DEFAULT
|
||||
int count = 0;
|
||||
#endif
|
||||
|
||||
for(typename C::iterator it = it_first; it != it_last; ++it)
|
||||
{
|
||||
StreamBase& stream = resp.mDataStream.getStreamToMember();
|
||||
@ -71,11 +93,16 @@ void handlePaginationRequest(Request& req, Response& resp, C& data)
|
||||
|
||||
// todo: also handle the case when the last element is specified and the first element is begin
|
||||
// then want to return the elements near the specified element
|
||||
count++;
|
||||
if(count > 20){
|
||||
resp.mDebug << "limited the number of returned items to 20" << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
// G10h4ck: @see first comment about JSON_API_LIMIT_CHAT_MSG_COUNT_BY_DEFAULT
|
||||
#ifdef JSON_API_LIMIT_CHAT_MSG_COUNT_BY_DEFAULT
|
||||
++count;
|
||||
if(count > 20)
|
||||
{
|
||||
resp.mDebug << "limited the number of returned items to 20";
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
resp.setOk();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user