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
72e3feb5
Unverified
Commit
72e3feb5
authored
Nov 09, 2023
by
pythongosssss
Committed by
GitHub
Nov 09, 2023
Browse files
Load API JSON (#1932)
* added loading api json * revert async change * reorder
parent
cd6df8b3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
9 deletions
+60
-9
web/scripts/app.js
web/scripts/app.js
+60
-9
No files found.
web/scripts/app.js
View file @
72e3feb5
...
...
@@ -1469,6 +1469,17 @@ export class ComfyApp {
localStorage
.
setItem
(
"
litegrapheditor_clipboard
"
,
old
);
}
showMissingNodesError
(
missingNodeTypes
,
hasAddedNodes
=
true
)
{
this
.
ui
.
dialog
.
show
(
`When loading the graph, the following node types were not found: <ul>
${
Array
.
from
(
new
Set
(
missingNodeTypes
)).
map
(
(
t
)
=>
`<li>
${
t
}
</li>`
).
join
(
""
)}
</ul>
${
hasAddedNodes
?
"
Nodes that have failed to load will show as red on the graph.
"
:
""
}
`
);
this
.
logging
.
addEntry
(
"
Comfy.App
"
,
"
warn
"
,
{
MissingNodes
:
missingNodeTypes
,
});
}
/**
* Populates the graph with the specified workflow data
* @param {*} graphData A serialized graph object
...
...
@@ -1587,14 +1598,7 @@ export class ComfyApp {
}
if
(
missingNodeTypes
.
length
)
{
this
.
ui
.
dialog
.
show
(
`When loading the graph, the following node types were not found: <ul>
${
Array
.
from
(
new
Set
(
missingNodeTypes
)).
map
(
(
t
)
=>
`<li>
${
t
}
</li>`
).
join
(
""
)}
</ul>Nodes that have failed to load will show as red on the graph.`
);
this
.
logging
.
addEntry
(
"
Comfy.App
"
,
"
warn
"
,
{
MissingNodes
:
missingNodeTypes
,
});
this
.
showMissingNodesError
(
missingNodeTypes
);
}
}
...
...
@@ -1825,9 +1829,11 @@ export class ComfyApp {
}
else
if
(
file
.
type
===
"
application/json
"
||
file
.
name
?.
endsWith
(
"
.json
"
))
{
const
reader
=
new
FileReader
();
reader
.
onload
=
()
=>
{
var
jsonContent
=
JSON
.
parse
(
reader
.
result
);
const
jsonContent
=
JSON
.
parse
(
reader
.
result
);
if
(
jsonContent
?.
templates
)
{
this
.
loadTemplateData
(
jsonContent
);
}
else
if
(
this
.
isApiJson
(
jsonContent
))
{
this
.
loadApiJson
(
jsonContent
);
}
else
{
this
.
loadGraphData
(
jsonContent
);
}
...
...
@@ -1841,6 +1847,51 @@ export class ComfyApp {
}
}
isApiJson
(
data
)
{
return
Object
.
values
(
data
).
every
((
v
)
=>
v
.
class_type
);
}
loadApiJson
(
apiData
)
{
const
missingNodeTypes
=
Object
.
values
(
apiData
).
filter
((
n
)
=>
!
LiteGraph
.
registered_node_types
[
n
.
class_type
]);
if
(
missingNodeTypes
.
length
)
{
this
.
showMissingNodesError
(
missingNodeTypes
.
map
(
t
=>
t
.
class_type
),
false
);
return
;
}
const
ids
=
Object
.
keys
(
apiData
);
app
.
graph
.
clear
();
for
(
const
id
of
ids
)
{
const
data
=
apiData
[
id
];
const
node
=
LiteGraph
.
createNode
(
data
.
class_type
);
node
.
id
=
id
;
graph
.
add
(
node
);
}
for
(
const
id
of
ids
)
{
const
data
=
apiData
[
id
];
const
node
=
app
.
graph
.
getNodeById
(
id
);
for
(
const
input
in
data
.
inputs
??
{})
{
const
value
=
data
.
inputs
[
input
];
if
(
value
instanceof
Array
)
{
const
[
fromId
,
fromSlot
]
=
value
;
const
fromNode
=
app
.
graph
.
getNodeById
(
fromId
);
const
toSlot
=
node
.
inputs
?.
findIndex
((
inp
)
=>
inp
.
name
===
input
);
if
(
toSlot
!==
-
1
)
{
fromNode
.
connect
(
fromSlot
,
node
,
toSlot
);
}
}
else
{
const
widget
=
node
.
widgets
?.
find
((
w
)
=>
w
.
name
===
input
);
if
(
widget
)
{
widget
.
value
=
value
;
widget
.
callback
?.(
value
);
}
}
}
}
app
.
graph
.
arrange
();
}
/**
* Registers a Comfy web extension with the app
* @param {ComfyExtension} extension
...
...
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