mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-26 06:10:15 +08:00
Improve typing and file path handling
This commit is contained in:
parent
e6623a1359
commit
44882eab0c
@ -29,12 +29,15 @@ def file_output_path(filename: str, type: Literal["input", "output", "temp"] = "
|
|||||||
output_dir = folder_paths.get_directory_by_type(type)
|
output_dir = folder_paths.get_directory_by_type(type)
|
||||||
if output_dir is None:
|
if output_dir is None:
|
||||||
raise ValueError(f"no such output directory because invalid type specified (type={type})")
|
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)
|
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")
|
raise PermissionError("insecure")
|
||||||
output_dir = full_output_dir
|
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)
|
file = os.path.join(output_dir, filename)
|
||||||
return file
|
return file
|
||||||
|
|||||||
@ -32,7 +32,7 @@ class StringSpecOptions(TypedDict, total=True):
|
|||||||
|
|
||||||
# todo: analyze the base_nodes for these types
|
# todo: analyze the base_nodes for these types
|
||||||
CommonReturnTypes = Union[
|
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]
|
IntSpec = Tuple[Literal["INT"], IntSpecOptions]
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ class CustomNode(Protocol):
|
|||||||
def INPUT_TYPES(cls) -> InputTypes: ...
|
def INPUT_TYPES(cls) -> InputTypes: ...
|
||||||
|
|
||||||
# Optional method signature for VALIDATE_INPUTS
|
# Optional method signature for VALIDATE_INPUTS
|
||||||
VALIDATE_INPUTS: ClassVar[ValidateInputsMethod] = None
|
VALIDATE_INPUTS: Optional[ClassVar[ValidateInputsMethod]]
|
||||||
|
|
||||||
RETURN_TYPES: ClassVar[Tuple[CommonReturnTypes, ...]]
|
RETURN_TYPES: ClassVar[Tuple[CommonReturnTypes, ...]]
|
||||||
RETURN_NAMES: Optional[ClassVar[Tuple[str, ...]]]
|
RETURN_NAMES: Optional[ClassVar[Tuple[str, ...]]]
|
||||||
@ -106,9 +106,6 @@ class CustomNode(Protocol):
|
|||||||
CATEGORY: ClassVar[str]
|
CATEGORY: ClassVar[str]
|
||||||
OUTPUT_NODE: Optional[ClassVar[bool]]
|
OUTPUT_NODE: Optional[ClassVar[bool]]
|
||||||
|
|
||||||
def __call__(self) -> T:
|
|
||||||
...
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ExportedNodes:
|
class ExportedNodes:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user