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
592b377a
Commit
592b377a
authored
Mar 03, 2023
by
pythongosssss
Browse files
Added dynamic loading of extensions
parent
c23af92b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
13 deletions
+34
-13
server.py
server.py
+6
-0
web/extensions/logging.js.example
web/extensions/logging.js.example
+1
-0
web/index.html
web/index.html
+0
-3
web/scripts/api.js
web/scripts/api.js
+9
-0
web/scripts/app.js
web/scripts/app.js
+18
-10
No files found.
server.py
View file @
592b377a
...
@@ -5,6 +5,7 @@ import nodes
...
@@ -5,6 +5,7 @@ import nodes
import
execution
import
execution
import
uuid
import
uuid
import
json
import
json
import
glob
try
:
try
:
import
aiohttp
import
aiohttp
...
@@ -52,6 +53,11 @@ class PromptServer():
...
@@ -52,6 +53,11 @@ class PromptServer():
async
def
get_root
(
request
):
async
def
get_root
(
request
):
return
web
.
FileResponse
(
os
.
path
.
join
(
self
.
web_root
,
"index.html"
))
return
web
.
FileResponse
(
os
.
path
.
join
(
self
.
web_root
,
"index.html"
))
@
routes
.
get
(
"/extensions"
)
async
def
get_extensions
(
request
):
files
=
glob
.
glob
(
os
.
path
.
join
(
self
.
web_root
,
'extensions/**/*.js'
),
recursive
=
True
)
return
web
.
json_response
(
list
(
map
(
lambda
f
:
"/"
+
os
.
path
.
relpath
(
f
,
self
.
web_root
).
replace
(
"
\\
"
,
"/"
),
files
)))
@
routes
.
get
(
"/view/{file}"
)
@
routes
.
get
(
"/view/{file}"
)
async
def
view_image
(
request
):
async
def
view_image
(
request
):
if
"file"
in
request
.
match_info
:
if
"file"
in
request
.
match_info
:
...
...
web/extensions/logging.js.example
View file @
592b377a
import { app } from "../scripts/app.js";
import { app } from "../scripts/app.js";
const ext = {
const ext = {
// Unique name for the extension
name: "Example.LoggingExtension",
name: "Example.LoggingExtension",
async init(app) {
async init(app) {
// Any initial setup to run as soon as the page loads
// Any initial setup to run as soon as the page loads
...
...
web/index.html
View file @
592b377a
...
@@ -6,9 +6,6 @@
...
@@ -6,9 +6,6 @@
<script
type=
"text/javascript"
src=
"lib/litegraph.core.js"
></script>
<script
type=
"text/javascript"
src=
"lib/litegraph.core.js"
></script>
<script
type=
"module"
>
<script
type=
"module"
>
import
"
/extensions/core/dynamicPrompts.js
"
;
import
"
/extensions/core/rerouteNode.js
"
;
import
{
app
}
from
"
/scripts/app.js
"
;
import
{
app
}
from
"
/scripts/app.js
"
;
await
app
.
setup
();
await
app
.
setup
();
window
.
app
=
app
;
window
.
app
=
app
;
...
...
web/scripts/api.js
View file @
592b377a
...
@@ -88,6 +88,15 @@ class ComfyApi extends EventTarget {
...
@@ -88,6 +88,15 @@ class ComfyApi extends EventTarget {
this
.
#
createSocket
();
this
.
#
createSocket
();
}
}
/**
* Gets a list of extension urls
* @returns An array of script urls to import
*/
async
getExtensions
()
{
const
resp
=
await
fetch
(
"
/extensions
"
,
{
cache
:
"
no-store
"
});
return
await
resp
.
json
();
}
/**
/**
* Loads node object definitions for the graph
* Loads node object definitions for the graph
* @returns The node definitions
* @returns The node definitions
...
...
web/scripts/app.js
View file @
592b377a
...
@@ -11,14 +11,6 @@ class ComfyApp {
...
@@ -11,14 +11,6 @@ class ComfyApp {
this
.
nodeOutputs
=
{};
this
.
nodeOutputs
=
{};
}
}
#
log
(
message
,
...
other
)
{
console
.
log
(
"
[comfy]
"
,
message
,
...
other
);
}
#
error
(
message
,
...
other
)
{
console
.
error
(
"
[comfy]
"
,
message
,
...
other
);
}
/**
/**
* Invoke an extension callback
* Invoke an extension callback
* @param {string} method The extension callback to execute
* @param {string} method The extension callback to execute
...
@@ -32,7 +24,7 @@ class ComfyApp {
...
@@ -32,7 +24,7 @@ class ComfyApp {
try
{
try
{
results
.
push
(
ext
[
method
](...
args
,
this
));
results
.
push
(
ext
[
method
](...
args
,
this
));
}
catch
(
error
)
{
}
catch
(
error
)
{
this
.
#
error
(
console
.
error
(
`Error calling extension '
${
ext
.
name
}
' method '
${
method
}
'`
,
`Error calling extension '
${
ext
.
name
}
' method '
${
method
}
'`
,
{
error
},
{
error
},
{
extension
:
ext
},
{
extension
:
ext
},
...
@@ -58,7 +50,7 @@ class ComfyApp {
...
@@ -58,7 +50,7 @@ class ComfyApp {
try
{
try
{
return
await
ext
[
method
](...
args
,
this
);
return
await
ext
[
method
](...
args
,
this
);
}
catch
(
error
)
{
}
catch
(
error
)
{
this
.
#
error
(
console
.
error
(
`Error calling extension '
${
ext
.
name
}
' method '
${
method
}
'`
,
`Error calling extension '
${
ext
.
name
}
' method '
${
method
}
'`
,
{
error
},
{
error
},
{
extension
:
ext
},
{
extension
:
ext
},
...
@@ -413,10 +405,26 @@ class ComfyApp {
...
@@ -413,10 +405,26 @@ class ComfyApp {
api
.
init
();
api
.
init
();
}
}
/**
* Loads all extensions from the API into the window
*/
async
#
loadExtensions
()
{
const
extensions
=
await
api
.
getExtensions
();
for
(
const
ext
of
extensions
)
{
try
{
await
import
(
ext
);
}
catch
(
error
)
{
console
.
error
(
"
Error loading extension
"
,
ext
,
error
);
}
}
}
/**
/**
* Set up the app on the page
* Set up the app on the page
*/
*/
async
setup
()
{
async
setup
()
{
await
this
.
#
loadExtensions
();
// Create and mount the LiteGraph in the DOM
// Create and mount the LiteGraph in the DOM
const
canvasEl
=
Object
.
assign
(
document
.
createElement
(
"
canvas
"
),
{
id
:
"
graph-canvas
"
});
const
canvasEl
=
Object
.
assign
(
document
.
createElement
(
"
canvas
"
),
{
id
:
"
graph-canvas
"
});
document
.
body
.
prepend
(
canvasEl
);
document
.
body
.
prepend
(
canvasEl
);
...
...
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