mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-04-13 22:38:00 +08:00
adding pagination requirement to 'names in namespace' api call, and fixing bug in pagination where it would infinite loop trying to fetch pages above the total number of names
This commit is contained in:
@@ -651,6 +651,9 @@ def get_all_names(offset=None, count=None, proxy=None):
|
||||
# error
|
||||
error_str = 'server replied too much data'
|
||||
return {'error': error_str}
|
||||
elif len(page) == 0:
|
||||
# end-of-table
|
||||
break
|
||||
|
||||
all_names += page
|
||||
|
||||
@@ -833,6 +836,9 @@ def get_names_in_namespace(namespace_id, offset=None, count=None, proxy=None):
|
||||
# error
|
||||
error_str = 'server replied too much data'
|
||||
return {'error': error_str}
|
||||
elif len(page) == 0:
|
||||
# end-of-table
|
||||
break
|
||||
|
||||
all_names += page
|
||||
|
||||
|
||||
@@ -55,9 +55,6 @@ from types import ModuleType
|
||||
import keylib
|
||||
from keylib import *
|
||||
|
||||
import virtualchain
|
||||
from virtualchain.lib.ecdsalib import *
|
||||
|
||||
import signal
|
||||
import json
|
||||
import config as blockstack_config
|
||||
@@ -1785,8 +1782,19 @@ class BlockstackAPIEndpointHandler(SimpleHTTPRequestHandler):
|
||||
"""
|
||||
|
||||
qs_values = path_info['qs_values']
|
||||
offset = qs_values.get('offset', None)
|
||||
count = qs_values.get('count', None)
|
||||
page = qs_values.get('page', None)
|
||||
if page is None:
|
||||
log.error("Page required")
|
||||
return self._reply_json({'error': 'page= argument required'}, status_code=401)
|
||||
|
||||
try:
|
||||
page = int(page)
|
||||
except ValueError:
|
||||
log.error("Invalid page")
|
||||
return self._reply_json({'error': 'Invalid page= value'}, status_code=401)
|
||||
|
||||
offset = page * 100
|
||||
count = 100
|
||||
|
||||
namespace_names = proxy.get_names_in_namespace(namespace_id, offset=offset, count=count)
|
||||
if json_is_error(namespace_names):
|
||||
|
||||
Reference in New Issue
Block a user