@@ -216,7 +216,44 @@ async def manage_configuration(request):
216216 logging .error (f"Error managing configuration: { str (e )} " )
217217 return web .json_response ({"error" : str (e )}, status = 500 )
218218
219+ @routes .post ('/comfystream/settings/manage' )
220+ async def manage_comfystream (request ):
221+ """Manage ComfyStream server settings"""
222+ #check if server is running
223+ server_status = server_manager .get_status ()
224+ if not server_status ["running" ]:
225+ return web .json_response ({"error" : "ComfyStream Server is not running" }, status = 503 )
226+
227+ try :
228+ data = await request .json ()
229+ action_type = data .get ("action_type" )
230+ action = data .get ("action" )
231+ payload = data .get ("payload" )
232+ url_host = server_status .get ("host" , "localhost" )
233+ url_port = server_status .get ("port" , "8889" )
234+ mgmt_url = f"http://{ url_host } :{ url_port } /settings/{ action_type } /{ action } "
235+
236+ async with aiohttp .ClientSession () as session :
237+ async with session .post (
238+ mgmt_url ,
239+ json = payload ,
240+ headers = {"Content-Type" : "application/json" }
241+ ) as response :
242+ if not response .ok :
243+ return web .json_response (
244+ {"error" : f"Server error: { response .status } " },
245+ status = response .status
246+ )
247+ return web .json_response (await response .json ())
248+ except Exception as e :
249+ logging .error (f"Error managing ComfyStream: { str (e )} " )
250+ return web .json_response ({"error" : str (e )}, status = 500 )
251+
219252 @routes .post ('/comfyui/restart' )
220253 async def manage_configuration (request ):
254+ server_status = server_manager .get_status ()
255+ if server_status ["running" ]:
256+ await server_manager .stop ()
257+
221258 subprocess .run (["supervisorctl" , "restart" , "comfyui" ])
222259 return web .json_response ({"success" : True }, status = 200 )
0 commit comments