From ca499d4d2b71fe910f8835dbd2fd4850ff242028 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Tue, 24 May 2022 20:38:29 +0300 Subject: [PATCH] add route for getting db size --- app/server.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/server.py b/app/server.py index e76f57f0..e6794480 100644 --- a/app/server.py +++ b/app/server.py @@ -493,6 +493,19 @@ def profile(username): abort(403) +@app.route("/capacity", methods=["GET"]) +def system_capacity(): + units = {'b': 1, 'mb':1024**2, 'gb': 1024**3} + unit = units.get(request.args.get('unit', 'gb').lower(), units['gb']) + current_size = data.get_storage() + ratio = current_size / app.config['MAX_SYSTEM_STORAGE'] + return { + 'size': current_size / unit, + 'max_size': app.config['MAX_SYSTEM_STORAGE'] / unit, + 'ratio': ratio + } + + # Handle exceptions @app.errorhandler(413)