Compare commits

...

77 Commits

Author SHA1 Message Date
huchenlei
0ae2b7f338 nit 2024-12-19 15:39:24 -08:00
huchenlei
c2ac84c3d3 nit 2024-12-19 15:35:11 -08:00
huchenlei
fd29dc5133 Add extension to attach node versions 2024-12-19 15:29:56 -08:00
Chenlei Hu
aab45dff44 Merge pull request #1352 from huchenlei/fix_installed_module_name
Use module name without @Version in /customnode/installed object key
2024-12-19 15:25:56 -08:00
huchenlei
6fee2b8b10 Use module name without @version in /customnode/installed object key 2024-12-19 15:22:50 -08:00
Dr.Lt.Data
9b5adfeb2c feat: endpoint customnode/installed is added 2024-12-19 18:13:10 +09:00
Dr.Lt.Data
95ee037a44 refactor: print -> logging. 2024-12-19 15:50:23 +09:00
Dr.Lt.Data
3ecf3a359d Merge branch 'main' into feat/cnr 2024-12-19 15:35:11 +09:00
Dr.Lt.Data
31de8ffc3d implement: support --user-directory 2024-12-19 15:27:31 +09:00
Dr.Lt.Data
602d04e236 fix: prestartup - import error 2024-12-19 11:33:58 +09:00
Dr.Lt.Data
a44d1fbd37 fix: mismatches caused by manager-core integration 2024-12-19 09:29:30 +09:00
Dr.Lt.Data
e4bb21f25c fix: import error - cnr_utils.extract_package_as_zip 2024-12-19 08:20:39 +09:00
Dr.Lt.Data
87d447f7b5 apply manager-core modifications
- custom custom_nodes dir
2024-12-18 16:21:35 +09:00
Dr.Lt.Data
e2e1e23ab5 modified: Change the default from CNR to nightly
fixed: broken CNR installation
2024-12-18 15:00:23 +09:00
Dr.Lt.Data
46a6afcc19 refactor: ruff 2024-12-18 12:30:47 +09:00
Dr.Lt.Data
222254896c Merge branch 'main' into feat/cnr 2024-12-18 12:00:16 +09:00
Dr.Lt.Data
b8f153e4eb Merge branch 'main' into feat/cnr 2024-12-18 09:08:15 +09:00
Dr.Lt.Data
5f300b8aea Merge branch 'main' into feat/cnr 2024-11-22 07:27:27 +09:00
Dr.Lt.Data
093097cf31 Merge branch 'main' into feat/cnr 2024-11-17 15:39:49 +09:00
Dr.Lt.Data
eb5b512c34 Merge branch 'main' into feat/cnr 2024-11-14 02:26:53 +09:00
Dr.Lt.Data
1bd64e97cc Merge branch 'main' into feat/cnr 2024-11-11 16:51:56 +09:00
Dr.Lt.Data
b703384f6b Merge branch 'main' into feat/cnr 2024-11-11 13:42:13 +09:00
Dr.Lt.Data
d968c55e48 Merge branch 'main' into feat/cnr 2024-11-05 19:52:17 +09:00
Dr.Lt.Data
bc4126f526 Merge branch 'main' into feat/cnr 2024-10-30 03:49:32 +09:00
Dr.Lt.Data
41d4ba9721 Merge branch 'main' into feat/cnr 2024-10-20 14:07:08 +09:00
Dr.Lt.Data
5e5e567181 Merge branch 'main' into feat/cnr 2024-10-16 08:36:21 +09:00
Dr.Lt.Data
a6eaba7e18 Merge branch 'main' into feat/cnr 2024-10-15 23:36:42 +09:00
Dr.Lt.Data
f8221b9b5d Merge branch 'main' into feat/cnr 2024-10-13 17:06:19 +09:00
Dr.Lt.Data
f4442972bc Merge branch 'main' into feat/cnr 2024-10-08 19:47:38 +09:00
Dr.Lt.Data
aa4b3d81ba Merge branch 'main' into feat/cnr 2024-10-05 15:35:48 +09:00
Dr.Lt.Data
cbb6432803 Merge branch 'main' into feat/cnr 2024-09-29 17:18:47 +09:00
Dr.Lt.Data
14afc8d998 Merge branch 'main' into feat/cnr 2024-09-26 09:51:01 +09:00
Dr.Lt.Data
e83e15b9fc Merge branch 'main' into feat/cnr 2024-09-26 08:57:29 +09:00
Dr.Lt.Data
76db17c7f8 Merge branch 'main' into feat/cnr 2024-09-24 09:03:32 +09:00
Dr.Lt.Data
d48c936770 Merge branch 'main' into feat/cnr 2024-09-24 02:07:19 +09:00
Dr.Lt.Data
527c994d43 Merge branch 'main' into feat/cnr 2024-09-23 01:18:25 +09:00
Dr.Lt.Data
800faf96d4 Merge branch 'main' into feat/cnr 2024-09-21 01:38:51 +09:00
Dr.Lt.Data
2c3a11012f Merge branch 'main' into feat/cnr 2024-09-19 02:45:39 +09:00
Dr.Lt.Data
95311cb225 Merge branch 'main' into feat/cnr 2024-09-19 01:57:15 +09:00
Dr.Lt.Data
70471b54f6 hotfix: updating cnr node - invalid garbage handling 2024-09-18 01:21:32 +09:00
Dr.Lt.Data
f0205c8eba Merge branch 'main' into feat/cnr 2024-09-17 23:30:36 +09:00
Dr.Lt.Data
1a5fa290a3 Merge branch 'main' into feat/cnr 2024-09-13 01:46:04 +09:00
Dr.Lt.Data
4fc50d5019 Merge branch 'main' into feat/cnr 2024-09-11 00:08:36 +09:00
Dr.Lt.Data
a1c90ceb52 modify: close button -> back button 2024-09-08 16:51:41 +09:00
Dr.Lt.Data
ecda9bd34e add favorites button 2024-09-08 16:42:36 +09:00
Dr.Lt.Data
a952009d4a modified: remove uninstall/switch/disable button for ComfyUI-Manager in the list
feat: support favorites list
2024-09-08 15:53:54 +09:00
Dr.Lt.Data
6f2e1345b2 Merge branch 'main' into feat/cnr 2024-09-08 13:48:35 +09:00
Dr.Lt.Data
7b93c831de Merge branch 'main' into feat/cnr 2024-09-05 22:18:56 +09:00
Dr.Lt.Data
80e1fcd672 Merge branch 'main' into feat/cnr 2024-09-01 15:49:03 +09:00
Dr.Lt.Data
bff8dbee30 Merge branch 'main' into feat/cnr 2024-08-29 21:53:37 +09:00
Dr.Lt.Data
32c828670a fix: update_all - nightly version issue 2024-08-29 21:27:10 +09:00
Dr.Lt.Data
ad1faee2ef fix: snapshot 2024-08-28 02:09:00 +09:00
Dr.Lt.Data
005fa14254 fix: execute_install_script - missing pip install except first pip item in requirements.txt 2024-08-24 18:40:25 +09:00
Dr.Lt.Data
7b60b69968 Merge branch 'main' into feat/cnr 2024-08-24 17:20:59 +09:00
Dr.Lt.Data
ed123750d9 postponed processing for cnr switch & migration 2024-08-22 03:38:22 +09:00
Dr.Lt.Data
bede95cd05 improve: better comfyui switch
show 'nightly' if current commit is latest commit.
2024-08-22 02:10:04 +09:00
Dr.Lt.Data
693a226a41 improve: comfyui version switch
top 4 + nightly
2024-08-22 02:08:23 +09:00
Dr.Lt.Data
7ec2793c9a Merge branch 'main' into feat/cnr 2024-08-22 01:47:55 +09:00
Dr.Lt.Data
a1f7f7069f comfyui version switch 2024-08-21 01:33:55 +09:00
Dr.Lt.Data
f74d8cb470 print stash message.
https://github.com/ltdrdata/ComfyUI-Manager/issues/976#issuecomment-2295670323
2024-08-21 00:45:04 +09:00
Dr.Lt.Data
b02cb2b833 Merge branch 'main' into feat/cnr 2024-08-18 13:02:39 +09:00
Dr.Lt.Data
243b65961f unknown fix 2024-08-17 16:55:23 +09:00
Dr.Lt.Data
a6d20b0865 Merge branch 'main' into feat/cnr 2024-08-17 16:35:22 +09:00
Dr.Lt.Data
06b79287e2 Merge branch 'main' into feat/cnr 2024-08-16 00:10:02 +09:00
Dr.Lt.Data
e906d27606 fix: nightly url mismatch if ssh github url is used
fix: don't show pure cnr node unless default channel
2024-08-15 23:44:12 +09:00
Dr.Lt.Data
0968dd85aa fix: undefined show_message
fix: invalid disable for nightly
2024-08-15 22:45:37 +09:00
Dr.Lt.Data
75240a028a Merge branch 'main' into feat/cnr 2024-08-14 02:02:33 +09:00
Dr.Lt.Data
3335c82350 Merge branch 'main' into feat/cnr 2024-08-08 22:52:07 +09:00
Dr.Lt.Data
e16e72cbbd feat: config.ini - skip_migration_check is supported. 2024-08-04 22:39:13 +09:00
Dr.Lt.Data
0b6f7962a4 fix: should not be displayed switch button if unknown node 2024-08-04 16:34:40 +09:00
Dr.Lt.Data
ea3413be9b conservative migration system
keep original repo name as possible if unknown node
2024-08-04 16:26:23 +09:00
Dr.Lt.Data
10055f578b Merge branch 'main' into feat/cnr 2024-08-04 16:03:25 +09:00
Dr.Lt.Data
cddd000848 Merge branch 'main' into feat/cnr 2024-08-02 03:25:30 +09:00
Dr.Lt.Data
cdb400d32b implement: invalid installation handling
- print invalid installation nodes on terminal
(installed by `comfy registryinstall`)

