From 94d4a239cee5ff1bcdb950222cd3e5cebdddb253 Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Sat, 10 May 2025 10:28:44 -0400 Subject: [PATCH] feat: add API endpoint to retrieve hourly usage caps for apps --- src/primary/web_server.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/primary/web_server.py b/src/primary/web_server.py index 5181ccf4..993d59e6 100644 --- a/src/primary/web_server.py +++ b/src/primary/web_server.py @@ -758,6 +758,39 @@ def api_reset_stats(): web_logger.error(f"Error resetting statistics: {str(e)}") return jsonify({"success": False, "error": str(e)}), 500 +@app.route('/api/hourly-caps', methods=['GET']) +def api_get_hourly_caps(): + """Get hourly API usage caps for each app""" + try: + # Import necessary functions + from src.primary.stats_manager import load_hourly_caps + from src.primary.settings_manager import load_settings + + # Get the logger + web_logger = get_logger("web_server") + + # Load the current hourly caps + caps = load_hourly_caps() + + # Get the hourly cap limit from general settings + settings = load_settings('general') + hourly_limit = settings.get('hourly_cap', 20) # Default to 20 if not set + + web_logger.info(f"Serving hourly caps data with limit {hourly_limit}") + + return jsonify({ + "success": True, + "caps": caps, + "limit": hourly_limit + }) + except Exception as e: + web_logger = get_logger("web_server") + web_logger.error(f"Error retrieving hourly API caps: {e}") + return jsonify({ + "success": False, + "message": "Error retrieving hourly API caps." + }), 500 + @app.route('/api/stats/reset_public', methods=['POST']) def api_reset_stats_public(): """Reset the media statistics for all apps or a specific app - public endpoint without auth"""