From 0750b7dd80cf058cf7508e2465a67ed47e0c03f1 Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Tue, 4 Mar 2025 11:38:01 -0600 Subject: [PATCH] Fixes CRSF issues. --- apps/proxy/ts_proxy/views.py | 46 ++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/apps/proxy/ts_proxy/views.py b/apps/proxy/ts_proxy/views.py index 2d4b0c6a..56276540 100644 --- a/apps/proxy/ts_proxy/views.py +++ b/apps/proxy/ts_proxy/views.py @@ -9,6 +9,28 @@ from .server import ProxyServer logger = logging.getLogger(__name__) proxy_server = ProxyServer() +@csrf_exempt +@require_http_methods(["POST"]) +def initialize_stream(request, channel_id): + """Initialize a new stream channel""" + try: + data = json.loads(request.body) + url = data.get('url') + if not url: + return JsonResponse({'error': 'No URL provided'}, status=400) + + proxy_server.initialize_channel(url, channel_id) + return JsonResponse({ + 'message': 'Stream initialized', + 'channel': channel_id, + 'url': url + }) + except json.JSONDecodeError: + return JsonResponse({'error': 'Invalid JSON'}, status=400) + except Exception as e: + logger.error(f"Failed to initialize stream: {e}") + return JsonResponse({'error': str(e)}, status=500) + @csrf_exempt @require_http_methods(["GET"]) def stream_ts(request, channel_id): @@ -39,7 +61,7 @@ def stream_ts(request, channel_id): except Exception as e: logger.error(f"Streaming error for channel {channel_id}: {e}") - finally: # Add finally block to ensure cleanup + finally: try: if channel_id in proxy_server.client_managers: remaining = proxy_server.client_managers[channel_id].remove_client(client_id) @@ -54,28 +76,6 @@ def stream_ts(request, channel_id): content_type='video/MP2T' ) -@csrf_exempt -@require_http_methods(["POST"]) -def initialize_stream(request, channel_id): - """Initialize a new stream channel""" - try: - data = json.loads(request.body) - url = data.get('url') - if not url: - return JsonResponse({'error': 'No URL provided'}, status=400) - - proxy_server.initialize_channel(url, channel_id) - return JsonResponse({ - 'message': 'Stream initialized', - 'channel': channel_id, - 'url': url - }) - except json.JSONDecodeError: - return JsonResponse({'error': 'Invalid JSON'}, status=400) - except Exception as e: - logger.error(f"Failed to initialize stream: {e}") - return JsonResponse({'error': str(e)}, status=500) - @csrf_exempt @require_http_methods(["POST"]) def change_stream(request, channel_id):