Files
talesofai-comfyui-browser/__init__.py
T
Logan Barnett e406d40ad6 read paths from configuration file
This updates the automatic path detection to use a configuration file
_optionally_ as a means of overriding the paths used by
`comfyui-browser`.  This change is motivated by recent work I have done
with ComfyUI and Nix, wherein I provided [an easy means to install
`comfyui-browser` via
Nix](https://github.com/loganbarnett/dotfiles/blob/ccbfe12e755ab3d6d24b3f0f5a3386208b23357f/nix/hacks/comfyui/custom-nodes.nix#L50-L74).
The big reason this was necessary for my Nix work is because Nix's
installations are locked down into a purely read-only store.  I needed a
place to put things such as the `collections` path into a location that
`comfyui-browser` could write to.

I don't expect `comfyui-browser` to directly support Nix. My hope is
that allowing the directories to be configurable, with the defaults
being exactly what was used to before, to be something desirable for the
project in a general sense, and not just for Nix.

I've tested this under a Nix configuration with `config.json` values
being used.  Unfortunately I don't have a means to test
`comfyui-browser` outside of Nix, as the `comfyui` and CUDA setup was
hard enough with Nix itself.  So to be clear - this isn't tested under
the standard configuration that most `comfyui-browser` users are using.
I suggest giving these changes a quick spin to make sure I didn't miss
anything.  I did my best to make the code changes branchless - in that
no new code paths are added - just a default means of determining what
the configuration values should be.  Memoization is used to ensure that
the order in which these functions are called is irrelevant.

Unfortunately I am not familiar at all with Chinese/Mandarin(?) to write
the documentation for it - perhaps someone else can pick that up?

Earmarked as part of this:  I've changed the `mkdir` calls to
`makedirs`, which adds all directories in the chain that are missing,
and the `exist_ok` argument means the call will not fail if the
directory already exists, which allows us to clean up a little code.

Thanks for your work on maintaining this useful custom nodes project!
2024-04-22 16:09:34 -07:00

61 lines
2.4 KiB
Python

import os
from aiohttp import web
import server
from .utils import collections_path, browser_path, sources_path, download_logs_path, outputs_path
from .routes import sources, collections, config, files, downloads, xyz_plot as xyz_plot_routes
from .nodes import select_inputs, load_image_by_url, xyz_plot, dify_text_generator, upload_to_remote
browser_app = web.Application()
browser_app.add_routes([
web.get("/files", files.api_get_files),
web.delete("/files", files.api_delete_file),
web.put("/files", files.api_update_file),
web.get("/files/view", files.api_view_file),
web.post("/collections", collections.api_add_to_collections),
web.post("/collections/workflows", collections.api_create_new_workflow),
web.post("/collections/sync", collections.api_sync_my_collections),
web.get("/sources", sources.api_get_sources),
web.post("/sources", sources.api_create_source),
web.delete("/sources/{name}", sources.api_delete_source),
web.post("/sources/sync/{name}", sources.api_sync_source),
web.get("/sources/all", sources.api_get_all_sources),
web.get("/config", config.api_get_browser_config),
web.put("/config", config.api_update_browser_config),
web.post("/downloads", downloads.api_create_new_download),
web.get("/downloads", downloads.api_list_downloads),
web.get("/downloads/{uuid}", downloads.api_show_download),
web.put("/xyz_plot/score", xyz_plot_routes.api_update_score),
web.get("/xyz_plot/statistic", xyz_plot_routes.api_get_score_statistic),
web.static("/web", os.path.join(browser_path, 'web/build')),
web.static("/s/outputs", outputs_path()),
web.static("/s/collections", collections_path()),
web.static("/s/sources", sources_path()),
])
server.PromptServer.instance.app.add_subapp("/browser/", browser_app)
WEB_DIRECTORY = "web"
NODE_CLASS_MAPPINGS = {
"LoadImageByUrl //Browser": load_image_by_url.LoadImageByUrl,
"SelectInputs //Browser": select_inputs.SelectInputs,
"XyzPlot //Browser": xyz_plot.XyzPlot,
"DifyTextGenerator //Browser": dify_text_generator.DifyTextGenerator,
"UploadToRemote //Browser": upload_to_remote.UploadToRemote,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"LoadImageByUrl //Browser": "Load Image By URL",
"SelectInputs //Browser": "Select Node Inputs",
"XyzPlot //Browser": "XYZ Plot",
"DifyTextGenerator //Browser": "Dify Text Generator",
"UploadToRemote //Browser": "Upload To Remote",
}