diff --git a/app.py b/app.py index 0dbe65e..780a24c 100644 --- a/app.py +++ b/app.py @@ -58,6 +58,7 @@ from helpers import ( get_max_revisions, get_callback_expiry_hours, get_hermes_api_key, set_hermes_api_key, generate_hermes_api_key, mask_api_key, get_musicgpt_api_key, get_musicgpt_default_model, get_musicgpt_models, + get_musicgpt_autopoll_enabled, set_musicgpt_autopoll_enabled, build_musicgpt_webhook_url, musicgpt_generate_request, musicgpt_queue_stems, musicgpt_poll_status, download_musicgpt_outputs, format_musicgpt_cost, get_musicgpt_cost_totals, @@ -378,6 +379,17 @@ def musicgpt_webhook(): return jsonify({'ok': False, 'reason': 'unknown_conversion_type'}), 400 +@app.route('/admin/musicgpt/autopoll', methods=['POST']) +def admin_musicgpt_autopoll(): + """Internal endpoint used by the cron job. Only runs refresh if auto-poll is enabled.""" + redir = require_admin() + if redir: + return redir + if not get_musicgpt_autopoll_enabled(): + return jsonify({'ok': True, 'autopoll': False, 'message': 'Automatic polling is disabled in settings.'}), 200 + return admin_musicgpt_refresh() + + @app.route('/admin/musicgpt/refresh', methods=['POST']) def admin_musicgpt_refresh(): """Manual dashboard action: poll all in-flight MusicGPT tasks and update statuses.""" @@ -1273,6 +1285,7 @@ def admin_settings(): current_max_revisions = get_max_revisions() current_refresh_seconds = runtime_settings.get('refresh_seconds', 10) booth_open = runtime_settings.get('booth_open', True) + musicgpt_autopoll = runtime_settings.get('musicgpt_autopoll', True) # Effective email config to show in the form (non-sensitive only; password left blank). email_form = { @@ -1579,6 +1592,14 @@ def admin_settings(): flash('Album cover delivery setting saved.', 'success') return redirect(url_for('admin_settings')) + elif action == 'save_musicgpt_autopoll': + cfg = load_booth_settings() + cfg['musicgpt_autopoll'] = request.form.get('musicgpt_autopoll', '0') == '1' + save_booth_settings(cfg) + state = 'enabled' if cfg['musicgpt_autopoll'] else 'disabled' + flash(f'Automatic MusicGPT polling {state}.', 'success') + return redirect(url_for('admin_settings')) + return render_template( 'admin/settings.html', health=health, @@ -1611,6 +1632,7 @@ def admin_settings(): deliver_album_cover=runtime_settings.get('deliver_album_cover', False), musicgpt_api_key_set=bool(get_musicgpt_api_key()), musicgpt_webhook_url=build_musicgpt_webhook_url(), + musicgpt_autopoll=runtime_settings.get('musicgpt_autopoll', True), ) diff --git a/helpers.py b/helpers.py index d84dc4b..e29cb30 100644 --- a/helpers.py +++ b/helpers.py @@ -527,9 +527,17 @@ def get_booth_open(): return cfg.get('booth_open', True) -# --------------------------------------------------------------------------- -# MusicGPT API client -# --------------------------------------------------------------------------- +def get_musicgpt_autopoll_enabled(): + """Return True if automatic MusicGPT polling is enabled (default True).""" + cfg = load_booth_settings() + return cfg.get('musicgpt_autopoll', True) + + +def set_musicgpt_autopoll_enabled(enabled): + """Persist the automatic MusicGPT polling toggle.""" + cfg = load_booth_settings() + cfg['musicgpt_autopoll'] = bool(enabled) + save_booth_settings(cfg) MUSICGPT_API_BASE = "https://api.musicgpt.com/api/public" diff --git a/templates/admin/settings.html b/templates/admin/settings.html index aaef2e0..1c36c7b 100644 --- a/templates/admin/settings.html +++ b/templates/admin/settings.html @@ -359,6 +359,19 @@ + +
When enabled, the site automatically polls MusicGPT every few minutes and downloads MP3/WAV files once they are ready.
+