Start a proxy server for a channel
(self, request)
| 11 | |
| 12 | @action(detail=False, methods=['post']) |
| 13 | def start(self, request): |
| 14 | """Start a proxy server for a channel""" |
| 15 | try: |
| 16 | proxy_type = request.data.get('type', 'hls') |
| 17 | channel_id = request.data.get('channel', 'default') |
| 18 | url = request.data.get('url') |
| 19 | |
| 20 | if not url: |
| 21 | return Response( |
| 22 | {'error': 'URL is required'}, |
| 23 | status=status.HTTP_400_BAD_REQUEST |
| 24 | ) |
| 25 | |
| 26 | proxy_app = apps.get_app_config('proxy') |
| 27 | proxy_server = getattr(proxy_app, f'{proxy_type}_proxy') |
| 28 | proxy_server.initialize_channel(url, channel_id) |
| 29 | |
| 30 | return Response({ |
| 31 | 'message': f'{proxy_type.upper()} proxy started', |
| 32 | 'channel': channel_id, |
| 33 | 'url': url |
| 34 | }) |
| 35 | |
| 36 | except Exception as e: |
| 37 | logger.error(f"Error starting proxy: {e}") |
| 38 | return Response( |
| 39 | {'error': str(e)}, |
| 40 | status=status.HTTP_500_INTERNAL_SERVER_ERROR |
| 41 | ) |
| 42 | |
| 43 | @action(detail=False, methods=['post']) |
| 44 | def stop(self, request): |