mirror of
https://github.com/adulau/hashlookup-server.git
synced 2024-12-10 02:47:18 +00:00
new: [server] /children and /parents end-points added
The two new endpoints `children` and `parents` allow to paginate over the large-set of parents or children. - The first value is the SHA1 value having children or parents. - The second value is the number of elements to get (by default is 100 if the value is set to 0). - The third value is the cursor to paginate over the element (for starting the cursor must be set to 0). A sample usage: ~~~~ adulau@kolmogorov ~ $ curl -s http://127.0.0.1:5000/children/31C43D24d696BC5F5309CCBFA5BDEF65A7170439/10/0 | jq . { "children": [ "003587440172055C75130EF1A063C3BB050C3251", "007C1E16B3F0F2E48C114E458308397953C7D224", "014D1060C674FBBCEAFFD94B85D60AD00618B56B", "01A2FACD61D157FC80DD0C5F6B525CC9EDE4B6DE", "01D1A98F559966A05923A74EE239C6BBEEB0FDAC", "01D381F2FCDD1BDF642AF83C9E96083F2C8D1C03", "02B37BA21D1831C120C1C9C1D41893B4DB424EE7", "02DED521ADCF17AA8818EA1142F63E05F558E668", "0364E0EFE65D9B6502084813189B4D888C117859", "05C9A276A0E03F7A5F99DE5CC8911583FD8FD60E" ], "cursor": "05C9A276A0E03F7A5F99DE5CC8911583FD8FD60E", "total": 774 } adulau@kolmogorov ~ $ curl -s http://127.0.0.1:5000/children/31C43D24d696BC5F5309CCBFA5BDEF65A7170439/10/05C9A276A0E03F7A5F99DE5CC8911583FD8FD60E | jq . { "children": [ "063EC5526DA21372D77AFC3C40F694478521829B", "0647EA948ED37383F74CC68A94E2DC3CBC2A9E4E", "0648AAAC06A76A58CB1E999882447BBDEEA42C57", "06A62F10F269824FFD75A917A35ACD3F2461981C", "0727FE9E2437B15B3F879C7617973AE11E55BA13", "074A0CA7131AE8FD9665CFE68A0C124EB6AD0170", "075B11AE383071BDA9BE66E336C916F6E6E1F49C", "081A336DE7D636F95F0150B7708C614592CBBDAE", "08DF546EE44D4B7546FCE5A7B7E284CA35F1B059", "0947CE713B69C2318CA684BBB63912621CC17A6A" ], "cursor": "0947CE713B69C2318CA684BBB63912621CC17A6A", "total": 774 } ~~~~
This commit is contained in:
parent
74efc57b3d
commit
baf2b82f7b
1 changed files with 52 additions and 0 deletions
|
@ -357,6 +357,58 @@ class lookup(Resource):
|
|||
return h
|
||||
|
||||
|
||||
@api.route('/parents/<string:sha1>/<int:count>/<string:cursor>')
|
||||
@api.doc(
|
||||
description="Return parents from a given SHA1. A number of element to return and an offset must be given. If not set it will be the 100 first elements. A cursor must be given to paginate over. The starting cursor is 0."
|
||||
)
|
||||
class parents(Resource):
|
||||
def get(self, sha1, count, cursor):
|
||||
if check_sha1(value=sha1) is False:
|
||||
return {
|
||||
'message': 'SHA1 value incorrect, expecting a SHA1 value in hex format.'
|
||||
}, 400
|
||||
sha1 = check_sha1(value=sha1)
|
||||
if not count:
|
||||
count = 100
|
||||
if not cursor:
|
||||
cursor = 0
|
||||
if not rdb.exists("p:{}".format(sha1)):
|
||||
return {'message': 'The SHA1 value has no known parent.'}, 404
|
||||
parents = []
|
||||
cursor, parents = rdb.sscan("p:{}".format(sha1), count=count, cursor=cursor)
|
||||
h = {}
|
||||
h['parents'] = parents
|
||||
h['cursor'] = cursor
|
||||
h['total'] = rdb.scard("p:{}".format(sha1))
|
||||
return h
|
||||
|
||||
|
||||
@api.route('/children/<string:sha1>/<int:count>/<string:cursor>')
|
||||
@api.doc(
|
||||
description="Return children from a given SHA1. A number of element to return and an offset must be given. If not set it will be the 100 first elements. A cursor must be given to paginate over. The starting cursor is 0."
|
||||
)
|
||||
class children(Resource):
|
||||
def get(self, sha1, count, cursor):
|
||||
if check_sha1(value=sha1) is False:
|
||||
return {
|
||||
'message': 'SHA1 value incorrect, expecting a SHA1 value in hex format.'
|
||||
}, 400
|
||||
sha1 = check_sha1(value=sha1)
|
||||
if not count:
|
||||
count = 100
|
||||
if not cursor:
|
||||
cursor = 0
|
||||
if not rdb.exists("c:{}".format(sha1)):
|
||||
return {'message': 'The SHA1 value has no known child.'}, 404
|
||||
children = []
|
||||
cursor, children = rdb.sscan("c:{}".format(sha1), count=count, cursor=cursor)
|
||||
h = {}
|
||||
h['children'] = children
|
||||
h['cursor'] = cursor
|
||||
h['total'] = rdb.scard("c:{}".format(sha1))
|
||||
return h
|
||||
|
||||
|
||||
@api.route('/info')
|
||||
@api.doc(description="Info about the hashlookup database")
|
||||
class info(Resource):
|
||||
|
|
Loading…
Reference in a new issue