diff --git a/js/metahub_save_cta.js b/js/metahub_save_cta.js index 1143ca6..11b7ba8 100644 --- a/js/metahub_save_cta.js +++ b/js/metahub_save_cta.js @@ -25,11 +25,27 @@ function openUrl(url) { } function getSavedPaths(message) { - const files = message?.imagemetahub?.files; - if (!Array.isArray(files)) { - return []; + const candidates = [ + message?.imagemetahub?.files, + message?.ui?.imagemetahub?.files, + ]; + + for (const files of candidates) { + if (Array.isArray(files)) { + return files.filter( + (filePath) => typeof filePath === "string" && filePath.trim() + ); + } + } + + return []; +} + +function captureLastSavedPath(node, message) { + const savedPaths = getSavedPaths(message); + if (savedPaths.length > 0) { + node.__imageMetaHubLastSavedPath = savedPaths[savedPaths.length - 1]; } - return files.filter((filePath) => typeof filePath === "string" && filePath.trim()); } function addMetaHubCTA(node) { @@ -42,14 +58,6 @@ function addMetaHubCTA(node) { } node.__imageMetaHubCTAAdded = true; - const originalOnExecuted = node.onExecuted; - node.onExecuted = function (message) { - originalOnExecuted?.apply(this, arguments); - const savedPaths = getSavedPaths(message); - if (savedPaths.length > 0) { - this.__imageMetaHubLastSavedPath = savedPaths[savedPaths.length - 1]; - } - }; node.addWidget( "button", @@ -75,6 +83,18 @@ function addMetaHubCTA(node) { app.registerExtension({ name: "ImageMetaHub.SaveNodeCTA", + async beforeRegisterNodeDef(nodeType, nodeData) { + if (!METAHUB_SAVE_NODE_CLASSES.has(nodeData.name)) { + return; + } + + const originalOnExecuted = nodeType.prototype.onExecuted; + nodeType.prototype.onExecuted = function (message) { + originalOnExecuted?.apply(this, arguments); + captureLastSavedPath(this, message); + }; + }, + async nodeCreated(node) { addMetaHubCTA(node); }, diff --git a/metadata_utils.py b/metadata_utils.py index 82d52d1..b3f3e28 100644 --- a/metadata_utils.py +++ b/metadata_utils.py @@ -3,7 +3,7 @@ Compatibility shim for MetaHub Save Node metadata helpers. The implementation is kept in metadata_utils_impl.py; this module exposes the same public API expected by the save nodes while pinning the published node -version to 1.1.5. +version to 1.1.6. """ try: @@ -11,7 +11,7 @@ try: except ImportError: import metadata_utils_impl as _impl -METAHUB_SAVE_NODE_VERSION = "1.1.5" +METAHUB_SAVE_NODE_VERSION = "1.1.6" _impl.METAHUB_SAVE_NODE_VERSION = METAHUB_SAVE_NODE_VERSION for _name in dir(_impl): diff --git a/metadata_utils_impl.py b/metadata_utils_impl.py index a568806..f833a81 100644 --- a/metadata_utils_impl.py +++ b/metadata_utils_impl.py @@ -14,7 +14,7 @@ from xml.sax.saxutils import escape as xml_escape import numpy as np from PIL import Image, PngImagePlugin -METAHUB_SAVE_NODE_VERSION = "1.1.5" +METAHUB_SAVE_NODE_VERSION = "1.1.6" try: import piexif diff --git a/pyproject.toml b/pyproject.toml index 18483fa..fa07e3f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "imagemetahub-comfyui-save" description = "Official companion node for Image MetaHub. Saves A1111/Civitai-compatible parameters plus extended Image MetaHub metadata (workflow JSON, SHA256 model hashes, VRAM peak/total, GPU device, generation time, and steps/sec) for reproducibility and benchmarking." -version = "1.1.5" +version = "1.1.6" license = {file = "LICENSE"} # classifiers = [ # # For OS-independent nodes (works on all operating systems) diff --git a/tests/test_metadata_utils.py b/tests/test_metadata_utils.py index 681da65..d3d6964 100644 --- a/tests/test_metadata_utils.py +++ b/tests/test_metadata_utils.py @@ -334,7 +334,7 @@ def test_extract_workflow_attribution_from_node_properties(): assert attribution["token"] == "imhcrt_br_creator_workflow_v1_random" assert attribution["source"] == "metahub_save_node" - assert attribution["node_version"] == "1.1.5" + assert attribution["node_version"] == "1.1.6" def test_build_imh_metadata_includes_attribution_without_a1111_parameters():