mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-03-05 01:07:37 +08:00
feat: add --enable-assets flag, disable assets by default, expose to frontend
Replace --disable-assets-autoscan with --enable-assets so the assets system (API routes, database sync, background scanning) is off by default and must be explicitly opted into. Expose the flag as an "assets" entry in SERVER_FEATURE_FLAGS so the frontend can read it from GET /features. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
13277d2658
commit
3232f48a41
@ -1,3 +1,4 @@
|
|||||||
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@ -636,22 +637,12 @@ async def seed_assets(request: web.Request) -> web.Response:
|
|||||||
wait_param = request.query.get("wait", "").lower()
|
wait_param = request.query.get("wait", "").lower()
|
||||||
should_wait = wait_param in ("true", "1", "yes")
|
should_wait = wait_param in ("true", "1", "yes")
|
||||||
|
|
||||||
# Temporarily enable seeder for explicit API calls (--disable-assets-autoscan
|
|
||||||
# only prevents the automatic startup scan, not manual triggers)
|
|
||||||
was_disabled = asset_seeder.is_disabled()
|
|
||||||
if was_disabled:
|
|
||||||
asset_seeder.enable()
|
|
||||||
|
|
||||||
started = asset_seeder.start(roots=valid_roots)
|
started = asset_seeder.start(roots=valid_roots)
|
||||||
if not started:
|
if not started:
|
||||||
if was_disabled:
|
|
||||||
asset_seeder.disable()
|
|
||||||
return web.json_response({"status": "already_running"}, status=409)
|
return web.json_response({"status": "already_running"}, status=409)
|
||||||
|
|
||||||
if should_wait:
|
if should_wait:
|
||||||
asset_seeder.wait()
|
await asyncio.to_thread(asset_seeder.wait)
|
||||||
if was_disabled:
|
|
||||||
asset_seeder.disable()
|
|
||||||
status = asset_seeder.get_status()
|
status = asset_seeder.get_status()
|
||||||
return web.json_response(
|
return web.json_response(
|
||||||
{
|
{
|
||||||
@ -667,11 +658,6 @@ async def seed_assets(request: web.Request) -> web.Response:
|
|||||||
status=200,
|
status=200,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Re-disable after starting: the running thread doesn't check _disabled,
|
|
||||||
# so this only prevents new scans from auto-starting while this one runs.
|
|
||||||
if was_disabled:
|
|
||||||
asset_seeder.disable()
|
|
||||||
|
|
||||||
return web.json_response({"status": "started"}, status=202)
|
return web.json_response({"status": "started"}, status=202)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -232,7 +232,7 @@ database_default_path = os.path.abspath(
|
|||||||
os.path.join(os.path.dirname(__file__), "..", "user", "comfyui.db")
|
os.path.join(os.path.dirname(__file__), "..", "user", "comfyui.db")
|
||||||
)
|
)
|
||||||
parser.add_argument("--database-url", type=str, default=f"sqlite:///{database_default_path}", help="Specify the database URL, e.g. for an in-memory database you can use 'sqlite:///:memory:'.")
|
parser.add_argument("--database-url", type=str, default=f"sqlite:///{database_default_path}", help="Specify the database URL, e.g. for an in-memory database you can use 'sqlite:///:memory:'.")
|
||||||
parser.add_argument("--disable-assets-autoscan", action="store_true", help="Disable asset scanning on startup for database synchronization.")
|
parser.add_argument("--enable-assets", action="store_true", help="Enable the assets system (API routes, database synchronization, and background scanning).")
|
||||||
|
|
||||||
if comfy.options.args_parsing:
|
if comfy.options.args_parsing:
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|||||||
@ -15,6 +15,7 @@ SERVER_FEATURE_FLAGS: dict[str, Any] = {
|
|||||||
"max_upload_size": args.max_upload_size * 1024 * 1024, # Convert MB to bytes
|
"max_upload_size": args.max_upload_size * 1024 * 1024, # Convert MB to bytes
|
||||||
"extension": {"manager": {"supports_v4": True}},
|
"extension": {"manager": {"supports_v4": True}},
|
||||||
"node_replacements": True,
|
"node_replacements": True,
|
||||||
|
"assets": args.enable_assets,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
7
main.py
7
main.py
@ -359,10 +359,9 @@ def setup_database():
|
|||||||
from app.database.db import init_db, dependencies_available
|
from app.database.db import init_db, dependencies_available
|
||||||
if dependencies_available():
|
if dependencies_available():
|
||||||
init_db()
|
init_db()
|
||||||
if args.disable_assets_autoscan:
|
if args.enable_assets:
|
||||||
asset_seeder.disable()
|
if asset_seeder.start(roots=("models", "input", "output"), prune_first=True, compute_hashes=True):
|
||||||
elif asset_seeder.start(roots=("models", "input", "output"), prune_first=True, compute_hashes=True):
|
logging.info("Background asset scan initiated for models, input, output")
|
||||||
logging.info("Background asset scan initiated for models, input, output")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Failed to initialize database. Please ensure you have installed the latest requirements. If the error persists, please report this as in future the database will be required: {e}")
|
logging.error(f"Failed to initialize database. Please ensure you have installed the latest requirements. If the error persists, please report this as in future the database will be required: {e}")
|
||||||
|
|
||||||
|
|||||||
@ -239,7 +239,8 @@ class PromptServer():
|
|||||||
else args.front_end_root
|
else args.front_end_root
|
||||||
)
|
)
|
||||||
logging.info(f"[Prompt Server] web root: {self.web_root}")
|
logging.info(f"[Prompt Server] web root: {self.web_root}")
|
||||||
register_assets_system(self.app, self.user_manager)
|
if args.enable_assets:
|
||||||
|
register_assets_system(self.app, self.user_manager)
|
||||||
routes = web.RouteTableDef()
|
routes = web.RouteTableDef()
|
||||||
self.routes = routes
|
self.routes = routes
|
||||||
self.last_node_id = None
|
self.last_node_id = None
|
||||||
|
|||||||
@ -108,7 +108,7 @@ def comfy_url_and_proc(comfy_tmp_base_dir: Path, request: pytest.FixtureRequest)
|
|||||||
"main.py",
|
"main.py",
|
||||||
f"--base-directory={str(comfy_tmp_base_dir)}",
|
f"--base-directory={str(comfy_tmp_base_dir)}",
|
||||||
f"--database-url={db_url}",
|
f"--database-url={db_url}",
|
||||||
"--disable-assets-autoscan",
|
"--enable-assets",
|
||||||
"--listen",
|
"--listen",
|
||||||
"127.0.0.1",
|
"127.0.0.1",
|
||||||
"--port",
|
"--port",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user