fix: player connectivity and media download pipeline
- nginx: add /api/ shortcut block (no portal auth, X-Script-Name /digiserver, Host $http_host) so players can reach DigiServer API without /digiserver prefix - nginx: use $http_host in /api/ block so Flask host_url includes port — fixes media download URLs missing :8080 (was http://ip/digiserver/... not http://ip:8080/...) - player main.py: fix double-port bug when server_ip already contains a port (e.g. 192.168.0.230:8080 was producing http://192.168.0.230:8080:80) - get_playlists_v2.py: force re-sync when server version differs OR local media files are missing on disk — fixes stale playlist after server reset - digiserver api.py: playlist endpoint builds full media URLs using script_root from X-Script-Name header set by nginx - weblink support, player build/deploy improvements, manage-playlist AJAX prefix fix
This commit is contained in:
@@ -6,6 +6,9 @@ from werkzeug.utils import secure_filename
|
||||
from typing import Optional
|
||||
import os
|
||||
import threading
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from app.extensions import db, cache
|
||||
from app.models import Content, Playlist, Player
|
||||
@@ -201,8 +204,10 @@ def manage_playlist_content(playlist_id: int):
|
||||
# Get content in playlist (ordered)
|
||||
playlist_content = playlist.get_content_ordered()
|
||||
|
||||
# Get all available content not in this playlist
|
||||
all_content = Content.query.all()
|
||||
# Get all available content not in this playlist.
|
||||
# Web links are created on demand per playlist, so they are not offered
|
||||
# as reusable library items here.
|
||||
all_content = Content.query.filter(Content.content_type != 'weblink').all()
|
||||
playlist_content_ids = {c.id for c in playlist_content}
|
||||
available_content = [c for c in all_content if c.id not in playlist_content_ids]
|
||||
|
||||
@@ -262,6 +267,72 @@ def add_content_to_playlist(playlist_id: int):
|
||||
return redirect(url_for('content.manage_playlist_content', playlist_id=playlist_id))
|
||||
|
||||
|
||||
@content_bp.route('/playlist/<int:playlist_id>/add-weblink', methods=['POST'])
|
||||
@login_required
|
||||
def add_weblink_to_playlist(playlist_id: int):
|
||||
"""Create a web link content item and add it to the playlist."""
|
||||
playlist = Playlist.query.get_or_404(playlist_id)
|
||||
|
||||
try:
|
||||
web_url = (request.form.get('url') or '').strip()
|
||||
duration = request.form.get('duration', type=int, default=30)
|
||||
description = (request.form.get('description') or '').strip() or None
|
||||
|
||||
# Validate the URL: only http/https schemes are allowed (avoid file://, etc.)
|
||||
parsed = urlparse(web_url)
|
||||
if parsed.scheme.lower() not in ('http', 'https') or not parsed.netloc:
|
||||
flash('Please enter a valid http:// or https:// web address.', 'warning')
|
||||
return redirect(url_for('content.manage_playlist_content', playlist_id=playlist_id))
|
||||
|
||||
if duration is None or duration < 1:
|
||||
duration = 30
|
||||
|
||||
# Create a weblink Content row. filename is a synthetic unique label
|
||||
# (no file on disk); the real target lives in the url column.
|
||||
content = Content(
|
||||
filename=f'weblink-{uuid.uuid4().hex[:12]}',
|
||||
content_type='weblink',
|
||||
url=web_url,
|
||||
duration=duration,
|
||||
description=description or web_url,
|
||||
uploaded_at=datetime.utcnow(),
|
||||
)
|
||||
db.session.add(content)
|
||||
db.session.flush() # assign content.id
|
||||
|
||||
# Append to the end of the playlist
|
||||
from sqlalchemy import select, func
|
||||
|
||||
max_pos = db.session.execute(
|
||||
select(func.max(playlist_content.c.position)).where(
|
||||
playlist_content.c.playlist_id == playlist_id
|
||||
)
|
||||
).scalar() or 0
|
||||
|
||||
db.session.execute(
|
||||
playlist_content.insert().values(
|
||||
playlist_id=playlist_id,
|
||||
content_id=content.id,
|
||||
position=max_pos + 1,
|
||||
duration=duration,
|
||||
)
|
||||
)
|
||||
|
||||
playlist.increment_version()
|
||||
db.session.commit()
|
||||
cache.clear()
|
||||
|
||||
log_action('info', f'Added web link "{web_url}" to playlist "{playlist.name}"')
|
||||
flash('Web link added to playlist.', 'success')
|
||||
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
log_action('error', f'Error adding web link to playlist: {str(e)}')
|
||||
flash('Error adding web link to playlist.', 'danger')
|
||||
|
||||
return redirect(url_for('content.manage_playlist_content', playlist_id=playlist_id))
|
||||
|
||||
|
||||
@content_bp.route('/playlist/<int:playlist_id>/remove-content/<int:content_id>', methods=['POST'])
|
||||
@login_required
|
||||
def remove_content_from_playlist(playlist_id: int, content_id: int):
|
||||
@@ -277,6 +348,12 @@ def remove_content_from_playlist(playlist_id: int, content_id: int):
|
||||
(playlist_content.c.content_id == content_id)
|
||||
)
|
||||
db.session.execute(stmt)
|
||||
|
||||
# Web link items are playlist-specific and have no media-library
|
||||
# presence, so delete the orphan Content row when it is removed.
|
||||
content = db.session.get(Content, content_id)
|
||||
if content is not None and content.content_type == 'weblink':
|
||||
db.session.delete(content)
|
||||
|
||||
playlist.increment_version()
|
||||
db.session.commit()
|
||||
|
||||
Reference in New Issue
Block a user