Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
405e8886e0 |
@@ -9,6 +9,29 @@ and this project adheres to [Semantic Versioning 2.0.0](https://semver.org/spec/
|
||||
|
||||
### Added
|
||||
|
||||
- A folder can be a channel of a private network. With
|
||||
`network_mode = private`, a line of `channels.list` can name a folder, such
|
||||
as `private::\\NAS\comfy\channel` or `private::/srv/comfy/channel`. Such a
|
||||
line was refused with `An invalid channel was used`: the channel was in the
|
||||
Channel menu of the legacy UI, and its list did not load. The folder is now
|
||||
read as a channel, so a closed network needs no web server for its own
|
||||
`custom-node-list.json`. As for every channel but the default one, its
|
||||
lists are read at the start with `default_cache_as_channel_url = True`, or
|
||||
with the database mode `remote`. Only a folder that is written in
|
||||
`channels.list` is a channel, and only on a private network. A folder that
|
||||
a request names, or that only `channel_url` of `config.ini` names, is
|
||||
refused as before.
|
||||
|
||||
With another `network_mode` the folder is refused, and the refusal names the
|
||||
channel as `channels.list` names it and the setting that it needs, not the
|
||||
folder. The legacy Custom Nodes Manager shows it in place of `Failed to get
|
||||
custom node list.`, an install from that channel reports it, `cm-cli show`
|
||||
prints it in place of a traceback, and the start logs it as a warning. A
|
||||
refused channel no longer stops the tasks of the start with a traceback. For
|
||||
a channel that `channels.list` does not have, the legacy Custom Nodes
|
||||
Manager, `cm-cli` and an install say that a channel has to be in
|
||||
`channels.list`, without its URL or folder.
|
||||
|
||||
- An aria2 on the same machine can be the downloader. With aria2 as the
|
||||
downloader, the Manager asks aria2 to save a file into `/models/...` or
|
||||
`/custom_nodes`, which is where the container of `docs/en/use_aria2.md`
|
||||
|
||||
+10
-2
@@ -446,7 +446,11 @@ def disable_node(node_spec_str: str, is_all=False, cnt_msg=''):
|
||||
|
||||
|
||||
def show_list(kind, simple=False):
|
||||
custom_nodes = asyncio.run(unified_manager.get_custom_nodes(channel=cmd_ctx.channel, mode=cmd_ctx.mode))
|
||||
try:
|
||||
custom_nodes = asyncio.run(unified_manager.get_custom_nodes(channel=cmd_ctx.channel, mode=cmd_ctx.mode))
|
||||
except core.InvalidChannel as e:
|
||||
print(f"ERROR: {e.reason}", style="bold red")
|
||||
raise typer.Exit(code=1)
|
||||
|
||||
# collect not-installed unknown nodes
|
||||
not_installed_unknown_nodes = []
|
||||
@@ -1484,7 +1488,11 @@ def export_custom_node_ids(
|
||||
for x in unified_manager.cnr_map.keys():
|
||||
print(x, file=output_file)
|
||||
|
||||
custom_nodes = asyncio.run(unified_manager.get_custom_nodes(channel=cmd_ctx.channel, mode=cmd_ctx.mode))
|
||||
try:
|
||||
custom_nodes = asyncio.run(unified_manager.get_custom_nodes(channel=cmd_ctx.channel, mode=cmd_ctx.mode))
|
||||
except core.InvalidChannel as e:
|
||||
print(f"ERROR: {e.reason}", style="bold red")
|
||||
raise typer.Exit(code=1)
|
||||
for x in custom_nodes.values():
|
||||
if 'cnr_latest' not in x:
|
||||
if len(x['files']) == 1:
|
||||
|
||||
@@ -72,9 +72,10 @@ default_custom_nodes_path = None
|
||||
|
||||
|
||||
class InvalidChannel(Exception):
|
||||
def __init__(self, channel):
|
||||
def __init__(self, channel, reason='The channel is not allowed. A channel has to be in `channels.list`.'):
|
||||
self.channel = channel
|
||||
super().__init__(channel)
|
||||
self.reason = reason
|
||||
super().__init__(reason)
|
||||
|
||||
|
||||
def get_default_custom_nodes_path():
|
||||
@@ -191,6 +192,13 @@ def normalize_channel(channel):
|
||||
return normalize_channel_url(channel)
|
||||
elif channel.startswith('http://') and get_config()['http_channel_enabled'] == True:
|
||||
return channel
|
||||
elif channel.startswith('\\\\') or os.path.isabs(channel):
|
||||
network_mode = get_config()['network_mode']
|
||||
if network_mode == 'private':
|
||||
return channel
|
||||
for name, url in get_channel_dict().items():
|
||||
if url == channel:
|
||||
raise InvalidChannel(channel, f"The channel '{name}' is a folder, and a folder is allowed as a channel only with `network_mode = private`. The current network_mode is `{network_mode}`.")
|
||||
|
||||
tmp_dict = get_channel_dict()
|
||||
channel_url = tmp_dict.get(channel)
|
||||
@@ -1518,7 +1526,7 @@ class UnifiedManager:
|
||||
try:
|
||||
repo_url = await self._get_git_install_url(node_id, version_spec, channel, mode)
|
||||
except InvalidChannel as exc:
|
||||
return ManagedResult('fail').fail(f'Invalid channel is used: {exc.channel}')
|
||||
return ManagedResult('fail').fail(exc.reason)
|
||||
except LookupError as exc:
|
||||
return ManagedResult('install').fail(str(exc))
|
||||
|
||||
@@ -1585,7 +1593,7 @@ class UnifiedManager:
|
||||
try:
|
||||
repo_url = await self._get_git_install_url(node_id, version_spec, channel, mode)
|
||||
except InvalidChannel as exc:
|
||||
return ManagedResult('fail').fail(f'Invalid channel is used: {exc.channel}')
|
||||
return ManagedResult('fail').fail(exc.reason)
|
||||
except LookupError as exc:
|
||||
return ManagedResult('install').fail(str(exc))
|
||||
install_path = self._git_install_path(node_id, version_spec, repo_url)
|
||||
|
||||
@@ -2222,9 +2222,12 @@ async def default_cache_update():
|
||||
await core.unified_manager.reload(
|
||||
ManagerDatabaseSource.remote.value, dont_wait=False
|
||||
)
|
||||
await core.unified_manager.get_custom_nodes(
|
||||
channel_url, ManagerDatabaseSource.remote.value
|
||||
)
|
||||
try:
|
||||
await core.unified_manager.get_custom_nodes(
|
||||
channel_url, ManagerDatabaseSource.remote.value
|
||||
)
|
||||
except core.InvalidChannel as e:
|
||||
logging.warning(f"[ComfyUI-Manager] {e.reason}")
|
||||
else:
|
||||
await core.unified_manager.reload(
|
||||
ManagerDatabaseSource.remote.value, dont_wait=False, update_cnr_map=False
|
||||
|
||||
@@ -422,7 +422,8 @@ export async function fetchData(route, options) {
|
||||
if (status !== 200) {
|
||||
return {
|
||||
status,
|
||||
error: new Error(statusText || "Unknown Error")
|
||||
error: new Error(statusText || "Unknown Error"),
|
||||
detail: await res.text().catch(() => "")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2175,7 +2175,7 @@ export class CustomNodesManager {
|
||||
// a server that was not restarted since its update still fetches every repository without skip_update
|
||||
const res = await fetchData(`/v2/customnode/getlist?mode=${mode}&skip_update=true`);
|
||||
if (res.error) {
|
||||
this.showError("Failed to get custom node list.");
|
||||
this.showError(res.status === 403 && res.detail ? sanitizeHTML(res.detail) : "Failed to get custom node list.");
|
||||
this.hideLoading();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -70,9 +70,10 @@ default_custom_nodes_path = None
|
||||
|
||||
|
||||
class InvalidChannel(Exception):
|
||||
def __init__(self, channel):
|
||||
def __init__(self, channel, reason='The channel is not allowed. A channel has to be in `channels.list`.'):
|
||||
self.channel = channel
|
||||
super().__init__(channel)
|
||||
self.reason = reason
|
||||
super().__init__(reason)
|
||||
|
||||
|
||||
def get_default_custom_nodes_path():
|
||||
@@ -192,6 +193,13 @@ def normalize_channel(channel):
|
||||
return normalize_channel_url(channel)
|
||||
elif channel.startswith('http://') and get_config()['http_channel_enabled'] == True:
|
||||
return channel
|
||||
elif channel.startswith('\\\\') or os.path.isabs(channel):
|
||||
network_mode = get_config()['network_mode']
|
||||
if network_mode == 'private':
|
||||
return channel
|
||||
for name, url in get_channel_dict().items():
|
||||
if url == channel:
|
||||
raise InvalidChannel(channel, f"The channel '{name}' is a folder, and a folder is allowed as a channel only with `network_mode = private`. The current network_mode is `{network_mode}`.")
|
||||
|
||||
tmp_dict = get_channel_dict()
|
||||
channel_url = tmp_dict.get(channel)
|
||||
@@ -1434,7 +1442,7 @@ class UnifiedManager:
|
||||
try:
|
||||
repo_url = await self.get_git_install_url(node_id, version_spec, channel, mode)
|
||||
except InvalidChannel as exc:
|
||||
return ManagedResult('fail').fail(f'Invalid channel is used: {exc.channel}')
|
||||
return ManagedResult('fail').fail(exc.reason)
|
||||
except LookupError as exc:
|
||||
return ManagedResult('install').fail(str(exc))
|
||||
|
||||
@@ -1536,7 +1544,7 @@ class UnifiedManager:
|
||||
try:
|
||||
repo_url = await self.get_git_install_url(node_id, version_spec, channel, mode)
|
||||
except InvalidChannel as exc:
|
||||
return ManagedResult('fail').fail(f'Invalid channel is used: {exc.channel}')
|
||||
return ManagedResult('fail').fail(exc.reason)
|
||||
except LookupError as exc:
|
||||
return ManagedResult('install').fail(str(exc))
|
||||
install_path = self._git_install_path(node_id, version_spec, repo_url)
|
||||
|
||||
@@ -1141,7 +1141,11 @@ async def fetch_customnode_list(request):
|
||||
else:
|
||||
channel = core.get_config()['channel_url']
|
||||
|
||||
node_packs = await core.get_unified_total_nodes(channel, mode, 'cache')
|
||||
try:
|
||||
node_packs = await core.get_unified_total_nodes(channel, mode, 'cache')
|
||||
except core.InvalidChannel as e:
|
||||
logging.warning(f"[ComfyUI-Manager] {e.reason}")
|
||||
return web.Response(status=403, text=e.reason)
|
||||
json_obj_github = core.get_data_by_mode(mode, 'github-stats.json', 'default')
|
||||
json_obj_extras = core.get_data_by_mode(mode, 'extras.json', 'default')
|
||||
|
||||
@@ -2082,7 +2086,10 @@ async def default_cache_update():
|
||||
else:
|
||||
# load at least once
|
||||
await core.unified_manager.reload('remote', dont_wait=False)
|
||||
await core.unified_manager.get_custom_nodes(channel_url, 'remote')
|
||||
try:
|
||||
await core.unified_manager.get_custom_nodes(channel_url, 'remote')
|
||||
except core.InvalidChannel as e:
|
||||
logging.warning(f"[ComfyUI-Manager] {e.reason}")
|
||||
else:
|
||||
await core.unified_manager.reload('remote', dont_wait=False, update_cnr_map=False)
|
||||
|
||||
|
||||
@@ -348,3 +348,15 @@ def test_restore_dependencies_runs_for_the_nodepacks_only(cm_cli, manager, folde
|
||||
|
||||
assert [line for line in cm_cli.said() if line.startswith('Restoring')] == [f'Restoring [1/1]: {folder}{os.sep}a-pack']
|
||||
assert [call.args[1] for call in manager.execute_install_script.call_args_list] == [os.path.join(folder, 'a-pack')]
|
||||
|
||||
|
||||
def test_a_list_of_a_refused_channel_says_why_and_fails(cm_cli, manager, core, monkeypatch): # noqa: F811
|
||||
async def refused(channel, mode):
|
||||
raise core.InvalidChannel('/srv/channel', 'the reason [of it]')
|
||||
|
||||
monkeypatch.setattr(manager, 'get_custom_nodes', refused)
|
||||
|
||||
with pytest.raises(typer.Exit) as stop:
|
||||
cm_cli('show_list')['show_list']('all')
|
||||
|
||||
assert (cm_cli.said(), stop.value.exit_code) == (['ERROR: the reason [of it]'], 1)
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
from aiohttp import web
|
||||
|
||||
from legacy_html_testutil import PACKAGE, load_functions
|
||||
from test_default_channel import COMFY_ORG, answer, configure, handlers, idle, route, user, write # noqa: F401
|
||||
|
||||
SHARED_URL = 'https://github.com/example/ComfyUI-Shared'
|
||||
SERVERS = ['glob', 'legacy']
|
||||
NETWORKS = [((), 'public'), (('network_mode = offline',), 'offline')]
|
||||
UNLISTED = 'The channel is not allowed. A channel has to be in `channels.list`.'
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def share(user): # noqa: F811
|
||||
folder = user.path / 'share'
|
||||
folder.mkdir()
|
||||
(folder / 'custom-node-list.json').write_text(json.dumps({'custom_nodes': [
|
||||
{'author': 'example', 'title': 'ComfyUI-Shared', 'reference': SHARED_URL, 'files': [SHARED_URL],
|
||||
'install_type': 'git-clone', 'description': ''}]}))
|
||||
read, cloned = [], []
|
||||
read_data = user.util.get_data
|
||||
|
||||
async def recording(uri, silent=False):
|
||||
read.append(uri)
|
||||
return await read_data(uri, silent)
|
||||
|
||||
user.monkeypatch.setattr(user.util, 'get_data', recording)
|
||||
custom_nodes = user.path / 'comfyui' / 'custom_nodes'
|
||||
custom_nodes.mkdir(parents=True)
|
||||
user.monkeypatch.setattr(sys.modules['folder_paths'], 'get_folder_paths', lambda name: [str(custom_nodes)], raising=False)
|
||||
|
||||
def start(server):
|
||||
write(user, f'{server} start')
|
||||
core = user.cores[server]
|
||||
manager = core.UnifiedManager()
|
||||
|
||||
def repo_install(url, to_path, **kwargs):
|
||||
cloned.append(url)
|
||||
return core.ManagedResult('install')
|
||||
|
||||
user.monkeypatch.setattr(manager, 'repo_install', repo_install)
|
||||
user.monkeypatch.setattr(core, 'unified_manager', manager)
|
||||
read.clear()
|
||||
return core
|
||||
|
||||
return SimpleNamespace(folder=str(folder), start=start, read=read, cloned=cloned)
|
||||
|
||||
|
||||
def install(core, channel):
|
||||
result = asyncio.run(core.unified_manager.install_by_id('ComfyUI-Shared', 'unknown', channel, 'cache'))
|
||||
return result.result, result.msg
|
||||
|
||||
|
||||
@pytest.mark.parametrize('server', SERVERS)
|
||||
def test_a_folder_that_channels_list_names_is_a_channel_of_a_private_network(user, share, server): # noqa: F811
|
||||
configure(user, share.folder, COMFY_ORG, 'network_mode = private', 'default_cache_as_channel_url = True')
|
||||
with open(user.path / 'channels.list', 'a') as f:
|
||||
f.write(f'private::{share.folder}\n')
|
||||
core = share.start(server)
|
||||
|
||||
assert list(asyncio.run(core.unified_manager.get_custom_nodes(core.get_config()['channel_url'], 'cache'))) == ['ComfyUI-Shared']
|
||||
assert answer(handlers(user, server, {'channel_url_list'})['channel_url_list'])['selected'] == 'private'
|
||||
assert install(core, 'private') == (True, None)
|
||||
assert share.cloned == [SHARED_URL]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('unc', [False, True], ids=['folder', 'UNC'])
|
||||
@pytest.mark.parametrize('server', SERVERS)
|
||||
def test_a_request_cannot_name_a_folder_that_channels_list_does_not_have(user, share, server, unc): # noqa: F811
|
||||
configure(user, None, COMFY_ORG, 'network_mode = private')
|
||||
core = share.start(server)
|
||||
channel = '\\\\attacker\\share' if unc else share.folder
|
||||
|
||||
assert install(core, channel) == (False, UNLISTED)
|
||||
assert (share.cloned, share.read) == ([], [])
|
||||
|
||||
|
||||
def needs(mode):
|
||||
return ("The channel 'private' is a folder, and a folder is allowed as a channel only with `network_mode = private`. "
|
||||
f'The current network_mode is `{mode}`.')
|
||||
|
||||
|
||||
def register(user, share, *lines): # noqa: F811
|
||||
configure(user, share.folder, COMFY_ORG, *lines)
|
||||
with open(user.path / 'channels.list', 'a') as f:
|
||||
f.write(f'private::{share.folder}\n')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('lines', [('network_mode = private',), ()], ids=['private', 'public'])
|
||||
@pytest.mark.parametrize('server', SERVERS)
|
||||
def test_a_folder_that_only_config_ini_names_is_refused(user, share, server, lines): # noqa: F811
|
||||
configure(user, share.folder, COMFY_ORG, *lines)
|
||||
core = share.start(server)
|
||||
|
||||
with pytest.raises(core.InvalidChannel) as refused:
|
||||
asyncio.run(core.unified_manager.get_custom_nodes(core.get_config()['channel_url'], 'cache'))
|
||||
assert refused.value.reason == UNLISTED
|
||||
assert share.read == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize('lines,mode', NETWORKS, ids=['public', 'offline'])
|
||||
@pytest.mark.parametrize('server', SERVERS)
|
||||
def test_a_folder_on_another_network_is_refused_with_the_setting_it_needs(user, share, server, lines, mode): # noqa: F811
|
||||
register(user, share, *lines)
|
||||
core = share.start(server)
|
||||
|
||||
with pytest.raises(core.InvalidChannel) as refused:
|
||||
asyncio.run(core.unified_manager.get_custom_nodes(core.get_config()['channel_url'], 'cache'))
|
||||
assert refused.value.reason == needs(mode)
|
||||
assert install(core, 'private') == (False, needs(mode))
|
||||
assert (share.cloned, share.read) == ([], [])
|
||||
|
||||
|
||||
def test_the_legacy_list_answers_why_a_folder_is_refused(user, share): # noqa: F811
|
||||
register(user, share)
|
||||
core = share.start('legacy')
|
||||
handler = load_functions(PACKAGE / 'legacy/manager_server.py', {'fetch_customnode_list'}, {
|
||||
'core': core, 'web': web, 'logging': logging, 'routes': SimpleNamespace(get=route, post=route)})['fetch_customnode_list']
|
||||
|
||||
response = asyncio.run(handler(SimpleNamespace(rel_url=SimpleNamespace(query={'mode': 'cache'}))))
|
||||
|
||||
assert (response.status, response.text) == (403, needs('public'))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('server', SERVERS)
|
||||
def test_the_start_warns_of_a_folder_on_a_public_network_and_completes(user, share, server, caplog): # noqa: F811
|
||||
register(user, share)
|
||||
core = share.start(server)
|
||||
user.monkeypatch.setattr(core.unified_manager, 'reload', idle)
|
||||
user.monkeypatch.setattr(core, 'check_invalid_nodes', lambda: None)
|
||||
start = load_functions(PACKAGE / server / 'manager_server.py', {'default_cache_update'}, {
|
||||
'os': os, 'logging': logging, 'traceback': traceback, 'asyncio': asyncio, 'manager_util': user.util, 'core': core,
|
||||
'ManagerDatabaseSource': SimpleNamespace(remote=SimpleNamespace(value='remote'))})['default_cache_update']
|
||||
|
||||
with caplog.at_level(logging.WARNING):
|
||||
asyncio.run(start())
|
||||
|
||||
assert [record.getMessage() for record in caplog.records if 'network_mode' in record.getMessage()] == [
|
||||
f'[ComfyUI-Manager] {needs("public")}']
|
||||
assert [uri for uri in share.read if uri.startswith(share.folder)] == []
|
||||
Reference in New Issue
Block a user