From 2c91a5666e709fa1f94181d1c8e20de7344cefe2 Mon Sep 17 00:00:00 2001 From: ske087 Date: Wed, 1 Jul 2026 19:21:59 +0300 Subject: [PATCH] updated player deploy and config --- .dev-pids | 10 +- digiserver-v2/app/blueprints/content.py | 80 +++++++++++++++ .../app/templates/content/upload_media.html | 98 +++++++++++++++++++ 3 files changed, 183 insertions(+), 5 deletions(-) diff --git a/.dev-pids b/.dev-pids index 8f3ed45..79099e7 100644 --- a/.dev-pids +++ b/.dev-pids @@ -1,5 +1,5 @@ -36827 -36829 -36831 -36833 -36835 +77016 +77018 +77020 +77022 +77024 diff --git a/digiserver-v2/app/blueprints/content.py b/digiserver-v2/app/blueprints/content.py index 6ce77d5..9c3d77e 100644 --- a/digiserver-v2/app/blueprints/content.py +++ b/digiserver-v2/app/blueprints/content.py @@ -267,6 +267,86 @@ def add_content_to_playlist(playlist_id: int): return redirect(url_for('content.manage_playlist_content', playlist_id=playlist_id)) +@content_bp.route('/add-weblink', methods=['POST']) +@login_required +def add_weblink(): + """Create a web link content item from the Upload Media page. + + Optionally adds it directly to a playlist if playlist_id is supplied. + Returns JSON when the request carries Accept: application/json, otherwise + redirects back to the upload page. + """ + use_json = 'application/json' in request.accept_mimetypes.best or \ + request.headers.get('X-Requested-With') == 'XMLHttpRequest' + + 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 + playlist_id = request.form.get('playlist_id', type=int) + + parsed = urlparse(web_url) + if parsed.scheme.lower() not in ('http', 'https') or not parsed.netloc: + if use_json: + return jsonify({'success': False, 'error': 'Please enter a valid http:// or https:// web address.'}), 400 + flash('Please enter a valid http:// or https:// web address.', 'warning') + return redirect(url_for('content.upload_media_page')) + + if not duration or duration < 1: + duration = 30 + + 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() + + if playlist_id: + playlist = Playlist.query.get(playlist_id) + if 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() + log_action('info', f'Web link "{web_url}" added to playlist "{playlist.name}"') + else: + log_action('warning', f'Web link "{web_url}" created; playlist {playlist_id} not found') + else: + log_action('info', f'Web link "{web_url}" added to media library') + + db.session.commit() + cache.clear() + + if use_json: + return jsonify({'success': True, 'content_id': content.id, 'message': 'Web link added successfully.'}) + flash('Web link added successfully.', 'success') + + except Exception as e: + db.session.rollback() + log_action('error', f'Error adding web link: {str(e)}') + if use_json: + return jsonify({'success': False, 'error': 'Failed to add web link.'}), 500 + flash('Error adding web link.', 'danger') + + return redirect(url_for('content.upload_media_page')) + + @content_bp.route('/playlist//add-weblink', methods=['POST']) @login_required def add_weblink_to_playlist(playlist_id: int): diff --git a/digiserver-v2/app/templates/content/upload_media.html b/digiserver-v2/app/templates/content/upload_media.html index 3389ff6..7aabd60 100644 --- a/digiserver-v2/app/templates/content/upload_media.html +++ b/digiserver-v2/app/templates/content/upload_media.html @@ -315,6 +315,67 @@ + + +
+

+ 🌐 Add Web Page Link +

+

+ Add a website URL to display on the player (e.g. a dashboard, live feed, or any public web page). +

+ + +
+ {% endblock %}