updated player deployment for digiserver

This commit is contained in:
ske087
2026-06-07 23:40:50 +03:00
parent b97372f74d
commit f674330b93
30 changed files with 3459 additions and 201 deletions
+46 -3
View File
@@ -41,7 +41,7 @@ def list():
@players_bp.route('/add', methods=['GET', 'POST'])
@login_required
def add_player():
"""Add a new player."""
"""Add a new player with optional SSH deployment."""
if request.method == 'GET':
playlists = Playlist.query.filter_by(is_active=True).order_by(Playlist.name).all()
return render_template('players/add_player.html', playlists=playlists)
@@ -55,6 +55,13 @@ def add_player():
orientation = request.form.get('orientation', 'Landscape')
playlist_id = request.form.get('playlist_id', '').strip()
# Get SSH deployment info if provided
ssh_hostname = request.form.get('ssh_hostname', '').strip()
ssh_username = request.form.get('ssh_username', '').strip()
ssh_password = request.form.get('ssh_password', '').strip()
ssh_port = int(request.form.get('ssh_port', '22')) if request.form.get('ssh_port') else 22
deploy_player = request.form.get('deploy_player', '').strip()
# Validation
if not name or len(name) < 3:
flash('Player name must be at least 3 characters long.', 'warning')
@@ -102,14 +109,50 @@ def add_player():
log_action('info', f'Player "{name}" (hostname: {hostname}) created')
# If deployment requested and SSH credentials provided, trigger background deployment
deployment_initiated = False
if deploy_player and ssh_hostname and ssh_username and ssh_password:
try:
from app.utils.background_tasks import background_player_deployment, run_background_task
# Get server URL for player configuration
from flask import request as flask_request
server_url = f"{flask_request.scheme}://{flask_request.host}/digiserver"
# Generate API key for player authentication
import hashlib
api_key = hashlib.sha256(f'{name}:{hostname}'.encode()).hexdigest()[:32]
# Start deployment in background thread
run_background_task(
background_player_deployment,
hostname=ssh_hostname,
username=ssh_username,
password=ssh_password,
player_name=name,
player_id=new_player.id,
port=ssh_port,
server_url=server_url,
server_api_key=api_key
)
deployment_initiated = True
log_action('info', f'Background deployment initiated for player "{name}" on {ssh_hostname}')
except Exception as deploy_err:
log_action('error', f'Failed to initiate background deployment for player "{name}": {str(deploy_err)}')
# Flash detailed success message
success_msg = f'''
Player "{name}" created successfully!<br>
<strong>Auth Code:</strong> {auth_code}<br>
<strong>Auth Code:</strong> <code style="background: #f0f0f0; padding: 2px 6px; border-radius: 3px;">{auth_code}</code><br>
<strong>Hostname:</strong> {hostname}<br>
<strong>Quick Connect:</strong> {quickconnect_code}<br>
<small>Configure the player with these credentials in app_config.json</small>
'''
if deployment_initiated:
success_msg += f'<strong style="color: #0275d8;">⏳ Deployment in Progress</strong> Deploying to {ssh_hostname} in background...<br>'
success_msg += '<small>Check player status to see deployment completion</small><br>'
success_msg += '<small>Configure the player with these credentials in app_config.json</small>'
flash(success_msg, 'success')
return redirect(url_for('players.list'))