From 44882eab0c6ed9f5b3fae06f948e0069d07d56e9 Mon Sep 17 00:00:00 2001 From: doctorpangloss <@hiddenswitch.com> Date: Thu, 29 Feb 2024 19:29:06 -0800 Subject: [PATCH] Improve typing and file path handling --- comfy/component_model/file_output_path.py | 9 ++++++--- comfy/nodes/package_typing.py | 7 ++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/comfy/component_model/file_output_path.py b/comfy/component_model/file_output_path.py index 12701f4f5..0b35f3379 100644 --- a/comfy/component_model/file_output_path.py +++ b/comfy/component_model/file_output_path.py @@ -29,12 +29,15 @@ def file_output_path(filename: str, type: Literal["input", "output", "temp"] = " output_dir = folder_paths.get_directory_by_type(type) if output_dir is None: raise ValueError(f"no such output directory because invalid type specified (type={type})") - if subfolder is not None: + if subfolder is not None and subfolder != "": full_output_dir = os.path.join(output_dir, subfolder) - if os.path.commonpath((os.path.abspath(full_output_dir), output_dir)) != output_dir: + if os.path.commonpath([os.path.abspath(full_output_dir), output_dir]) != output_dir: raise PermissionError("insecure") output_dir = full_output_dir + filename = os.path.basename(filename) + else: + if os.path.commonpath([os.path.abspath(output_dir), os.path.join(output_dir, filename)]) != output_dir: + raise PermissionError("insecure") - filename = os.path.basename(filename) file = os.path.join(output_dir, filename) return file diff --git a/comfy/nodes/package_typing.py b/comfy/nodes/package_typing.py index 5d9ced150..2313322dd 100644 --- a/comfy/nodes/package_typing.py +++ b/comfy/nodes/package_typing.py @@ -32,7 +32,7 @@ class StringSpecOptions(TypedDict, total=True): # todo: analyze the base_nodes for these types CommonReturnTypes = Union[ - Literal["IMAGE", "STRING", "INT", "FLOAT", "CONDITIONING", "LATENT", "MASK", "MODEL", "VAE", "CLIP"], str] + Literal["IMAGE", "STRING", "INT", "BOOLEAN", "FLOAT", "CONDITIONING", "LATENT", "MASK", "MODEL", "VAE", "CLIP"], str] IntSpec = Tuple[Literal["INT"], IntSpecOptions] @@ -96,7 +96,7 @@ class CustomNode(Protocol): def INPUT_TYPES(cls) -> InputTypes: ... # Optional method signature for VALIDATE_INPUTS - VALIDATE_INPUTS: ClassVar[ValidateInputsMethod] = None + VALIDATE_INPUTS: Optional[ClassVar[ValidateInputsMethod]] RETURN_TYPES: ClassVar[Tuple[CommonReturnTypes, ...]] RETURN_NAMES: Optional[ClassVar[Tuple[str, ...]]] @@ -106,9 +106,6 @@ class CustomNode(Protocol): CATEGORY: ClassVar[str] OUTPUT_NODE: Optional[ClassVar[bool]] - def __call__(self) -> T: - ... - @dataclass class ExportedNodes: