Add iteration suffix stripping node

This commit is contained in:
2026-08-05 11:08:10 +00:00
parent 52d006cade
commit 5b9886cd1c
3 changed files with 64 additions and 0 deletions
+35
View File
@@ -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",