Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
bc76b382
Commit
bc76b382
authored
Aug 21, 2023
by
comfyanonymous
Browse files
Merge branch 'custom-node-js' of
https://github.com/pythongosssss/ComfyUI
parents
199d7336
cdaf65ce
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
2 deletions
+31
-2
nodes.py
nodes.py
+11
-0
server.py
server.py
+20
-2
No files found.
nodes.py
View file @
bc76b382
...
@@ -1673,6 +1673,8 @@ NODE_DISPLAY_NAME_MAPPINGS = {
...
@@ -1673,6 +1673,8 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"VAEEncodeTiled"
:
"VAE Encode (Tiled)"
,
"VAEEncodeTiled"
:
"VAE Encode (Tiled)"
,
}
}
EXTENSION_WEB_DIRS
=
{}
def
load_custom_node
(
module_path
,
ignore
=
set
()):
def
load_custom_node
(
module_path
,
ignore
=
set
()):
module_name
=
os
.
path
.
basename
(
module_path
)
module_name
=
os
.
path
.
basename
(
module_path
)
if
os
.
path
.
isfile
(
module_path
):
if
os
.
path
.
isfile
(
module_path
):
...
@@ -1681,11 +1683,20 @@ def load_custom_node(module_path, ignore=set()):
...
@@ -1681,11 +1683,20 @@ def load_custom_node(module_path, ignore=set()):
try
:
try
:
if
os
.
path
.
isfile
(
module_path
):
if
os
.
path
.
isfile
(
module_path
):
module_spec
=
importlib
.
util
.
spec_from_file_location
(
module_name
,
module_path
)
module_spec
=
importlib
.
util
.
spec_from_file_location
(
module_name
,
module_path
)
module_dir
=
os
.
path
.
split
(
module_path
)[
0
]
else
:
else
:
module_spec
=
importlib
.
util
.
spec_from_file_location
(
module_name
,
os
.
path
.
join
(
module_path
,
"__init__.py"
))
module_spec
=
importlib
.
util
.
spec_from_file_location
(
module_name
,
os
.
path
.
join
(
module_path
,
"__init__.py"
))
module_dir
=
module_path
module
=
importlib
.
util
.
module_from_spec
(
module_spec
)
module
=
importlib
.
util
.
module_from_spec
(
module_spec
)
sys
.
modules
[
module_name
]
=
module
sys
.
modules
[
module_name
]
=
module
module_spec
.
loader
.
exec_module
(
module
)
module_spec
.
loader
.
exec_module
(
module
)
if
hasattr
(
module
,
"WEB_DIRECTORY"
)
and
getattr
(
module
,
"WEB_DIRECTORY"
)
is
not
None
:
web_dir
=
os
.
path
.
abspath
(
os
.
path
.
join
(
module_dir
,
getattr
(
module
,
"WEB_DIRECTORY"
)))
if
os
.
path
.
isdir
(
web_dir
):
EXTENSION_WEB_DIRS
[
module_name
]
=
web_dir
if
hasattr
(
module
,
"NODE_CLASS_MAPPINGS"
)
and
getattr
(
module
,
"NODE_CLASS_MAPPINGS"
)
is
not
None
:
if
hasattr
(
module
,
"NODE_CLASS_MAPPINGS"
)
and
getattr
(
module
,
"NODE_CLASS_MAPPINGS"
)
is
not
None
:
for
name
in
module
.
NODE_CLASS_MAPPINGS
:
for
name
in
module
.
NODE_CLASS_MAPPINGS
:
if
name
not
in
ignore
:
if
name
not
in
ignore
:
...
...
server.py
View file @
bc76b382
...
@@ -5,6 +5,7 @@ import nodes
...
@@ -5,6 +5,7 @@ import nodes
import
folder_paths
import
folder_paths
import
execution
import
execution
import
uuid
import
uuid
import
urllib
import
json
import
json
import
glob
import
glob
import
struct
import
struct
...
@@ -67,6 +68,8 @@ class PromptServer():
...
@@ -67,6 +68,8 @@ class PromptServer():
mimetypes
.
init
()
mimetypes
.
init
()
mimetypes
.
types_map
[
'.js'
]
=
'application/javascript; charset=utf-8'
mimetypes
.
types_map
[
'.js'
]
=
'application/javascript; charset=utf-8'
self
.
supports
=
[
"custom_nodes_from_web"
]
self
.
prompt_queue
=
None
self
.
prompt_queue
=
None
self
.
loop
=
loop
self
.
loop
=
loop
self
.
messages
=
asyncio
.
Queue
()
self
.
messages
=
asyncio
.
Queue
()
...
@@ -123,8 +126,17 @@ class PromptServer():
...
@@ -123,8 +126,17 @@ class PromptServer():
@
routes
.
get
(
"/extensions"
)
@
routes
.
get
(
"/extensions"
)
async
def
get_extensions
(
request
):
async
def
get_extensions
(
request
):
files
=
glob
.
glob
(
os
.
path
.
join
(
self
.
web_root
,
'extensions/**/*.js'
),
recursive
=
True
)
files
=
glob
.
glob
(
os
.
path
.
join
(
return
web
.
json_response
(
list
(
map
(
lambda
f
:
"/"
+
os
.
path
.
relpath
(
f
,
self
.
web_root
).
replace
(
"
\\
"
,
"/"
),
files
)))
self
.
web_root
,
'extensions/**/*.js'
),
recursive
=
True
)
extensions
=
list
(
map
(
lambda
f
:
"/"
+
os
.
path
.
relpath
(
f
,
self
.
web_root
).
replace
(
"
\\
"
,
"/"
),
files
))
for
name
,
dir
in
nodes
.
EXTENSION_WEB_DIRS
.
items
():
files
=
glob
.
glob
(
os
.
path
.
join
(
dir
,
'**/*.js'
),
recursive
=
True
)
extensions
.
extend
(
list
(
map
(
lambda
f
:
"/extensions/"
+
urllib
.
parse
.
quote
(
name
)
+
"/"
+
os
.
path
.
relpath
(
f
,
dir
).
replace
(
"
\\
"
,
"/"
),
files
)))
return
web
.
json_response
(
extensions
)
def
get_dir_by_type
(
dir_type
):
def
get_dir_by_type
(
dir_type
):
if
dir_type
is
None
:
if
dir_type
is
None
:
...
@@ -492,6 +504,12 @@ class PromptServer():
...
@@ -492,6 +504,12 @@ class PromptServer():
def
add_routes
(
self
):
def
add_routes
(
self
):
self
.
app
.
add_routes
(
self
.
routes
)
self
.
app
.
add_routes
(
self
.
routes
)
for
name
,
dir
in
nodes
.
EXTENSION_WEB_DIRS
.
items
():
self
.
app
.
add_routes
([
web
.
static
(
'/extensions/'
+
urllib
.
parse
.
quote
(
name
),
dir
,
follow_symlinks
=
True
),
])
self
.
app
.
add_routes
([
self
.
app
.
add_routes
([
web
.
static
(
'/'
,
self
.
web_root
,
follow_symlinks
=
True
),
web
.
static
(
'/'
,
self
.
web_root
,
follow_symlinks
=
True
),
])
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment