Add iteration suffix stripping node
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from functools import lru_cache
|
||||
from itertools import islice
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def _clone_container(value):
|
||||
@@ -243,6 +244,21 @@ def _resolve_iteration_index(index, mode, total_items):
|
||||
return max(0, min(index, total_items - 1))
|
||||
|
||||
|
||||
def _strip_iteration_suffix(value):
|
||||
if not isinstance(value, str):
|
||||
return ""
|
||||
|
||||
root, extension = os.path.splitext(value)
|
||||
if "_" not in root:
|
||||
return value
|
||||
|
||||
prefix, suffix = root.rsplit("_", 1)
|
||||
if not suffix.isdigit():
|
||||
return value
|
||||
|
||||
return f"{prefix}{extension}"
|
||||
|
||||
|
||||
class DumasJSONStringToObjectNode:
|
||||
CATEGORY = "Dumas/JSON"
|
||||
RETURN_TYPES = ("JSON",)
|
||||
@@ -265,6 +281,23 @@ class DumasJSONStringToObjectNode:
|
||||
return (None,)
|
||||
|
||||
|
||||
class DumasStripIterationSuffixNode:
|
||||
CATEGORY = "Dumas/String"
|
||||
RETURN_TYPES = ("STRING",)
|
||||
FUNCTION = "strip_iteration_suffix"
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"filename": ("STRING", {"default": "", "multiline": False}),
|
||||
}
|
||||
}
|
||||
|
||||
def strip_iteration_suffix(self, filename):
|
||||
return (_strip_iteration_suffix(filename),)
|
||||
|
||||
|
||||
class DumasJSONObjectToStringNode:
|
||||
CATEGORY = "Dumas/JSON"
|
||||
RETURN_TYPES = ("STRING",)
|
||||
@@ -596,6 +629,7 @@ class DumasJSONUnflattenNode:
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"DumasJSONStringToObject": DumasJSONStringToObjectNode,
|
||||
"DumasStripIterationSuffix": DumasStripIterationSuffixNode,
|
||||
"DumasJSONObjectToString": DumasJSONObjectToStringNode,
|
||||
"DumasJSONGetValue": DumasJSONGetValueNode,
|
||||
"DumasJSONSetValue": DumasJSONSetValueNode,
|
||||
@@ -615,6 +649,7 @@ NODE_CLASS_MAPPINGS = {
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"DumasJSONStringToObject": "Dumas JSON String to Object",
|
||||
"DumasStripIterationSuffix": "Dumas Strip Iteration Suffix",
|
||||
"DumasJSONObjectToString": "Dumas JSON Object to String",
|
||||
"DumasJSONGetValue": "Dumas JSON Get Value",
|
||||
"DumasJSONSetValue": "Dumas JSON Set Value",
|
||||
|
||||
Reference in New Issue
Block a user