diff --git a/apps/m3u/api_views.py b/apps/m3u/api_views.py index 6176a0ca..daac92b1 100644 --- a/apps/m3u/api_views.py +++ b/apps/m3u/api_views.py @@ -51,7 +51,15 @@ class M3UAccountViewSet(viewsets.ModelViewSet): # Add file_path to the request data so it's available during creation request.data._mutable = True # Allow modification of the request data request.data['file_path'] = file_path # Include the file path if a file was uploaded - request.data.pop('server_url') + + # Handle the user_agent field - convert "null" string to None + if 'user_agent' in request.data and request.data['user_agent'] == 'null': + request.data['user_agent'] = None + + # Handle server_url appropriately + if 'server_url' in request.data and not request.data['server_url']: + request.data.pop('server_url') + request.data._mutable = False # Make the request data immutable again # Now call super().create() to create the instance @@ -82,16 +90,24 @@ class M3UAccountViewSet(viewsets.ModelViewSet): # Add file_path to the request data so it's available during creation request.data._mutable = True # Allow modification of the request data request.data['file_path'] = file_path # Include the file path if a file was uploaded - request.data.pop('server_url') + + # Handle the user_agent field - convert "null" string to None + if 'user_agent' in request.data and request.data['user_agent'] == 'null': + request.data['user_agent'] = None + + # Handle server_url appropriately + if 'server_url' in request.data and not request.data['server_url']: + request.data.pop('server_url') + request.data._mutable = False # Make the request data immutable again if instance.file_path and os.path.exists(instance.file_path): os.remove(instance.file_path) - # Now call super().create() to create the instance + # Now call super().update() to update the instance response = super().update(request, *args, **kwargs) - # After the instance is created, return the response + # After the instance is updated, return the response return response def partial_update(self, request, *args, **kwargs): diff --git a/frontend/src/components/forms/M3U.jsx b/frontend/src/components/forms/M3U.jsx index 8e8fd932..9affa984 100644 --- a/frontend/src/components/forms/M3U.jsx +++ b/frontend/src/components/forms/M3U.jsx @@ -307,7 +307,7 @@ const M3U = ({ description="User-Agent header to use when accessing this M3U source" {...form.getInputProps('user_agent')} key={form.key('user_agent')} - data={[{ value: '0', label: '(use default)' }].concat( + data={[{ value: '0', label: '(Use Default)' }].concat( userAgents.map((ua) => ({ label: ua.name, value: `${ua.id}`,