Add toggle for automatic MusicGPT polling in settings
This commit is contained in:
parent
77cd712f10
commit
2ec73dee0f
3 changed files with 46 additions and 3 deletions
22
app.py
22
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),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue