Update workflow-metadata.js

This commit is contained in:
huchenlei 2025-01-08 19:49:58 -05:00
parent de907718e2
commit 5b61c2cb9a

View File

@ -17,16 +17,18 @@ import { api } from "../../scripts/api.js";
class WorkflowMetadataExtension { class WorkflowMetadataExtension {
constructor() { constructor() {
this.name = "Comfy.CustomNodesManager.WorkflowMetadata"; this.name = "Comfy.CustomNodesManager.WorkflowMetadata";
this.installedNodeVersions = {}; this.installedNodes = {};
this.comfyCoreVersion = null; this.comfyCoreVersion = null;
} }
/** /**
* Get the installed node versions * Get the installed nodes info
* @returns {Promise<Record<string, string>>} The mapping from node name to version * @returns {Promise<Record<string, {ver: string, cnr_id: string, enabled: boolean}>>} The mapping from node name to its info.
* version can either be a git commit hash or a semantic version such as "1.0.0" * ver can either be a git commit hash or a semantic version such as "1.0.0"
* cnr_id is the id of the node in the ComfyRegistry
* enabled is true if the node is enabled, false if it is disabled
*/ */
async getInstalledNodeVersions() { async getInstalledNodes() {
const res = await api.fetchApi("/customnode/installed"); const res = await api.fetchApi("/customnode/installed");
return await res.json(); return await res.json();
} }
@ -48,8 +50,10 @@ class WorkflowMetadataExtension {
if (modules[0] === "custom_nodes") { if (modules[0] === "custom_nodes") {
const nodePackageName = modules[1]; const nodePackageName = modules[1];
const nodeVersion = this.installedNodeVersions[nodePackageName]; const nodeInfo =
nodeVersions[nodePackageName] = nodeVersion; this.installedNodes[nodePackageName] ??
this.installedNodes[nodePackageName.toLowerCase()];
nodeVersions[nodePackageName] = nodeInfo.ver;
} else if (["nodes", "comfy_extras"].includes(modules[0])) { } else if (["nodes", "comfy_extras"].includes(modules[0])) {
nodeVersions["comfy-core"] = this.comfyCoreVersion; nodeVersions["comfy-core"] = this.comfyCoreVersion;
} else { } else {
@ -61,7 +65,7 @@ class WorkflowMetadataExtension {
async init() { async init() {
const extension = this; const extension = this;
this.installedNodeVersions = await this.getInstalledNodeVersions(); this.installedNodes = await this.getInstalledNodes();
this.comfyCoreVersion = (await api.getSystemStats()).system.comfyui_version; this.comfyCoreVersion = (await api.getSystemStats()).system.comfyui_version;
// Attach metadata when app.graphToPrompt is called. // Attach metadata when app.graphToPrompt is called.