From 7a6085dc71efdf64d866ff0768aaa175363a1f0b Mon Sep 17 00:00:00 2001 From: mus-taches Date: Fri, 15 Nov 2024 09:37:43 +0100 Subject: [PATCH] refactor: use Node static methods to handle widget values --- py/cozy_spoke.py | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/py/cozy_spoke.py b/py/cozy_spoke.py index c085886..75ba251 100644 --- a/py/cozy_spoke.py +++ b/py/cozy_spoke.py @@ -2,12 +2,14 @@ # https://github.com/cozy-comfyui/cozy_spoke import time -import toml -from pathlib import Path +# import toml +# from pathlib import Path from typing import Any -from aiohttp import web +from aiohttp import web # , ClientSession from server import PromptServer +from .node import Node + EVENT_COZY_UPDATE = "cozy-event-combo-update" @@ -40,17 +42,7 @@ def poll(cls, ident, period=0.01, timeout=3) -> Any: def initialize_cozy_spoke(): - # Load action config data - path = Path(__file__).parent.parent / "config/actions.toml" - - try: - with open(path) as file: - data = toml.load(file) - except Exception: - print(f"Error loading {path}") - data = {} - - # Define routes + data = Node.load_data("actions.toml") @PromptServer.instance.routes.get("/cozy_spoke") async def route_cozy_spoke(request) -> Any: @@ -85,7 +77,8 @@ async def route_cozy_spoke_update(request) -> Any: result = {} if (response := json_data.get("data")) is not None: acts = data["nsfw"]["acts"] - result = {'data': acts.get(response.lower(), - [])} + selected_acts = acts.get(response.lower(), []) + inputs = Node.build_inputs_list(selected_acts) + result = {'data': inputs} return web.json_response(result)