From c17dbff6a617d5cc6dc746b3e7126572b183a666 Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Sun, 29 Aug 2021 14:06:35 +0200 Subject: [PATCH] new: [api:stats/top] Add a new optional entry to point to get the top 100 of most queried hashes (existing and non-existing) --- bin/server.py | 18 ++++++++++++++++++ etc/server.conf.sample | 1 + 2 files changed, 19 insertions(+) diff --git a/bin/server.py b/bin/server.py index 4451d13..a4c1b24 100644 --- a/bin/server.py +++ b/bin/server.py @@ -9,6 +9,7 @@ config = configparser.ConfigParser() config.read('../etc/server.conf') stats = config['global'].getboolean('stats') stats_pubsub = config['global'].getboolean('stats_pubsub') +stats_public = config['global'].getboolean('stats_public') score = 1 session = config['session'].getboolean('enable') session_ttl = config['session'].get('ttl') @@ -263,6 +264,23 @@ class sessioncreate(Resource): ret['info'] = rdb.get('session:{}'.format(name)) return ret +@api.route('/stats/top') +@api.doc(description="Return the top 100 of most queried values.") +class stattop(Resource): + def get(self): + if stats_public is False: + return {'message': 'Public statistics not enabled'}, 400 + ret = {} + ret['nx'] = rdb.zrevrange("s:nx:sha1", 0, 100, withscores=True) + exist = rdb.zrevrange("s:exist:sha1", 0, 100, withscores=True) + ret['exist'] = [] + for value in exist: + name = rdb.hget("h:{}".format(value[0]), "FileName") + entry = {} + entry['FileName'] = name + entry['SHA-1'] = value + ret['exist'].append(entry) + return ret if __name__ == '__main__': app.run(host='0.0.0.0') diff --git a/etc/server.conf.sample b/etc/server.conf.sample index b6c4abd..3a94d94 100644 --- a/etc/server.conf.sample +++ b/etc/server.conf.sample @@ -1,6 +1,7 @@ [global] stats = yes stats_pubsub = yes +stats_public = yes [session] enable = yes ttl = 86400