MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / create

Method create

apps/m3u/api_views.py:91–146  ·  view source on GitHub ↗
(self, request, *args, **kwargs)

Source from the content-addressed store, hash-verified

89 return Response(serializer.data)
90
91 def create(self, request, *args, **kwargs):
92 # Handle file upload first, if any
93 file_path = None
94 if "file" in request.FILES:
95 file = request.FILES["file"]
96 try:
97 file_path = safe_upload_path(file.name, "/data/uploads/m3us")
98 except ValueError:
99 return Response({"detail": "Invalid filename."}, status=status.HTTP_400_BAD_REQUEST)
100
101 os.makedirs("/data/uploads/m3us", exist_ok=True)
102 with open(file_path, "wb+") as destination:
103 for chunk in file.chunks():
104 destination.write(chunk)
105
106 # Add file_path to the request data so it's available during creation
107 request.data._mutable = True # Allow modification of the request data
108 request.data["file_path"] = (
109 file_path # Include the file path if a file was uploaded
110 )
111
112 # Handle the user_agent field - convert "null" string to None
113 if "user_agent" in request.data and request.data["user_agent"] == "null":
114 request.data["user_agent"] = None
115
116 # Handle server_url appropriately
117 if "server_url" in request.data and not request.data["server_url"]:
118 request.data.pop("server_url")
119
120 request.data._mutable = False # Make the request data immutable again
121
122 # Now call super().create() to create the instance
123 response = super().create(request, *args, **kwargs)
124
125 account_type = response.data.get("account_type")
126 account_id = response.data.get("id")
127
128 # Notify frontend that a new playlist was created
129 from core.utils import send_websocket_update
130 send_websocket_update('updates', 'update', {
131 'type': 'playlist_created',
132 'playlist_id': account_id
133 })
134
135 if account_type == M3UAccount.Types.XC:
136 refresh_m3u_groups(account_id)
137
138 # Check if VOD is enabled
139 enable_vod = request.data.get("enable_vod", False)
140 if enable_vod:
141 from apps.vod.tasks import refresh_categories
142
143 refresh_categories(account_id)
144
145 # After the instance is created, return the response
146 return response
147
148 def update(self, request, *args, **kwargs):

Calls 5

safe_upload_pathFunction · 0.90
send_websocket_updateFunction · 0.90
refresh_categoriesFunction · 0.90
refresh_m3u_groupsFunction · 0.85
getMethod · 0.45