- show only 'reinstall' menu if invalid installation node in gui
(and show INVALID marker)
2024-07-31 02:08:30 +09:00
Dr.Lt.Data
8e1f792cd1 fix: crash by version handling 2024-07-27 22:08:19 +09:00
Max Klein
f0299e07f9 added support for --no-deps option to node install and reinstall (#886)
* added support for `--no-deps` option to node install and reinstall

* post rebase fixup

* fixup help msg for --no-deps option
2024-07-27 01:52:07 +09:00
Dr.Lt.Data
b3be556837 support CNR 2024-07-25 00:24:58 +09:00
20 changed files with 4315 additions and 1276 deletions

2
.gitignore vendored
View File

@@ -1,6 +1,8 @@
__pycache__/ __pycache__/
.idea/ .idea/
.vscode/ .vscode/
.history/
*.code-workspace
.tmp .tmp
.cache .cache
config.ini config.ini

View File

@@ -320,6 +320,9 @@ NODE_CLASS_MAPPINGS.update({
* Use `aria2` as downloader * Use `aria2` as downloader
* [howto](docs/en/use_aria2.md) * [howto](docs/en/use_aria2.md)
* If you add the item `skip_migration_check = True` to `config.ini`, it will not check whether there are nodes that can be migrated at startup.
* This option can be used if performance issues occur in a Colab+GDrive environment.
## Scanner ## Scanner
When you run the `scan.sh` script: When you run the `scan.sh` script:

View File

@@ -9,6 +9,7 @@ files=(
"alter-list.json" "alter-list.json"
"extension-node-map.json" "extension-node-map.json"
"github-stats.json" "github-stats.json"
"extras.json"
"node_db/new/custom-node-list.json" "node_db/new/custom-node-list.json"
"node_db/new/model-list.json" "node_db/new/model-list.json"
"node_db/new/extension-node-map.json" "node_db/new/extension-node-map.json"

837
cm-cli.py
View File

File diff suppressed because it is too large Load Diff

2
cm-cli.sh Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
python cm-cli.py $*

25
extras.json Normal file
View File

@@ -0,0 +1,25 @@
{
"favorites": [
"comfyui_ipadapter_plus",
"comfyui-animatediff-evolved",
"comfyui_controlnet_aux",
"comfyui-impact-pack",
"comfyui-custom-scripts",
"comfyui-layerdiffuse",
"comfyui-liveportraitkj",
"aigodlike-comfyui-translation",
"comfyui-reactor-node",
"comfyui_instantid",
"sd-dynamic-thresholding",
"pr-was-node-suite-comfyui-47064894",
"comfyui-advancedliveportrait",
"comfyui_layerstyle",
"efficiency-nodes-comfyui",
"comfyui-crystools",
"comfyui-advanced-controlnet",
"comfyui-videohelpersuite",
"comfyui-kjnodes",
"comfy-mtb",
"comfyui_essentials"
]
}

View File

@@ -5,7 +5,6 @@ import traceback
import git import git
import configparser import configparser
import re
import json import json
import yaml import yaml
import requests import requests
@@ -13,6 +12,14 @@ from tqdm.auto import tqdm
from git.remote import RemoteProgress from git.remote import RemoteProgress
comfy_path = os.environ.get('COMFYUI_PATH')
if comfy_path is None:
print("\n[bold yellow]WARN: The `COMFYUI_PATH` environment variable is not set. Assuming `custom_nodes/ComfyUI-Manager/../../` as the ComfyUI path.[/bold yellow]", file=sys.stderr)
comfy_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
def download_url(url, dest_folder, filename=None): def download_url(url, dest_folder, filename=None):
# Ensure the destination folder exists # Ensure the destination folder exists
if not os.path.exists(dest_folder): if not os.path.exists(dest_folder):
@@ -59,8 +66,10 @@ class GitProgress(RemoteProgress):
self.pbar.refresh() self.pbar.refresh()
def gitclone(custom_nodes_path, url, target_hash=None): def gitclone(custom_nodes_path, url, target_hash=None, repo_path=None):
repo_name = os.path.splitext(os.path.basename(url))[0] repo_name = os.path.splitext(os.path.basename(url))[0]
if repo_path is None:
repo_path = os.path.join(custom_nodes_path, repo_name) repo_path = os.path.join(custom_nodes_path, repo_name)
# Clone the repository from the remote URL # Clone the repository from the remote URL
@@ -94,7 +103,12 @@ def gitcheck(path, do_fetch=False):
# Get the current commit hash and the commit hash of the remote branch # Get the current commit hash and the commit hash of the remote branch
commit_hash = repo.head.commit.hexsha commit_hash = repo.head.commit.hexsha
if f'{remote_name}/{branch_name}' in repo.refs:
remote_commit_hash = repo.refs[f'{remote_name}/{branch_name}'].object.hexsha remote_commit_hash = repo.refs[f'{remote_name}/{branch_name}'].object.hexsha
else:
print("CUSTOM NODE CHECK: True") # non default branch is treated as updatable
return
# Compare the commit hashes to determine if the local repository is behind the remote repository # Compare the commit hashes to determine if the local repository is behind the remote repository
if commit_hash != remote_commit_hash: if commit_hash != remote_commit_hash:
@@ -113,10 +127,7 @@ def gitcheck(path, do_fetch=False):
def switch_to_default_branch(repo): def switch_to_default_branch(repo):
show_result = repo.git.remote("show", "origin") default_branch = repo.git.symbolic_ref('refs/remotes/origin/HEAD').replace('refs/remotes/origin/', '')
matches = re.search(r"\s*HEAD branch:\s*(.*)", show_result)
if matches:
default_branch = matches.group(1)
repo.git.checkout(default_branch) repo.git.checkout(default_branch)
@@ -128,6 +139,7 @@ def gitpull(path):
# Pull the latest changes from the remote repository # Pull the latest changes from the remote repository
repo = git.Repo(path) repo = git.Repo(path)
if repo.is_dirty(): if repo.is_dirty():
print(f"STASH: '{path}' is dirty.")
repo.git.stash() repo.git.stash()
commit_hash = repo.head.commit.hexsha commit_hash = repo.head.commit.hexsha
@@ -141,6 +153,11 @@ def gitpull(path):
remote_name = current_branch.tracking_branch().remote_name remote_name = current_branch.tracking_branch().remote_name
remote = repo.remote(name=remote_name) remote = repo.remote(name=remote_name)
if f'{remote_name}/{branch_name}' not in repo.refs:
switch_to_default_branch(repo)
current_branch = repo.active_branch
branch_name = current_branch.name
remote.fetch() remote.fetch()
remote_commit_hash = repo.refs[f'{remote_name}/{branch_name}'].object.hexsha remote_commit_hash = repo.refs[f'{remote_name}/{branch_name}'].object.hexsha
@@ -166,9 +183,7 @@ def gitpull(path):
def checkout_comfyui_hash(target_hash): def checkout_comfyui_hash(target_hash):
repo_path = os.path.abspath(os.path.join(working_directory, '..')) # ComfyUI dir repo = git.Repo(comfy_path)
repo = git.Repo(repo_path)
commit_hash = repo.head.commit.hexsha commit_hash = repo.head.commit.hexsha
if commit_hash != target_hash: if commit_hash != target_hash:
@@ -191,7 +206,7 @@ def checkout_custom_node_hash(git_custom_node_infos):
repo_name_to_url[repo_name] = url repo_name_to_url[repo_name] = url
for path in os.listdir(working_directory): for path in os.listdir(working_directory):
if path.endswith("ComfyUI-Manager"): if '@' in path or path.endswith("ComfyUI-Manager"):
continue continue
fullpath = os.path.join(working_directory, path) fullpath = os.path.join(working_directory, path)
@@ -250,6 +265,9 @@ def checkout_custom_node_hash(git_custom_node_infos):
# clone missing # clone missing
for k, v in git_custom_node_infos.items(): for k, v in git_custom_node_infos.items():
if 'ComfyUI-Manager' in k:
continue
if not v['disabled']: if not v['disabled']:
repo_name = k.split('/')[-1] repo_name = k.split('/')[-1]
if repo_name.endswith('.git'): if repo_name.endswith('.git'):
@@ -258,7 +276,7 @@ def checkout_custom_node_hash(git_custom_node_infos):
path = os.path.join(working_directory, repo_name) path = os.path.join(working_directory, repo_name)
if not os.path.exists(path): if not os.path.exists(path):
print(f"CLONE: {path}") print(f"CLONE: {path}")
gitclone(working_directory, k, v['hash']) gitclone(working_directory, k, target_hash=v['hash'])
def invalidate_custom_node_file(file_custom_node_infos): def invalidate_custom_node_file(file_custom_node_infos):
@@ -308,19 +326,18 @@ def invalidate_custom_node_file(file_custom_node_infos):
download_url(url, working_directory) download_url(url, working_directory)
def apply_snapshot(target): def apply_snapshot(path):
try: try:
path = os.path.join(os.path.dirname(__file__), 'snapshots', f"{target}")
if os.path.exists(path): if os.path.exists(path):
if not target.endswith('.json') and not target.endswith('.yaml'): if not path.endswith('.json') and not path.endswith('.yaml'):
print(f"Snapshot file not found: `{path}`") print(f"Snapshot file not found: `{path}`")
print("APPLY SNAPSHOT: False") print("APPLY SNAPSHOT: False")
return None return None
with open(path, 'r', encoding="UTF-8") as snapshot_file: with open(path, 'r', encoding="UTF-8") as snapshot_file:
if target.endswith('.json'): if path.endswith('.json'):
info = json.load(snapshot_file) info = json.load(snapshot_file)
elif target.endswith('.yaml'): elif path.endswith('.yaml'):
info = yaml.load(snapshot_file, Loader=yaml.SafeLoader) info = yaml.load(snapshot_file, Loader=yaml.SafeLoader)
info = info['custom_nodes'] info = info['custom_nodes']
else: else:
@@ -425,7 +442,11 @@ setup_environment()
try: try:
if sys.argv[1] == "--clone": if sys.argv[1] == "--clone":
gitclone(sys.argv[2], sys.argv[3]) repo_path = None
if len(sys.argv) > 4:
repo_path = sys.argv[4]
gitclone(sys.argv[2], sys.argv[3], repo_path=repo_path)
elif sys.argv[1] == "--check": elif sys.argv[1] == "--check":
gitcheck(sys.argv[2], False) gitcheck(sys.argv[2], False)
elif sys.argv[1] == "--fetch": elif sys.argv[1] == "--fetch":

100
glob/cnr_utils.py Normal file
View File

@@ -0,0 +1,100 @@
import requests
from dataclasses import dataclass
from typing import List
import manager_util
base_url = "https://api.comfy.org"
async def get_cnr_data(page=1, limit=1000, cache_mode=True):
try:
uri = f'{base_url}/nodes?page={page}&limit={limit}'
json_obj = await manager_util.get_data_with_cache(uri, cache_mode=cache_mode)
for v in json_obj['nodes']:
if 'latest_version' not in v:
v['latest_version'] = dict(version='nightly')
return json_obj['nodes']
except:
res = {}
print("Cannot connect to comfyregistry.")
return res
@dataclass
class NodeVersion:
changelog: str
dependencies: List[str]
deprecated: bool
id: str
version: str
download_url: str
def map_node_version(api_node_version):
"""
Maps node version data from API response to NodeVersion dataclass.
Args:
api_data (dict): The 'node_version' part of the API response.
Returns:
NodeVersion: An instance of NodeVersion dataclass populated with data from the API.
"""
return NodeVersion(
changelog=api_node_version.get(
"changelog", ""
), # Provide a default value if 'changelog' is missing
dependencies=api_node_version.get(
"dependencies", []
), # Provide a default empty list if 'dependencies' is missing
deprecated=api_node_version.get(
"deprecated", False
), # Assume False if 'deprecated' is not specified
id=api_node_version[
"id"
], # 'id' should be mandatory; raise KeyError if missing
version=api_node_version[
"version"
], # 'version' should be mandatory; raise KeyError if missing
download_url=api_node_version.get(
"downloadUrl", ""
), # Provide a default value if 'downloadUrl' is missing
)
def install_node(node_id, version=None):
"""
Retrieves the node version for installation.
Args:
node_id (str): The unique identifier of the node.
version (str, optional): Specific version of the node to retrieve. If omitted, the latest version is returned.
Returns:
NodeVersion: Node version data or error message.
"""
if version is None:
url = f"{base_url}/nodes/{node_id}/install"
else:
url = f"{base_url}/nodes/{node_id}/install?version={version}"
response = requests.get(url)
if response.status_code == 200:
# Convert the API response to a NodeVersion object
return map_node_version(response.json())
else:
return None
def all_versions_of_node(node_id):
url = f"https://api.comfy.org/nodes/{node_id}/versions"
response = requests.get(url)
if response.status_code == 200:
return response.json()
else:
return None

View File

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,7 @@
import os import os
from urllib.parse import urlparse from urllib.parse import urlparse
import urllib
import sys
aria2 = os.getenv('COMFYUI_MANAGER_ARIA2_SERVER') aria2 = os.getenv('COMFYUI_MANAGER_ARIA2_SERVER')
HF_ENDPOINT = os.getenv('HF_ENDPOINT') HF_ENDPOINT = os.getenv('HF_ENDPOINT')
@@ -14,12 +16,32 @@ if aria2 is not None:
aria2 = aria2p.API(aria2p.Client(host=host, port=port, secret=secret)) aria2 = aria2p.API(aria2p.Client(host=host, port=port, secret=secret))
def basic_download_url(url, dest_folder, filename):
import requests
# Ensure the destination folder exists
if not os.path.exists(dest_folder):
os.makedirs(dest_folder)
# Full path to save the file
dest_path = os.path.join(dest_folder, filename)
# Download the file
response = requests.get(url, stream=True)
if response.status_code == 200:
with open(dest_path, 'wb') as file:
for chunk in response.iter_content(chunk_size=1024):
if chunk:
file.write(chunk)
else:
raise Exception(f"Failed to download file from {url}")
def download_url(model_url: str, model_dir: str, filename: str): def download_url(model_url: str, model_dir: str, filename: str):
if aria2: if aria2:
return aria2_download_url(model_url, model_dir, filename) return aria2_download_url(model_url, model_dir, filename)
else: else:
from torchvision.datasets.utils import download_url as torchvision_download_url from torchvision.datasets.utils import download_url as torchvision_download_url
return torchvision_download_url(model_url, model_dir, filename) return torchvision_download_url(model_url, model_dir, filename)
@@ -68,3 +90,26 @@ def aria2_download_url(model_url: str, model_dir: str, filename: str):
progress_bar.update(download.completed_length - progress_bar.n) progress_bar.update(download.completed_length - progress_bar.n)
time.sleep(1) time.sleep(1)
download.update() download.update()
def download_url_with_agent(url, save_path):
try:
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
req = urllib.request.Request(url, headers=headers)
response = urllib.request.urlopen(req)
data = response.read()
if not os.path.exists(os.path.dirname(save_path)):
os.makedirs(os.path.dirname(save_path))
with open(save_path, 'wb') as f:
f.write(data)
except Exception as e:
print(f"Download error: {url} / {e}", file=sys.stderr)
return False
print("Installation was successful.")
return True

View File

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,17 @@
import aiohttp
import json
import threading
import os
from datetime import datetime
import subprocess import subprocess
import sys import sys
import re
cache_lock = threading.Lock()
comfyui_manager_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
cache_dir = os.path.join(comfyui_manager_path, '.cache')
# DON'T USE StrictVersion - cannot handle pre_release version # DON'T USE StrictVersion - cannot handle pre_release version
# try: # try:
@@ -66,8 +78,84 @@ class StrictVersion:
return not self == other return not self == other
def simple_hash(input_string):
hash_value = 0
for char in input_string:
hash_value = (hash_value * 31 + ord(char)) % (2**32)
return hash_value
def is_file_created_within_one_day(file_path):
if not os.path.exists(file_path):
return False
file_creation_time = os.path.getctime(file_path)
current_time = datetime.now().timestamp()
time_difference = current_time - file_creation_time
return time_difference <= 86400
async def get_data(uri, silent=False):
if not silent:
print(f"FETCH DATA from: {uri}", end="")
if uri.startswith("http"):
async with aiohttp.ClientSession(trust_env=True, connector=aiohttp.TCPConnector(verify_ssl=False)) as session:
async with session.get(uri) as resp:
json_text = await resp.text()
else:
with cache_lock:
with open(uri, "r", encoding="utf-8") as f:
json_text = f.read()
json_obj = json.loads(json_text)
if not silent:
print(" [DONE]")
return json_obj
async def get_data_with_cache(uri, silent=False, cache_mode=True):
cache_uri = str(simple_hash(uri)) + '_' + os.path.basename(uri).replace('&', "_").replace('?', "_").replace('=', "_")
cache_uri = os.path.join(cache_dir, cache_uri+'.json')
if cache_mode and is_file_created_within_one_day(cache_uri):
json_obj = await get_data(cache_uri, silent=silent)
else:
json_obj = await get_data(uri, silent=silent)
with cache_lock:
with open(cache_uri, "w", encoding='utf-8') as file:
json.dump(json_obj, file, indent=4, sort_keys=True)
if not silent:
print(f"[ComfyUI-Manager] default cache updated: {uri}")
return json_obj
def sanitize_tag(x):
return x.replace('<', '&lt;').replace('>', '&gt;')
def extract_package_as_zip(file_path, extract_path):
import zipfile
try:
with zipfile.ZipFile(file_path, "r") as zip_ref:
zip_ref.extractall(extract_path)
extracted_files = zip_ref.namelist()
print(f"Extracted zip file to {extract_path}")
return extracted_files
except zipfile.BadZipFile:
print(f"File '{file_path}' is not a zip or is corrupted.")
return None
pip_map = None pip_map = None
def get_installed_packages(renew=False): def get_installed_packages(renew=False):
global pip_map global pip_map
@@ -212,3 +300,12 @@ class PIPFixer:
except Exception as e: except Exception as e:
print("[manager-core] Failed to restore numpy") print("[manager-core] Failed to restore numpy")
print(e) print(e)
def sanitize(data):
return data.replace("<", "&lt;").replace(">", "&gt;")
def sanitize_filename(input_string):
result_string = re.sub(r'[^a-zA-Z0-9_]', '_', input_string)
return result_string

View File

@@ -65,10 +65,10 @@ async def share_option(request):
def get_openart_auth(): def get_openart_auth():
if not os.path.exists(os.path.join(core.comfyui_manager_path, ".openart_key")): if not os.path.exists(os.path.join(core.manager_files_path, ".openart_key")):
return None return None
try: try:
with open(os.path.join(core.comfyui_manager_path, ".openart_key"), "r") as f: with open(os.path.join(core.manager_files_path, ".openart_key"), "r") as f:
openart_key = f.read().strip() openart_key = f.read().strip()
return openart_key if openart_key else None return openart_key if openart_key else None
except: except:
@@ -76,10 +76,10 @@ def get_openart_auth():
def get_matrix_auth(): def get_matrix_auth():
if not os.path.exists(os.path.join(core.comfyui_manager_path, "matrix_auth")): if not os.path.exists(os.path.join(core.manager_files_path, "matrix_auth")):
return None return None
try: try:
with open(os.path.join(core.comfyui_manager_path, "matrix_auth"), "r") as f: with open(os.path.join(core.manager_files_path, "matrix_auth"), "r") as f:
matrix_auth = f.read() matrix_auth = f.read()
homeserver, username, password = matrix_auth.strip().split("\n") homeserver, username, password = matrix_auth.strip().split("\n")
if not homeserver or not username or not password: if not homeserver or not username or not password:
@@ -94,10 +94,10 @@ def get_matrix_auth():
def get_comfyworkflows_auth(): def get_comfyworkflows_auth():
if not os.path.exists(os.path.join(core.comfyui_manager_path, "comfyworkflows_sharekey")): if not os.path.exists(os.path.join(core.manager_files_path, "comfyworkflows_sharekey")):
return None return None
try: try:
with open(os.path.join(core.comfyui_manager_path, "comfyworkflows_sharekey"), "r") as f: with open(os.path.join(core.manager_files_path, "comfyworkflows_sharekey"), "r") as f:
share_key = f.read() share_key = f.read()
if not share_key.strip(): if not share_key.strip():
return None return None
@@ -107,10 +107,10 @@ def get_comfyworkflows_auth():
def get_youml_settings(): def get_youml_settings():
if not os.path.exists(os.path.join(core.comfyui_manager_path, ".youml")): if not os.path.exists(os.path.join(core.manager_files_path, ".youml")):
return None return None
try: try:
with open(os.path.join(core.comfyui_manager_path, ".youml"), "r") as f: with open(os.path.join(core.manager_files_path, ".youml"), "r") as f:
youml_settings = f.read().strip() youml_settings = f.read().strip()
return youml_settings if youml_settings else None return youml_settings if youml_settings else None
except: except:
@@ -118,7 +118,7 @@ def get_youml_settings():
def set_youml_settings(settings): def set_youml_settings(settings):
with open(os.path.join(core.comfyui_manager_path, ".youml"), "w") as f: with open(os.path.join(core.manager_files_path, ".youml"), "w") as f:
f.write(settings) f.write(settings)
@@ -135,7 +135,7 @@ async def api_get_openart_auth(request):
async def api_set_openart_auth(request): async def api_set_openart_auth(request):
json_data = await request.json() json_data = await request.json()
openart_key = json_data['openart_key'] openart_key = json_data['openart_key']
with open(os.path.join(core.comfyui_manager_path, ".openart_key"), "w") as f: with open(os.path.join(core.manager_files_path, ".openart_key"), "w") as f:
f.write(openart_key) f.write(openart_key)
return web.Response(status=200) return web.Response(status=200)
@@ -178,14 +178,14 @@ async def api_get_comfyworkflows_auth(request):
@PromptServer.instance.routes.post("/manager/set_esheep_workflow_and_images") @PromptServer.instance.routes.post("/manager/set_esheep_workflow_and_images")
async def set_esheep_workflow_and_images(request): async def set_esheep_workflow_and_images(request):
json_data = await request.json() json_data = await request.json()
with open(os.path.join(core.comfyui_manager_path, "esheep_share_message.json"), "w", encoding='utf-8') as file: with open(os.path.join(core.manager_files_path, "esheep_share_message.json"), "w", encoding='utf-8') as file:
json.dump(json_data, file, indent=4) json.dump(json_data, file, indent=4)
return web.Response(status=200) return web.Response(status=200)
@PromptServer.instance.routes.get("/manager/get_esheep_workflow_and_images") @PromptServer.instance.routes.get("/manager/get_esheep_workflow_and_images")
async def get_esheep_workflow_and_images(request): async def get_esheep_workflow_and_images(request):
with open(os.path.join(core.comfyui_manager_path, "esheep_share_message.json"), 'r', encoding='utf-8') as file: with open(os.path.join(core.manager_files_path, "esheep_share_message.json"), 'r', encoding='utf-8') as file:
data = json.load(file) data = json.load(file)
return web.Response(status=200, text=json.dumps(data)) return web.Response(status=200, text=json.dumps(data))
@@ -194,12 +194,12 @@ def set_matrix_auth(json_data):
homeserver = json_data['homeserver'] homeserver = json_data['homeserver']
username = json_data['username'] username = json_data['username']
password = json_data['password'] password = json_data['password']
with open(os.path.join(core.comfyui_manager_path, "matrix_auth"), "w") as f: with open(os.path.join(core.manager_files_path, "matrix_auth"), "w") as f:
f.write("\n".join([homeserver, username, password])) f.write("\n".join([homeserver, username, password]))
def set_comfyworkflows_auth(comfyworkflows_sharekey): def set_comfyworkflows_auth(comfyworkflows_sharekey):
with open(os.path.join(core.comfyui_manager_path, "comfyworkflows_sharekey"), "w") as f: with open(os.path.join(core.manager_files_path, "comfyworkflows_sharekey"), "w") as f:
f.write(comfyworkflows_sharekey) f.write(comfyworkflows_sharekey)

View File

@@ -11,7 +11,7 @@ import {
showYouMLShareDialog showYouMLShareDialog
} from "./comfyui-share-common.js"; } from "./comfyui-share-common.js";
import { OpenArtShareDialog } from "./comfyui-share-openart.js"; import { OpenArtShareDialog } from "./comfyui-share-openart.js";
import { free_models, install_pip, install_via_git_url, manager_instance, rebootAPI, setManagerInstance, show_message } from "./common.js"; import { free_models, install_pip, install_via_git_url, manager_instance, rebootAPI, migrateAPI, setManagerInstance, show_message } from "./common.js";
import { ComponentBuilderDialog, getPureName, load_components, set_component_policy } from "./components-manager.js"; import { ComponentBuilderDialog, getPureName, load_components, set_component_policy } from "./components-manager.js";
import { CustomNodesManager } from "./custom-nodes-manager.js"; import { CustomNodesManager } from "./custom-nodes-manager.js";
import { ModelManager } from "./model-manager.js"; import { ModelManager } from "./model-manager.js";
@@ -239,6 +239,7 @@ function is_legacy_front() {
document.head.appendChild(docStyle); document.head.appendChild(docStyle);
var update_comfyui_button = null; var update_comfyui_button = null;
var switch_comfyui_button = null;
var fetch_updates_button = null; var fetch_updates_button = null;
var update_all_button = null; var update_all_button = null;
var badge_mode = "none"; var badge_mode = "none";
@@ -287,6 +288,18 @@ const style = `
color: white !important; color: white !important;
} }
.cm-button-orange {
width: 310px;
height: 30px;
position: relative;
overflow: hidden;
font-size: 17px !important;
font-weight: bold;
background-color: orange !important;
color: black !important;
}
.cm-experimental-button { .cm-experimental-button {
width: 290px; width: 290px;
height: 30px; height: 30px;
@@ -595,6 +608,154 @@ async function updateComfyUI() {
} }
} }
function showVersionSelectorDialog(versions, current, onSelect) {
const dialog = new ComfyDialog();
dialog.element.style.zIndex = 100003;
dialog.element.style.width = "300px";
dialog.element.style.padding = "0";
dialog.element.style.backgroundColor = "#2a2a2a";
dialog.element.style.border = "1px solid #3a3a3a";
dialog.element.style.borderRadius = "8px";
dialog.element.style.boxSizing = "border-box";
dialog.element.style.overflow = "hidden";
const contentStyle = {
width: "300px",
display: "flex",
flexDirection: "column",
alignItems: "center",
padding: "20px",
boxSizing: "border-box",
gap: "15px"
};
let selectedVersion = versions[0];
const versionList = $el("select", {
multiple: true,
size: Math.min(10, versions.length),
style: {
width: "260px",
height: "auto",
backgroundColor: "#383838",
color: "#ffffff",
border: "1px solid #4a4a4a",
borderRadius: "4px",
padding: "5px",
boxSizing: "border-box"
}
},
versions.map((v, index) => $el("option", {
value: v,
textContent: v,
selected: v === current
}))
);
versionList.addEventListener('change', (e) => {
selectedVersion = e.target.value;
Array.from(e.target.options).forEach(opt => {
opt.selected = opt.value === selectedVersion;
});
});
const content = $el("div", {
style: contentStyle
}, [
$el("h3", {
textContent: "Select Version",
style: {
color: "#ffffff",
backgroundColor: "#1a1a1a",
padding: "10px 15px",
margin: "0 0 10px 0",
width: "260px",
textAlign: "center",
borderRadius: "4px",
boxSizing: "border-box",
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis"
}
}),
versionList,
$el("div", {
style: {
display: "flex",
justifyContent: "space-between",
width: "260px",
gap: "10px"
}
}, [
$el("button", {
textContent: "Cancel",
onclick: () => dialog.close(),
style: {
flex: "1",
padding: "8px",
backgroundColor: "#4a4a4a",
color: "#ffffff",
border: "none",
borderRadius: "4px",
cursor: "pointer",
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis"
}
}),
$el("button", {
textContent: "Select",
onclick: () => {
if (selectedVersion) {
onSelect(selectedVersion);
dialog.close();
} else {
alert("Please select a version.");
}
},
style: {
flex: "1",
padding: "8px",
backgroundColor: "#4CAF50",
color: "#ffffff",
border: "none",
borderRadius: "4px",
cursor: "pointer",
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis"
}
}),
])
]);
dialog.show(content);
}
async function switchComfyUI() {
let res = await api.fetchApi(`/comfyui_manager/comfyui_versions`, { cache: "no-store" });
if(res.status == 200) {
let obj = await res.json();
let versions = [];
let default_version;
for(let v of obj.versions) {
default_version = v;
versions.push(v);
}
showVersionSelectorDialog(versions, obj.current, (selected_version) => {
api.fetchApi(`/comfyui_manager/comfyui_switch_version?ver=${selected_version}`, { cache: "no-store" });
});
}
else {
show_message('Failed to fetch ComfyUI versions.');
}
}
async function fetchUpdates(update_check_checkbox) { async function fetchUpdates(update_check_checkbox) {
let prev_text = fetch_updates_button.innerText; let prev_text = fetch_updates_button.innerText;
fetch_updates_button.innerText = "Fetching updates..."; fetch_updates_button.innerText = "Fetching updates...";
@@ -745,6 +906,14 @@ class ManagerMenuDialog extends ComfyDialog {
() => updateComfyUI() () => updateComfyUI()
}); });
switch_comfyui_button =
$el("button.cm-button", {
type: "button",
textContent: "Switch ComfyUI",
onclick:
() => switchComfyUI()
});
fetch_updates_button = fetch_updates_button =
$el("button.cm-button", { $el("button.cm-button", {
type: "button", type: "button",
@@ -815,6 +984,7 @@ class ManagerMenuDialog extends ComfyDialog {
$el("br", {}, []), $el("br", {}, []),
update_all_button, update_all_button,
update_comfyui_button, update_comfyui_button,
switch_comfyui_button,
fetch_updates_button, fetch_updates_button,
$el("br", {}, []), $el("br", {}, []),
@@ -838,6 +1008,28 @@ class ManagerMenuDialog extends ComfyDialog {
}), }),
]; ];
let migration_btn =
$el("button.cm-button-orange", {
type: "button",
textContent: "Migrate to New Node System",
onclick: () => migrateAPI()
});
migration_btn.style.display = 'none';
res.push(migration_btn);
api.fetchApi('/manager/need_to_migrate')
.then(response => response.text())
.then(text => {
if (text === 'True') {
migration_btn.style.display = 'block';
}
})
.catch(error => {
console.error('Error checking migration status:', error);
});
return res; return res;
} }
@@ -1340,7 +1532,6 @@ app.registerExtension({
try { try {
// new style Manager buttons // new style Manager buttons
// unload models button into new style Manager button // unload models button into new style Manager button
let cmGroup = new (await import("../../scripts/ui/components/buttonGroup.js")).ComfyButtonGroup( let cmGroup = new (await import("../../scripts/ui/components/buttonGroup.js")).ComfyButtonGroup(
new(await import("../../scripts/ui/components/button.js")).ComfyButton({ new(await import("../../scripts/ui/components/button.js")).ComfyButton({
@@ -1354,6 +1545,19 @@ app.registerExtension({
content: "Manager", content: "Manager",
classList: "comfyui-button comfyui-menu-mobile-collapse primary" classList: "comfyui-button comfyui-menu-mobile-collapse primary"
}).element, }).element,
new(await import("../../scripts/ui/components/button.js")).ComfyButton({
icon: "star",
action: () => {
if(!manager_instance)
setManagerInstance(new ManagerMenuDialog());
if(!CustomNodesManager.instance) {
CustomNodesManager.instance = new CustomNodesManager(app, self);
}
CustomNodesManager.instance.show(CustomNodesManager.ShowMode.FAVORITES);
},
tooltip: "Show favorite custom node list"
}).element,
new(await import("../../scripts/ui/components/button.js")).ComfyButton({ new(await import("../../scripts/ui/components/button.js")).ComfyButton({
icon: "vacuum-outline", icon: "vacuum-outline",
action: () => { action: () => {

View File

@@ -29,6 +29,23 @@ export function rebootAPI() {
return false; return false;
} }
export async function migrateAPI() {
if (confirm("When performing a migration, existing installed custom nodes will be renamed and the server will be restarted. Are you sure you want to apply this?\n\n(If you don't perform the migration, ComfyUI-Manager's start-up time will be longer each time due to re-checking during startup.)")) {
try {
await api.fetchApi("/manager/migrate_unmanaged_nodes");
api.fetchApi("/manager/reboot");
}
catch(exception) {
}
return true;
}
return false;
}
export var manager_instance = null; export var manager_instance = null;
export function setManagerInstance(obj) { export function setManagerInstance(obj) {

View File

@@ -1,8 +1,10 @@
import { app } from "../../scripts/app.js"; import { app } from "../../scripts/app.js";
import { $el } from "../../scripts/ui.js"; import { ComfyDialog, $el } from "../../scripts/ui.js";
import { api } from "../../scripts/api.js";
import { import {
manager_instance, rebootAPI, install_via_git_url, manager_instance, rebootAPI, install_via_git_url,
fetchData, md5, icons fetchData, md5, icons, show_message
} from "./common.js"; } from "./common.js";
// https://cenfun.github.io/turbogrid/api.html // https://cenfun.github.io/turbogrid/api.html
@@ -10,7 +12,7 @@ import TG from "./turbogrid.esm.js";
const pageCss = ` const pageCss = `
.cn-manager { .cn-manager {
--grid-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; --grid-font: -apple-system, BlinkMacSystemFont, "Segue UI", "Noto Sans", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
z-index: 10001; z-index: 10001;
width: 80%; width: 80%;
height: 80%; height: 80%;
@@ -212,17 +214,17 @@ const pageCss = `
} }
.cn-manager .cn-btn-enable { .cn-manager .cn-btn-enable {
background-color: blue; background-color: #333399;
color: white; color: white;
} }
.cn-manager .cn-btn-disable { .cn-manager .cn-btn-disable {
background-color: MediumSlateBlue; background-color: #442277;
color: white; color: white;
} }
.cn-manager .cn-btn-update { .cn-manager .cn-btn-update {
background-color: blue; background-color: #1155AA;
color: white; color: white;
} }
@@ -247,10 +249,21 @@ const pageCss = `
} }
.cn-manager .cn-btn-uninstall { .cn-manager .cn-btn-uninstall {
background-color: red; background-color: #993333;
color: white; color: white;
} }
.cn-manager .cn-btn-reinstall {
background-color: #993333;
color: white;
}
.cn-manager .cn-btn-switch {
background-color: #448833;
color: white;
}
@keyframes cn-btn-loading-bg { @keyframes cn-btn-loading-bg {
0% { 0% {
left: 0; left: 0;
@@ -312,7 +325,7 @@ const pageHtml = `
<div class="cn-manager-selection"></div> <div class="cn-manager-selection"></div>
<div class="cn-manager-message"></div> <div class="cn-manager-message"></div>
<div class="cn-manager-footer"> <div class="cn-manager-footer">
<button class="cn-manager-close">Close</button> <button class="cn-manager-back">◀ Back</button>
<button class="cn-manager-restart">Restart</button> <button class="cn-manager-restart">Restart</button>
<div class="cn-flex-auto"></div> <div class="cn-flex-auto"></div>
<button class="cn-manager-check-update">Check Update</button> <button class="cn-manager-check-update">Check Update</button>
@@ -325,6 +338,7 @@ const ShowMode = {
NORMAL: "Normal", NORMAL: "Normal",
UPDATE: "Update", UPDATE: "Update",
MISSING: "Missing", MISSING: "Missing",
FAVORITES: "Favorites",
ALTERNATIVES: "Alternatives" ALTERNATIVES: "Alternatives"
}; };
@@ -356,7 +370,6 @@ export class CustomNodesManager {
} }
init() { init() {
if (!document.querySelector(`style[context="${this.id}"]`)) { if (!document.querySelector(`style[context="${this.id}"]`)) {
const $style = document.createElement("style"); const $style = document.createElement("style");
$style.setAttribute("context", this.id); $style.setAttribute("context", this.id);
@@ -374,6 +387,130 @@ export class CustomNodesManager {
this.initGrid(); this.initGrid();
} }
showVersionSelectorDialog(versions, onSelect) {
const dialog = new ComfyDialog();
dialog.element.style.zIndex = 100003;
dialog.element.style.width = "300px";
dialog.element.style.padding = "0";
dialog.element.style.backgroundColor = "#2a2a2a";
dialog.element.style.border = "1px solid #3a3a3a";
dialog.element.style.borderRadius = "8px";
dialog.element.style.boxSizing = "border-box";
dialog.element.style.overflow = "hidden";
const contentStyle = {
width: "300px",
display: "flex",
flexDirection: "column",
alignItems: "center",
padding: "20px",
boxSizing: "border-box",
gap: "15px"
};
let selectedVersion = versions[0];
const versionList = $el("select", {
multiple: true,
size: Math.min(10, versions.length),
style: {
width: "260px",
height: "auto",
backgroundColor: "#383838",
color: "#ffffff",
border: "1px solid #4a4a4a",
borderRadius: "4px",
padding: "5px",
boxSizing: "border-box"
}
},
versions.map((v, index) => $el("option", {
value: v,
textContent: v,
selected: index === 0
}))
);
versionList.addEventListener('change', (e) => {
selectedVersion = e.target.value;
Array.from(e.target.options).forEach(opt => {
opt.selected = opt.value === selectedVersion;
});
});
const content = $el("div", {
style: contentStyle
}, [
$el("h3", {
textContent: "Select Version",
style: {
color: "#ffffff",
backgroundColor: "#1a1a1a",
padding: "10px 15px",
margin: "0 0 10px 0",
width: "260px",
textAlign: "center",
borderRadius: "4px",
boxSizing: "border-box",
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis"
}
}),
versionList,
$el("div", {
style: {
display: "flex",
justifyContent: "space-between",
width: "260px",
gap: "10px"
}
}, [
$el("button", {
textContent: "Cancel",
onclick: () => dialog.close(),
style: {
flex: "1",
padding: "8px",
backgroundColor: "#4a4a4a",
color: "#ffffff",
border: "none",
borderRadius: "4px",
cursor: "pointer",
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis"
}
}),
$el("button", {
textContent: "Select",
onclick: () => {
if (selectedVersion) {
onSelect(selectedVersion);
dialog.close();
} else {
alert("Please select a version.");
}
},
style: {
flex: "1",
padding: "8px",
backgroundColor: "#4CAF50",
color: "#ffffff",
border: "none",
borderRadius: "4px",
cursor: "pointer",
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis"
}
}),
])
]);
dialog.show(content);
}
initFilter() { initFilter() {
const $filter = this.element.querySelector(".cn-manager-filter"); const $filter = this.element.querySelector(".cn-manager-filter");
const filterList = [{ const filterList = [{
@@ -382,23 +519,31 @@ export class CustomNodesManager {
hasData: true hasData: true
}, { }, {
label: "Installed", label: "Installed",
value: "True", value: "installed",
hasData: true
}, {
label: "Enabled",
value: "enabled",
hasData: true hasData: true
}, { }, {
label: "Disabled", label: "Disabled",
value: "Disabled", value: "disabled",
hasData: true hasData: true
}, { }, {
label: "Import Failed", label: "Import Failed",
value: "Fail", value: "import-fail",
hasData: true hasData: true
}, { }, {
label: "Not Installed", label: "Not Installed",
value: "False", value: "not-installed",
hasData: true hasData: true
}, { }, {
label: "Unknown", label: "ComfyRegistry",
value: "None", value: "cnr",
hasData: true
}, {
label: "Non-ComfyRegistry",
value: "unknown",
hasData: true hasData: true
}, { }, {
label: "Update", label: "Update",
@@ -408,6 +553,10 @@ export class CustomNodesManager {
label: "Missing", label: "Missing",
value: ShowMode.MISSING, value: ShowMode.MISSING,
hasData: false hasData: false
}, {
label: "Favorites",
value: ShowMode.FAVORITES,
hasData: false
}, { }, {
label: "Alternatives of A1111", label: "Alternatives of A1111",
value: ShowMode.ALTERNATIVES, value: ShowMode.ALTERNATIVES,
@@ -423,16 +572,15 @@ export class CustomNodesManager {
return this.filterList.find(it => it.value === filter) return this.filterList.find(it => it.value === filter)
} }
getInstallButtons(installed, title) { getActionButtons(action, rowItem, is_selected_button) {
const buttons = { const buttons = {
"enable": { "enable": {
label: "Enable", label: "Enable",
mode: "toggle_active" mode: "enable"
}, },
"disable": { "disable": {
label: "Disable", label: "Disable",
mode: "toggle_active" mode: "disable"
}, },
"update": { "update": {
@@ -449,45 +597,63 @@ export class CustomNodesManager {
mode: "fix" mode: "fix"
}, },
"reinstall": {
label: "Reinstall",
mode: "reinstall"
},
"install": { "install": {
label: "Install", label: "Install",
mode: "install" mode: "install"
}, },
"try-install": { "try-install": {
label: "Try install", label: "Try install",
mode: "install" mode: "install"
}, },
"uninstall": { "uninstall": {
label: "Uninstall", label: "Uninstall",
mode: "uninstall" mode: "uninstall"
},
"switch": {
label: "Switch Ver",
mode: "switch"
} }
} }
const installGroups = { const installGroups = {
"Disabled": ["enable", "uninstall"], "disabled": ["enable", "switch", "uninstall"],
"Update": ["update", "disable", "uninstall"], "updatable": ["update", "switch", "disable", "uninstall"],
"Fail": ["try-fix", "uninstall"], "import-fail": ["try-fix", "switch", "disable", "uninstall"],
"True": ["try-update", "disable", "uninstall"], "enabled": ["try-update", "switch", "disable", "uninstall"],
"False": ["install"], "not-installed": ["install"],
'None': ["try-install"] 'unknown': ["try-install"],
"invalid-installation": ["reinstall"],
} }
if (!manager_instance.update_check_checkbox.checked) { if (!manager_instance.update_check_checkbox.checked) {
installGroups.True = installGroups.True.filter(it => it !== "try-update"); installGroups.enabled = installGroups.enabled.filter(it => it !== "try-update");
} }
if (title === "ComfyUI-Manager") { if (rowItem?.title === "ComfyUI-Manager") {
installGroups.True = installGroups.True.filter(it => it !== "disable"); installGroups.enabled = installGroups.enabled.filter(it => it !== "disable" && it !== "uninstall" && it !== "switch");
}
let list = installGroups[action];
if(is_selected_button || rowItem?.version === "unknown") {
list = list.filter(it => it !== "switch");
} }
const list = installGroups[installed];
if (!list) { if (!list) {
return ""; return "";
} }
return list.map(id => { return list.map(id => {
const bt = buttons[id]; const bt = buttons[id];
return `<button class="cn-btn-${id}" group="${installed}" mode="${bt.mode}">${bt.label}</button>`; return `<button class="cn-btn-${id}" group="${action}" mode="${bt.mode}">${bt.label}</button>`;
}).join(""); }).join("");
} }
@@ -554,8 +720,11 @@ export class CustomNodesManager {
} }
}, },
".cn-manager-close": { ".cn-manager-back": {
click: (e) => this.close() click: (e) => {
this.close()
manager_instance.show();
}
}, },
".cn-manager-restart": { ".cn-manager-restart": {
@@ -614,13 +783,9 @@ export class CustomNodesManager {
let prevViewRowsLength = -1; let prevViewRowsLength = -1;
grid.bind('onUpdated', (e, d) => { grid.bind('onUpdated', (e, d) => {
const viewRows = grid.viewRows; const viewRows = grid.viewRows;
if (viewRows.length !== prevViewRowsLength) {
prevViewRowsLength = viewRows.length; prevViewRowsLength = viewRows.length;
this.showStatus(`${prevViewRowsLength.toLocaleString()} custom nodes`); this.showStatus(`${prevViewRowsLength.toLocaleString()} custom nodes`);
}
}); });
grid.bind('onSelectChanged', (e, changes) => { grid.bind('onSelectChanged', (e, changes) => {
@@ -630,8 +795,17 @@ export class CustomNodesManager {
grid.bind('onClick', (e, d) => { grid.bind('onClick', (e, d) => {
const btn = this.getButton(d.e.target); const btn = this.getButton(d.e.target);
if (btn) { if (btn) {
const item = this.grid.getRowItemBy("hash", d.rowItem.hash);
const { target, label, mode} = btn;
if((mode === "install" || mode === "switch" || mode == "enable") && item.originalData.version != 'unknown') {
// install after select version via dialog if item is cnr node
this.installNodeWithVersion(d.rowItem, btn, mode == 'enable');
}
else {
this.installNodes([d.rowItem.hash], btn, d.rowItem.title); this.installNodes([d.rowItem.hash], btn, d.rowItem.title);
} }
}
}); });
grid.setOption({ grid.setOption({
@@ -651,7 +825,7 @@ export class CustomNodesManager {
bindContainerResize: true, bindContainerResize: true,
cellResizeObserver: (rowItem, columnItem) => { cellResizeObserver: (rowItem, columnItem) => {
const autoHeightColumns = ['title', 'installed', 'description', "alternatives"]; const autoHeightColumns = ['title', 'action', 'description', "alternatives"];
return autoHeightColumns.includes(columnItem.id) return autoHeightColumns.includes(columnItem.id)
}, },
@@ -696,11 +870,11 @@ export class CustomNodesManager {
theme: colorPalette === "light" ? "" : "dark" theme: colorPalette === "light" ? "" : "dark"
}; };
const rows = this.custom_nodes || []; const rows = this.custom_nodes || {};
rows.forEach((item, i) => { for(let nodeKey in rows) {
item.id = i + 1; let item = rows[nodeKey];
const nodeKey = item.files[0];
const extensionInfo = this.extension_mappings[nodeKey]; const extensionInfo = this.extension_mappings[nodeKey];
if(extensionInfo) { if(extensionInfo) {
const { extensions, conflicts } = extensionInfo; const { extensions, conflicts } = extensionInfo;
if (extensions.length) { if (extensions.length) {
@@ -712,7 +886,7 @@ export class CustomNodesManager {
item.conflictsList = conflicts; item.conflictsList = conflicts;
} }
} }
}); }
const columns = [{ const columns = [{
id: 'id', id: 'id',
@@ -727,22 +901,55 @@ export class CustomNodesManager {
maxWidth: 500, maxWidth: 500,
classMap: 'cn-node-name', classMap: 'cn-node-name',
formatter: (title, rowItem, columnItem) => { formatter: (title, rowItem, columnItem) => {
return `${rowItem.installed === 'Fail' ? '<font color="red"><B>(IMPORT FAILED)</B></font>' : ''} var prefix = '';
<a href=${rowItem.reference} target="_blank"><b>${title}</b></a>`; if(rowItem.action === 'invalid-installation') {
prefix = '<font color="red"><B>(INVALID)</B></font>';
}
else if(rowItem.action === 'import-fail') {
prefix = '<font color="red"><B>(IMPORT FAILED)</B></font>';
}
return `${prefix}<a href=${rowItem.reference} target="_blank"><b>${title}</b></a>`;
} }
}, { }, {
id: 'installed', id: 'version',
name: 'Install', name: 'Version',
width: 200,
minWidth: 100,
maxWidth: 500,
classMap: 'cn-node-desc',
formatter: (version, rowItem, columnItem) => {
if(version == undefined) {
return `undef`;
}
else {
if(rowItem.cnr_latest && version != rowItem.cnr_latest) {
if(version == 'nightly') {
return `${version} [${rowItem.cnr_latest}]`;
}
else {
return `${version} [↑${rowItem.cnr_latest}]`;
}
}
else {
return `${version}`;
}
}
}
}, {
id: 'action',
name: 'Action',
width: 130, width: 130,
minWidth: 110, minWidth: 110,
maxWidth: 200, maxWidth: 200,
sortable: false, sortable: false,
align: 'center', align: 'center',
formatter: (installed, rowItem, columnItem) => { formatter: (action, rowItem, columnItem) => {
if (rowItem.restart) { if (rowItem.restart) {
return `<font color="red">Restart Required</span>`; return `<font color="red">Restart Required</span>`;
} }
const buttons = this.getInstallButtons(installed, rowItem.title); const buttons = this.getActionButtons(action, rowItem);
return `<div class="cn-install-buttons">${buttons}</div>`; return `<div class="cn-install-buttons">${buttons}</div>`;
} }
}, { }, {
@@ -845,14 +1052,35 @@ export class CustomNodesManager {
} }
}]; }];
this.grid.setData({ let rows_values = Object.keys(rows).map(key => rows[key]);
options,
rows, rows_values =
columns rows_values.sort((a, b) => {
if (a.version == 'unknown' && b.version != 'unknown') return 1;
if (a.version != 'unknown' && b.version == 'unknown') return -1;
if (a.stars !== b.stars) {
return b.stars - a.stars;
}
if (a.last_update !== b.last_update) {
return new Date(b.last_update) - new Date(a.last_update);
}
return 0;
}); });
this.grid.render(); this.grid.setData({
options: options,
rows: rows_values,
columns: columns
});
for(let i=0; i<rows_values.length; i++) {
rows_values[i].id = i+1;
}
this.grid.render();
} }
updateGrid() { updateGrid() {
@@ -877,7 +1105,7 @@ export class CustomNodesManager {
const selectedMap = {}; const selectedMap = {};
selectedList.forEach(item => { selectedList.forEach(item => {
let type = item.installed; let type = item.action;
if (item.restart) { if (item.restart) {
type = "Restart Required"; type = "Restart Required";
} }
@@ -895,7 +1123,7 @@ export class CustomNodesManager {
const filterItem = this.getFilterItem(v); const filterItem = this.getFilterItem(v);
list.push(`<div class="cn-selected-buttons"> list.push(`<div class="cn-selected-buttons">
<span>Selected <b>${selectedMap[v].length}</b> ${filterItem ? filterItem.label : v}</span> <span>Selected <b>${selectedMap[v].length}</b> ${filterItem ? filterItem.label : v}</span>
${this.grid.hasMask ? "" : this.getInstallButtons(v)} ${this.grid.hasMask ? "" : this.getActionButtons(v, null, true)}
</div>`); </div>`);
}); });
@@ -913,8 +1141,61 @@ export class CustomNodesManager {
} }
} }
async installNodes(list, btn, title) { async installNodeWithVersion(rowItem, btn, is_enable) {
let hash = rowItem.hash;
let title = rowItem.title;
const item = this.grid.getRowItemBy("hash", hash);
let node_id = item.originalData.id;
this.showLoading();
let res;
if(is_enable) {
res = await api.fetchApi(`/customnode/disabled_versions/${node_id}`, { cache: "no-store" });
}
else {
res = await api.fetchApi(`/customnode/versions/${node_id}`, { cache: "no-store" });
}
this.hideLoading();
if(res.status == 200) {
let obj = await res.json();
let versions = [];
let default_version;
let version_cnt = 0;
if(!is_enable) {
if(rowItem.originalData.active_version != 'nightly') {
versions.push('nightly');
default_version = 'nightly';
version_cnt++;
}
if(rowItem.cnr_latest != rowItem.originalData.active_version) {
versions.push('latest');
}
}
for(let v of obj) {
if(rowItem.originalData.active_version != v.version) {
default_version = v.version;
versions.push(v.version);
version_cnt++;
}
}
this.showVersionSelectorDialog(versions, (selected_version) => {
this.installNodes([hash], btn, title, selected_version);
});
}
else {
show_message('Failed to fetch versions from ComfyRegistry.');
}
}
async installNodes(list, btn, title, selected_version) {
const { target, label, mode} = btn; const { target, label, mode} = btn;
if(mode === "uninstall") { if(mode === "uninstall") {
@@ -924,14 +1205,19 @@ export class CustomNodesManager {
} }
} }
if(mode === "reinstall") {
title = title || `${list.length} custom nodes`;
if (!confirm(`Are you sure reinstall ${title}?`)) {
return;
}
}
target.classList.add("cn-btn-loading"); target.classList.add("cn-btn-loading");
this.showLoading();
this.showError(""); this.showError("");
let needRestart = false; let needRestart = false;
let errorMsg = ""; let errorMsg = "";
for (const hash of list) { for (const hash of list) {
const item = this.grid.getRowItemBy("hash", hash); const item = this.grid.getRowItemBy("hash", hash);
if (!item) { if (!item) {
errorMsg = `Not found custom node: ${hash}`; errorMsg = `Not found custom node: ${hash}`;
@@ -949,9 +1235,28 @@ export class CustomNodesManager {
this.showStatus(`${label} ${item.title} ...`); this.showStatus(`${label} ${item.title} ...`);
const data = item.originalData; const data = item.originalData;
const res = await fetchData(`/customnode/${mode}`, { data.selected_version = selected_version;
data.channel = this.channel;
data.mode = this.mode;
let install_mode = mode;
if(mode == 'switch') {
install_mode = 'install';
}
// don't post install if install_mode == 'enable'
data.skip_post_install = install_mode == 'enable';
let api_mode = install_mode;
if(install_mode == 'enable') {
api_mode = 'install';
}
if(install_mode == 'reinstall') {
api_mode = 'reinstall';
}
const res = await api.fetchApi(`/customnode/${api_mode}`, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data) body: JSON.stringify(data)
}); });
@@ -974,13 +1279,12 @@ export class CustomNodesManager {
this.grid.setRowSelected(item, false); this.grid.setRowSelected(item, false);
item.restart = true; item.restart = true;
this.restartMap[item.hash] = true; this.restartMap[item.hash] = true;
this.grid.updateCell(item, "installed"); this.grid.updateCell(item, "action");
//console.log(res.data); //console.log(res.data);
} }
this.hideLoading();
target.classList.remove("cn-btn-loading"); target.classList.remove("cn-btn-loading");
if (errorMsg) { if (errorMsg) {
@@ -1064,26 +1368,28 @@ export class CustomNodesManager {
const mappings = res.data; const mappings = res.data;
// build regex->url map // build regex->url map
const regex_to_url = []; const regex_to_pack = [];
this.custom_nodes.forEach(node => { for(let k in this.custom_nodes) {
let node = this.custom_nodes[k];
if(node.nodename_pattern) { if(node.nodename_pattern) {
regex_to_url.push({ regex_to_pack.push({
regex: new RegExp(node.nodename_pattern), regex: new RegExp(node.nodename_pattern),
url: node.files[0] url: node.files[0]
}); });
} }
}); }
// build name->url map // build name->url map
const name_to_urls = {}; const name_to_packs = {};
for (const url in mappings) { for (const url in mappings) {
const names = mappings[url]; const names = mappings[url];
for(const name in names[0]) { for(const name in names[0]) {
let v = name_to_urls[names[0][name]]; let v = name_to_packs[names[0][name]];
if(v == undefined) { if(v == undefined) {
v = []; v = [];
name_to_urls[names[0][name]] = v; name_to_packs[names[0][name]] = v;
} }
v.push(url); v.push(url);
} }
@@ -1110,15 +1416,15 @@ export class CustomNodesManager {
continue; continue;
if (!registered_nodes.has(node_type)) { if (!registered_nodes.has(node_type)) {
const urls = name_to_urls[node_type.trim()]; const packs = name_to_packs[node_type.trim()];
if(urls) if(packs)
urls.forEach(url => { packs.forEach(url => {
missing_nodes.add(url); missing_nodes.add(url);
}); });
else { else {
for(let j in regex_to_url) { for(let j in regex_to_pack) {
if(regex_to_url[j].regex.test(node_type)) { if(regex_to_pack[j].regex.test(node_type)) {
missing_nodes.add(regex_to_url[j].url); missing_nodes.add(regex_to_pack[j].url);
} }
} }
} }
@@ -1126,16 +1432,32 @@ export class CustomNodesManager {
} }
const hashMap = {}; const hashMap = {};
this.custom_nodes.forEach(item => { for(let k in this.custom_nodes) {
if (item.files.some(file => missing_nodes.has(file))) { let item = this.custom_nodes[k];
if(missing_nodes.has(item.id)) {
hashMap[item.hash] = true; hashMap[item.hash] = true;
} }
}); else if (item.files?.some(file => missing_nodes.has(file))) {
hashMap[item.hash] = true;
}
}
return hashMap;
}
async getFavorites() {
const hashMap = {};
for(let k in this.custom_nodes) {
let item = this.custom_nodes[k];
if(item.is_favorite)
hashMap[item.hash] = true;
}
return hashMap; return hashMap;
} }
async getAlternatives() { async getAlternatives() {
const mode = manager_instance.datasrc_combo.value; const mode = manager_instance.datasrc_combo.value;
this.showStatus(`Loading alternatives (${mode}) ...`); this.showStatus(`Loading alternatives (${mode}) ...`);
const res = await fetchData(`/customnode/alternatives?mode=${mode}`); const res = await fetchData(`/customnode/alternatives?mode=${mode}`);
@@ -1145,27 +1467,28 @@ export class CustomNodesManager {
} }
const hashMap = {}; const hashMap = {};
const { items } = res.data; const items = res.data;
items.forEach(item => { for(let i in items) {
let item = items[i];
let custom_node = this.custom_nodes[i];
const custom_node = this.custom_nodes.find(node => node.files.find(file => file === item.id));
if (!custom_node) { if (!custom_node) {
console.log(`Not found custom node: ${item.id}`); console.log(`Not found custom node: ${item.id}`);
return; continue;
} }
const tags = `${item.tags}`.split(",").map(tag => { const tags = `${item.tags}`.split(",").map(tag => {
return `<div>${tag.trim()}</div>`; return `<div>${tag.trim()}</div>`;
}).join("") }).join("");
hashMap[custom_node.hash] = { hashMap[custom_node.hash] = {
alternatives: `<div class="cn-tag-list">${tags}</div> ${item.description}` alternatives: `<div class="cn-tag-list">${tags}</div> ${item.description}`
} }
}); }
return hashMap return hashMap;
} }
async loadData(show_mode = ShowMode.NORMAL) { async loadData(show_mode = ShowMode.NORMAL) {
@@ -1187,18 +1510,19 @@ export class CustomNodesManager {
return return
} }
const { channel, custom_nodes} = res.data; const { channel, node_packs } = res.data;
this.channel = channel; this.channel = channel;
this.custom_nodes = custom_nodes; this.mode = mode;
this.custom_nodes = node_packs;
if(this.channel !== 'default') { if(this.channel !== 'default') {
this.element.querySelector(".cn-manager-channel").innerHTML = `Channel: ${this.channel} (Incomplete list)`; this.element.querySelector(".cn-manager-channel").innerHTML = `Channel: ${this.channel} (Incomplete list)`;
} }
for (const item of custom_nodes) { for (const k in node_packs) {
let item = node_packs[k];
item.originalData = JSON.parse(JSON.stringify(item)); item.originalData = JSON.parse(JSON.stringify(item));
const message = item.title + item.files[0]; item.hash = md5(k);
item.hash = md5(message);
} }
const filterItem = this.getFilterItem(this.show_mode); const filterItem = this.getFilterItem(this.show_mode);
@@ -1206,24 +1530,44 @@ export class CustomNodesManager {
let hashMap; let hashMap;
if(this.show_mode == ShowMode.UPDATE) { if(this.show_mode == ShowMode.UPDATE) {
hashMap = {}; hashMap = {};
custom_nodes.forEach(it => { for (const k in node_packs) {
if (it.installed === "Update") { let it = node_packs[k];
if (it['update-state'] === "true") {
hashMap[it.hash] = true; hashMap[it.hash] = true;
} }
}); }
} else if(this.show_mode == ShowMode.MISSING) { } else if(this.show_mode == ShowMode.MISSING) {
hashMap = await this.getMissingNodes(); hashMap = await this.getMissingNodes();
} else if(this.show_mode == ShowMode.ALTERNATIVES) { } else if(this.show_mode == ShowMode.ALTERNATIVES) {
hashMap = await this.getAlternatives(); hashMap = await this.getAlternatives();
} else if(this.show_mode == ShowMode.FAVORITES) {
hashMap = await this.getFavorites();
} }
filterItem.hashMap = hashMap; filterItem.hashMap = hashMap;
filterItem.hasData = true; filterItem.hasData = true;
} }
custom_nodes.forEach(nodeItem => { for(let k in node_packs) {
let nodeItem = node_packs[k];
if (this.restartMap[nodeItem.hash]) { if (this.restartMap[nodeItem.hash]) {
nodeItem.restart = true; nodeItem.restart = true;
} }
if(nodeItem['update-state'] == "true") {
nodeItem.action = 'updatable';
}
else if(nodeItem['import-fail']) {
nodeItem.action = 'import-fail';
}
else {
nodeItem.action = nodeItem.state;
}
if(nodeItem['invalid-installation']) {
nodeItem.action = 'invalid-installation';
}
const filterTypes = new Set(); const filterTypes = new Set();
this.filterList.forEach(filterItem => { this.filterList.forEach(filterItem => {
const { value, hashMap } = filterItem; const { value, hashMap } = filterItem;
@@ -1232,29 +1576,55 @@ export class CustomNodesManager {
if (hashData) { if (hashData) {
filterTypes.add(value); filterTypes.add(value);
if (value === ShowMode.UPDATE) { if (value === ShowMode.UPDATE) {
nodeItem.installed = "Update"; nodeItem['update-state'] = "true";
}
if (value === ShowMode.MISSING) {
nodeItem['missing-node'] = "true";
} }
if (typeof hashData === "object") { if (typeof hashData === "object") {
Object.assign(nodeItem, hashData); Object.assign(nodeItem, hashData);
} }
} }
} else { } else {
if (nodeItem.installed === value) { if (nodeItem.state === value) {
filterTypes.add(value); filterTypes.add(value);
} }
const map = {
"Update": "True", switch(nodeItem.state) {
"Disabled": "True", case "enabled":
"Fail": "True", filterTypes.add("enabled");
"None": "False" case "disabled":
filterTypes.add("installed");
break;
case "not-installed":
filterTypes.add("not-installed");
break;
} }
if (map[nodeItem.installed]) {
filterTypes.add(map[nodeItem.installed]); if(nodeItem.version != 'unknown') {
filterTypes.add("cnr");
}
else {
filterTypes.add("unknown");
}
if(nodeItem['update-state'] == 'true') {
filterTypes.add("updatable");
}
if(nodeItem['import-fail']) {
filterTypes.add("import-fail");
}
if(nodeItem['invalid-installation']) {
filterTypes.add("invalid-installation");
} }
} }
}); });
nodeItem.filterTypes = Array.from(filterTypes); nodeItem.filterTypes = Array.from(filterTypes);
}); }
this.renderGrid(); this.renderGrid();

View File

@@ -235,7 +235,7 @@ const pageHtml = `
<div class="cmm-manager-selection"></div> <div class="cmm-manager-selection"></div>
<div class="cmm-manager-message"></div> <div class="cmm-manager-message"></div>
<div class="cmm-manager-footer"> <div class="cmm-manager-footer">
<button class="cmm-manager-close">Close</button> <button class="cmm-manager-back">Back</button>
<div class="cmm-flex-auto"></div> <div class="cmm-flex-auto"></div>
</div> </div>
`; `;
@@ -365,10 +365,12 @@ export class ModelManager {
} }
}, },
".cmm-manager-close": { ".cmm-manager-back": {
click: (e) => this.close() click: (e) => {
this.close()
manager_instance.show();
}
}, },
}; };
Object.keys(eventsMap).forEach(selector => { Object.keys(eventsMap).forEach(selector => {
const target = this.element.querySelector(selector); const target = this.element.querySelector(selector);

84
js/workflow-metadata.js Normal file
View File

@@ -0,0 +1,84 @@
/**
* Attaches metadata to the workflow on save
* - custom node pack version to all custom nodes used in the workflow
*
* Example metadata:
"extra": {
"node_versions": {
"comfy-core": "v0.3.8-4-g0b2eb7f",
"comfyui-easy-use": "1.2.5"
}
},
*/
import { app } from "../../scripts/app.js";
import { api } from "../../scripts/api.js";
class WorkflowMetadataExtension {
constructor() {
this.name = "Comfy.CustomNodesManager.WorkflowMetadata";
this.installedNodeVersions = {};
this.comfyCoreVersion = null;
}
/**
* Get the installed node versions
* @returns {Promise<Record<string, string>>} The mapping from node name to version
* version can either be a git commit hash or a semantic version such as "1.0.0"
*/
async getInstalledNodeVersions() {
const res = await api.fetchApi("/customnode/installed");
return await res.json();
}
/**
* Get the node versions for the given graph
* @param {LGraph} graph The graph to get the node versions for
* @returns {Promise<Record<string, string>>} The mapping from node name to version
*/
getGraphNodeVersions(graph) {
const nodeVersions = {};
for (const node of graph.nodes) {
const nodeData = node.constructor.nodeData;
// Frontend only nodes don't have nodeData
if (!nodeData) {
continue;
}
const modules = nodeData.python_module.split(".");
if (modules[0] === "custom_nodes") {
const nodePackageName = modules[1].split("@")[0];
const nodeVersion = this.installedNodeVersions[nodePackageName];
nodeVersions[nodePackageName] = nodeVersion;
} else if (["nodes", "comfy_extras"].includes(modules[0])) {
nodeVersions["comfy-core"] = this.comfyCoreVersion;
} else {
console.warn(`Unknown node source: ${nodeData.python_module}`);
}
}
return nodeVersions;
}
async init() {
const extension = this;
this.installedNodeVersions = await this.getInstalledNodeVersions();
this.comfyCoreVersion = (await api.getSystemStats()).system.comfyui_version;
// Attach metadata when app.graphToPrompt is called.
const originalSerialize = LGraph.prototype.serialize;
LGraph.prototype.serialize = function () {
const workflow = originalSerialize.apply(this, arguments);
// Add metadata to the workflow
if (!workflow.extra) {
workflow.extra = {};
}
const graph = this;
workflow.extra["node_versions"] = extension.getGraphNodeVersions(graph);
return workflow;
};
}
}
app.registerExtension(new WorkflowMetadataExtension());

View File

@@ -1,4 +1,3 @@
import datetime
import os import os
import subprocess import subprocess
import sys import sys
@@ -15,8 +14,11 @@ glob_path = os.path.join(os.path.dirname(__file__), "glob")
sys.path.append(glob_path) sys.path.append(glob_path)
import security_check import security_check
from manager_util import PIPFixer, StrictVersion, get_installed_packages, clear_pip_cache import manager_util
import cm_global import cm_global
import manager_downloader
from datetime import datetime
import folder_paths
security_check.security_check() security_check.security_check()
@@ -71,17 +73,20 @@ cm_global.register_api('cm.register_message_collapse', register_message_collapse
cm_global.register_api('cm.is_import_failed_extension', is_import_failed_extension) cm_global.register_api('cm.is_import_failed_extension', is_import_failed_extension)
comfyui_manager_path = os.path.dirname(__file__) comfyui_manager_path = os.path.abspath(os.path.dirname(__file__))
custom_nodes_path = os.path.abspath(os.path.join(comfyui_manager_path, ".."))
startup_script_path = os.path.join(comfyui_manager_path, "startup-scripts") custom_nodes_base_path = folder_paths.get_folder_paths('custom_nodes')[0]
restore_snapshot_path = os.path.join(startup_script_path, "restore-snapshot.json") manager_files_path = os.path.abspath(os.path.join(folder_paths.get_user_directory(), 'default', 'ComfyUI-Manager'))
manager_pip_overrides_path = os.path.join(manager_files_path, "pip_overrides.json")
restore_snapshot_path = os.path.join(manager_files_path, "startup-scripts", "restore-snapshot.json")
git_script_path = os.path.join(comfyui_manager_path, "git_helper.py") git_script_path = os.path.join(comfyui_manager_path, "git_helper.py")
pip_overrides_path = os.path.join(comfyui_manager_path, "pip_overrides.json") cm_cli_path = os.path.join(comfyui_manager_path, "cm-cli.py")
cm_global.pip_overrides = {} cm_global.pip_overrides = {}
if os.path.exists(pip_overrides_path): if os.path.exists(manager_pip_overrides_path):
with open(pip_overrides_path, 'r', encoding="UTF-8", errors="ignore") as json_file: with open(manager_pip_overrides_path, 'r', encoding="UTF-8", errors="ignore") as json_file:
cm_global.pip_overrides = json.load(json_file) cm_global.pip_overrides = json.load(json_file)
cm_global.pip_overrides['numpy'] = 'numpy<2' cm_global.pip_overrides['numpy'] = 'numpy<2'
cm_global.pip_overrides['ultralytics'] = 'ultralytics==8.3.40' # for security cm_global.pip_overrides['ultralytics'] = 'ultralytics==8.3.40' # for security
@@ -144,15 +149,18 @@ try:
postfix = "" postfix = ""
# Logger setup # Logger setup
log_path_base = None
if enable_file_logging: if enable_file_logging:
if os.path.exists(f"comfyui{postfix}.log"): log_path_base = os.path.join(folder_paths.user_directory, 'comfyui')
if os.path.exists(f"comfyui{postfix}.prev.log"):
if os.path.exists(f"comfyui{postfix}.prev2.log"):
os.remove(f"comfyui{postfix}.prev2.log")
os.rename(f"comfyui{postfix}.prev.log", f"comfyui{postfix}.prev2.log")
os.rename(f"comfyui{postfix}.log", f"comfyui{postfix}.prev.log")
log_file = open(f"comfyui{postfix}.log", "w", encoding="utf-8", errors="ignore") if os.path.exists(f"{log_path_base}{postfix}.log"):
if os.path.exists(f"{log_path_base}{postfix}.prev.log"):
if os.path.exists(f"{log_path_base}{postfix}.prev2.log"):
os.remove(f"{log_path_base}{postfix}.prev2.log")
os.rename(f"{log_path_base}{postfix}.prev.log", f"{log_path_base}{postfix}.prev2.log")
os.rename(f"{log_path_base}{postfix}.log", f"{log_path_base}{postfix}.prev.log")
log_file = open(f"{log_path_base}{postfix}.log", "w", encoding="utf-8", errors="ignore")
log_lock = threading.Lock() log_lock = threading.Lock()
@@ -173,7 +181,7 @@ try:
write_stderr = wrapper_stderr write_stderr = wrapper_stderr
pat_tqdm = r'\d+%.*\[(.*?)\]' pat_tqdm = r'\d+%.*\[(.*?)\]'
pat_import_fail = r'seconds \(IMPORT FAILED\):.*[/\\]custom_nodes[/\\](.*)$' pat_import_fail = r'seconds \(IMPORT FAILED\):(.*)$'
is_start_mode = True is_start_mode = True
@@ -206,7 +214,7 @@ try:
if is_start_mode: if is_start_mode:
match = re.search(pat_import_fail, message) match = re.search(pat_import_fail, message)
if match: if match:
import_failed_extensions.add(match.group(1)) import_failed_extensions.add(match.group(1).strip())
if 'Starting server' in message: if 'Starting server' in message:
is_start_mode = False is_start_mode = False
@@ -228,7 +236,7 @@ try:
def sync_write(self, message, file_only=False): def sync_write(self, message, file_only=False):
with log_lock: with log_lock:
timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3] timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
if self.last_char != '\n': if self.last_char != '\n':
log_file.write(message) log_file.write(message)
else: else:
@@ -292,7 +300,7 @@ try:
if is_start_mode: if is_start_mode:
match = re.search(pat_import_fail, message) match = re.search(pat_import_fail, message)
if match: if match:
import_failed_extensions.add(match.group(1)) import_failed_extensions.add(match.group(1).strip())
if 'Starting server' in message: if 'Starting server' in message:
is_start_mode = False is_start_mode = False
@@ -331,14 +339,14 @@ except:
print("## [ERROR] ComfyUI-Manager: GitPython package seems to be installed, but failed to load somehow. Make sure you have a working git client installed") print("## [ERROR] ComfyUI-Manager: GitPython package seems to be installed, but failed to load somehow. Make sure you have a working git client installed")
print("** ComfyUI startup time:", datetime.datetime.now()) print("** ComfyUI startup time:", datetime.now())
print("** Platform:", platform.system()) print("** Platform:", platform.system())
print("** Python version:", sys.version) print("** Python version:", sys.version)
print("** Python executable:", sys.executable) print("** Python executable:", sys.executable)
print("** ComfyUI Path:", comfy_path) print("** ComfyUI Path:", comfy_path)
if enable_file_logging: if log_path_base is not None:
print("** Log path:", os.path.abspath('comfyui.log')) print("** Log path:", os.path.abspath(f'{log_path_base}.log'))
else: else:
print("** Log path: file logging is disabled") print("** Log path: file logging is disabled")
@@ -384,8 +392,8 @@ check_bypass_ssl()
# Perform install # Perform install
processed_install = set() processed_install = set()
script_list_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "startup-scripts", "install-scripts.txt") script_list_path = os.path.join(folder_paths.user_directory, "default", "ComfyUI-Manager", "startup-scripts", "install-scripts.txt")
pip_fixer = PIPFixer(get_installed_packages()) pip_fixer = manager_util.PIPFixer(manager_util.get_installed_packages())
def is_installed(name): def is_installed(name):
@@ -404,18 +412,18 @@ def is_installed(name):
return True return True
if name in cm_global.pip_downgrade_blacklist: if name in cm_global.pip_downgrade_blacklist:
pips = get_installed_packages() pips = manager_util.get_installed_packages()
if match is None: if match is None:
if name in pips: if name in pips:
return True return True
elif match.group(2) in ['<=', '==', '<']: elif match.group(2) in ['<=', '==', '<']:
if name in pips: if name in pips:
if StrictVersion(pips[name]) >= StrictVersion(match.group(3)): if manager_util.StrictVersion(pips[name]) >= manager_util.StrictVersion(match.group(3)):
print(f"[ComfyUI-Manager] skip black listed pip installation: '{name}'") print(f"[ComfyUI-Manager] skip black listed pip installation: '{name}'")
return True return True
pkg = get_installed_packages().get(name.lower()) pkg = manager_util.get_installed_packages().get(name.lower())
if pkg is None: if pkg is None:
return False # update if not installed return False # update if not installed
@@ -423,9 +431,9 @@ def is_installed(name):
return True # don't update if version is not specified return True # don't update if version is not specified
if match.group(2) in ['>', '>=']: if match.group(2) in ['>', '>=']:
if StrictVersion(pkg) < StrictVersion(match.group(3)): if manager_util.StrictVersion(pkg) < manager_util.StrictVersion(match.group(3)):
return False return False
elif StrictVersion(pkg) > StrictVersion(match.group(3)): elif manager_util.StrictVersion(pkg) > manager_util.StrictVersion(match.group(3)):
print(f"[SKIP] Downgrading pip package isn't allowed: {name.lower()} (cur={pkg})") print(f"[SKIP] Downgrading pip package isn't allowed: {name.lower()} (cur={pkg})")
return True # prevent downgrade return True # prevent downgrade
@@ -457,53 +465,11 @@ if os.path.exists(restore_snapshot_path):
print(prefix, msg, end="") print(prefix, msg, end="")
print("[ComfyUI-Manager] Restore snapshot.") print("[ComfyUI-Manager] Restore snapshot.")
cmd_str = [sys.executable, git_script_path, '--apply-snapshot', restore_snapshot_path]
new_env = os.environ.copy() new_env = os.environ.copy()
new_env["COMFYUI_PATH"] = comfy_path new_env["COMFYUI_PATH"] = comfy_path
exit_code = process_wrap(cmd_str, custom_nodes_path, handler=msg_capture, env=new_env)
repository_name = '' cmd_str = [sys.executable, cm_cli_path, 'restore-snapshot', restore_snapshot_path]
for url in cloned_repos: exit_code = process_wrap(cmd_str, custom_nodes_base_path, handler=msg_capture, env=new_env)
try:
repository_name = url.split("/")[-1].strip()
repo_path = os.path.join(custom_nodes_path, repository_name)
repo_path = os.path.abspath(repo_path)
requirements_path = os.path.join(repo_path, 'requirements.txt')
install_script_path = os.path.join(repo_path, 'install.py')
this_exit_code = 0
if os.path.exists(requirements_path):
with open(requirements_path, 'r', encoding="UTF-8", errors="ignore") as file:
for line in file:
package_name = remap_pip_package(line.strip())
if package_name and not is_installed(package_name):
if not package_name.startswith('#'):
if '--index-url' in package_name:
s = package_name.split('--index-url')
install_cmd = [sys.executable, "-m", "pip", "install", s[0].strip(), '--index-url', s[1].strip()]
else:
install_cmd = [sys.executable, "-m", "pip", "install", package_name]
this_exit_code += process_wrap(install_cmd, repo_path)
if os.path.exists(install_script_path) and f'{repo_path}/install.py' not in processed_install:
processed_install.add(f'{repo_path}/install.py')
install_cmd = [sys.executable, install_script_path]
print(f">>> {install_cmd} / {repo_path}")
new_env = os.environ.copy()
new_env["COMFYUI_PATH"] = comfy_path
this_exit_code += process_wrap(install_cmd, repo_path, env=new_env)
if this_exit_code != 0:
print(f"[ComfyUI-Manager] Restoring '{repository_name}' is failed.")
except Exception as e:
print(e)
print(f"[ComfyUI-Manager] Restoring '{repository_name}' is failed.")
if exit_code != 0: if exit_code != 0:
print("[ComfyUI-Manager] Restore snapshot failed.") print("[ComfyUI-Manager] Restore snapshot failed.")
@@ -547,6 +513,65 @@ def execute_lazy_install_script(repo_path, executable):
process_wrap(install_cmd, repo_path, env=new_env) process_wrap(install_cmd, repo_path, env=new_env)
def execute_lazy_cnr_switch(target, zip_url, from_path, to_path, no_deps, custom_nodes_path):
import uuid
import shutil
# 1. download
archive_name = f"CNR_temp_{str(uuid.uuid4())}.zip" # should be unpredictable name - security precaution
download_path = os.path.join(custom_nodes_path, archive_name)
manager_downloader.download_url(zip_url, custom_nodes_path, archive_name)
# 2. extract files into <node_id>@<cur_ver>
extracted = manager_util.extract_package_as_zip(download_path, from_path)
os.remove(download_path)
if extracted is None:
if len(os.listdir(from_path)) == 0:
shutil.rmtree(from_path)
print(f'Empty archive file: {target}')
return False
# 3. calculate garbage files (.tracking - extracted)
tracking_info_file = os.path.join(from_path, '.tracking')
prev_files = set()
with open(tracking_info_file, 'r') as f:
for line in f:
prev_files.add(line.strip())
garbage = prev_files.difference(extracted)
garbage = [os.path.join(custom_nodes_path, x) for x in garbage]
# 4-1. remove garbage files
for x in garbage:
if os.path.isfile(x):
os.remove(x)
# 4-2. remove garbage dir if empty
for x in garbage:
if os.path.isdir(x):
if not os.listdir(x):
os.rmdir(x)
# 5. rename dir name <node_id>@<prev_ver> ==> <node_id>@<cur_ver>
print(f"'{from_path}' is moved to '{to_path}'")
shutil.move(from_path, to_path)
# 6. create .tracking file
tracking_info_file = os.path.join(to_path, '.tracking')
with open(tracking_info_file, "w", encoding='utf-8') as file:
file.write('\n'.join(list(extracted)))
def execute_migration(moves):
import shutil
for x in moves:
if os.path.exists(x[0]) and not os.path.exists(x[1]):
shutil.move(x[0], x[1])
print(f"[ComfyUI-Manager] MIGRATION: '{x[0]}' -> '{x[1]}'")
# Check if script_list_path exists # Check if script_list_path exists
if os.path.exists(script_list_path): if os.path.exists(script_list_path):
print("\n#######################################################################") print("\n#######################################################################")
@@ -568,6 +593,13 @@ if os.path.exists(script_list_path):
if script[1] == "#LAZY-INSTALL-SCRIPT": if script[1] == "#LAZY-INSTALL-SCRIPT":
execute_lazy_install_script(script[0], script[2]) execute_lazy_install_script(script[0], script[2])
elif script[1] == "#LAZY-CNR-SWITCH-SCRIPT":
execute_lazy_cnr_switch(script[0], script[2], script[3], script[4], script[5], script[6])
execute_lazy_install_script(script[3], script[7])
elif script[1] == "#LAZY-MIGRATION":
execute_migration(script[2])
elif os.path.exists(script[0]): elif os.path.exists(script[0]):
if script[1] == "#FORCE": if script[1] == "#FORCE":
del script[1] del script[1]
@@ -601,7 +633,7 @@ pip_fixer.fix_broken()
del processed_install del processed_install
del pip_fixer del pip_fixer
clear_pip_cache() manager_util.clear_pip_cache()
def check_windows_event_loop_policy(): def check_windows_event_loop_policy():

View File

@@ -1,7 +1,7 @@
[project] [project]
name = "comfyui-manager" name = "comfyui-manager"
description = "ComfyUI-Manager provides features to install and manage custom nodes for ComfyUI, as well as various functionalities to assist with ComfyUI." description = "ComfyUI-Manager provides features to install and manage custom nodes for ComfyUI, as well as various functionalities to assist with ComfyUI."
version = "2.55.5" version = "3.1"
license = { file = "LICENSE.txt" } license = { file = "LICENSE.txt" }
dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"] dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"]