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
907c9fbf
"...ldm/git@developer.sourcefind.cn:chenpangpang/ComfyUI.git" did not exist on "809bcc8cebba6d53565fd6acaac4dd0314054373"
Commit
907c9fbf
authored
Jul 14, 2023
by
comfyanonymous
Browse files
Refactor to make it easier to set the api path.
parent
30ea1871
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
16 deletions
+29
-16
web/extensions/core/maskeditor.js
web/extensions/core/maskeditor.js
+4
-3
web/scripts/api.js
web/scripts/api.js
+19
-9
web/scripts/app.js
web/scripts/app.js
+2
-2
web/scripts/widgets.js
web/scripts/widgets.js
+4
-2
No files found.
web/extensions/core/maskeditor.js
View file @
907c9fbf
import
{
app
}
from
"
../../scripts/app.js
"
;
import
{
app
}
from
"
../../scripts/app.js
"
;
import
{
ComfyDialog
,
$el
}
from
"
../../scripts/ui.js
"
;
import
{
ComfyDialog
,
$el
}
from
"
../../scripts/ui.js
"
;
import
{
ComfyApp
}
from
"
../../scripts/app.js
"
;
import
{
ComfyApp
}
from
"
../../scripts/app.js
"
;
import
{
ClipspaceDialog
}
from
"
../../extensions/core/clipspace.js
"
;
import
{
api
}
from
"
../../scripts/api.js
"
import
{
ClipspaceDialog
}
from
"
./clipspace.js
"
;
// Helper function to convert a data URL to a Blob object
// Helper function to convert a data URL to a Blob object
function
dataURLToBlob
(
dataURL
)
{
function
dataURLToBlob
(
dataURL
)
{
...
@@ -33,7 +34,7 @@ function loadedImageToBlob(image) {
...
@@ -33,7 +34,7 @@ function loadedImageToBlob(image) {
}
}
async
function
uploadMask
(
filepath
,
formData
)
{
async
function
uploadMask
(
filepath
,
formData
)
{
await
fetch
(
'
.
/upload/mask
'
,
{
await
api
.
fetch
Api
(
'
/upload/mask
'
,
{
method
:
'
POST
'
,
method
:
'
POST
'
,
body
:
formData
body
:
formData
}).
then
(
response
=>
{}).
catch
(
error
=>
{
}).
then
(
response
=>
{}).
catch
(
error
=>
{
...
@@ -41,7 +42,7 @@ async function uploadMask(filepath, formData) {
...
@@ -41,7 +42,7 @@ async function uploadMask(filepath, formData) {
});
});
ComfyApp
.
clipspace
.
imgs
[
ComfyApp
.
clipspace
[
'
selectedIndex
'
]]
=
new
Image
();
ComfyApp
.
clipspace
.
imgs
[
ComfyApp
.
clipspace
[
'
selectedIndex
'
]]
=
new
Image
();
ComfyApp
.
clipspace
.
imgs
[
ComfyApp
.
clipspace
[
'
selectedIndex
'
]].
src
=
"
.
/view?
"
+
new
URLSearchParams
(
filepath
).
toString
()
+
app
.
getPreviewFormatParam
();
ComfyApp
.
clipspace
.
imgs
[
ComfyApp
.
clipspace
[
'
selectedIndex
'
]].
src
=
api
.
apiURL
(
"
/view?
"
+
new
URLSearchParams
(
filepath
).
toString
()
+
app
.
getPreviewFormatParam
()
)
;
if
(
ComfyApp
.
clipspace
.
images
)
if
(
ComfyApp
.
clipspace
.
images
)
ComfyApp
.
clipspace
.
images
[
ComfyApp
.
clipspace
[
'
selectedIndex
'
]]
=
filepath
;
ComfyApp
.
clipspace
.
images
[
ComfyApp
.
clipspace
[
'
selectedIndex
'
]]
=
filepath
;
...
...
web/scripts/api.js
View file @
907c9fbf
...
@@ -3,6 +3,16 @@ class ComfyApi extends EventTarget {
...
@@ -3,6 +3,16 @@ class ComfyApi extends EventTarget {
constructor
()
{
constructor
()
{
super
();
super
();
this
.
api_host
=
location
.
host
;
this
.
api_base
=
location
.
pathname
.
split
(
'
/
'
).
slice
(
0
,
-
1
).
join
(
'
/
'
);
}
apiURL
(
route
)
{
return
this
.
api_base
+
route
;
}
fetchApi
(
route
,
options
)
{
return
fetch
(
this
.
apiURL
(
route
),
options
);
}
}
addEventListener
(
type
,
callback
,
options
)
{
addEventListener
(
type
,
callback
,
options
)
{
...
@@ -16,7 +26,7 @@ class ComfyApi extends EventTarget {
...
@@ -16,7 +26,7 @@ class ComfyApi extends EventTarget {
#
pollQueue
()
{
#
pollQueue
()
{
setInterval
(
async
()
=>
{
setInterval
(
async
()
=>
{
try
{
try
{
const
resp
=
await
fetch
(
"
.
/prompt
"
);
const
resp
=
await
this
.
fetch
Api
(
"
/prompt
"
);
const
status
=
await
resp
.
json
();
const
status
=
await
resp
.
json
();
this
.
dispatchEvent
(
new
CustomEvent
(
"
status
"
,
{
detail
:
status
}));
this
.
dispatchEvent
(
new
CustomEvent
(
"
status
"
,
{
detail
:
status
}));
}
catch
(
error
)
{
}
catch
(
error
)
{
...
@@ -40,7 +50,7 @@ class ComfyApi extends EventTarget {
...
@@ -40,7 +50,7 @@ class ComfyApi extends EventTarget {
existingSession
=
"
?clientId=
"
+
existingSession
;
existingSession
=
"
?clientId=
"
+
existingSession
;
}
}
this
.
socket
=
new
WebSocket
(
this
.
socket
=
new
WebSocket
(
`ws
${
window
.
location
.
protocol
===
"
https:
"
?
"
s
"
:
""
}
://
${
location
.
host
}${
location
.
pathnam
e
}
ws
${
existingSession
}
`
`ws
${
window
.
location
.
protocol
===
"
https:
"
?
"
s
"
:
""
}
://
${
this
.
api_host
}${
this
.
api_bas
e
}
/
ws
${
existingSession
}
`
);
);
this
.
socket
.
binaryType
=
"
arraybuffer
"
;
this
.
socket
.
binaryType
=
"
arraybuffer
"
;
...
@@ -149,7 +159,7 @@ class ComfyApi extends EventTarget {
...
@@ -149,7 +159,7 @@ class ComfyApi extends EventTarget {
* @returns An array of script urls to import
* @returns An array of script urls to import
*/
*/
async
getExtensions
()
{
async
getExtensions
()
{
const
resp
=
await
fetch
(
"
.
/extensions
"
,
{
cache
:
"
no-store
"
});
const
resp
=
await
this
.
fetch
Api
(
"
/extensions
"
,
{
cache
:
"
no-store
"
});
return
await
resp
.
json
();
return
await
resp
.
json
();
}
}
...
@@ -158,7 +168,7 @@ class ComfyApi extends EventTarget {
...
@@ -158,7 +168,7 @@ class ComfyApi extends EventTarget {
* @returns An array of script urls to import
* @returns An array of script urls to import
*/
*/
async
getEmbeddings
()
{
async
getEmbeddings
()
{
const
resp
=
await
fetch
(
"
.
/embeddings
"
,
{
cache
:
"
no-store
"
});
const
resp
=
await
this
.
fetch
Api
(
"
/embeddings
"
,
{
cache
:
"
no-store
"
});
return
await
resp
.
json
();
return
await
resp
.
json
();
}
}
...
@@ -167,7 +177,7 @@ class ComfyApi extends EventTarget {
...
@@ -167,7 +177,7 @@ class ComfyApi extends EventTarget {
* @returns The node definitions
* @returns The node definitions
*/
*/
async
getNodeDefs
()
{
async
getNodeDefs
()
{
const
resp
=
await
fetch
(
"
.
/object_info
"
,
{
cache
:
"
no-store
"
});
const
resp
=
await
this
.
fetch
Api
(
"
/object_info
"
,
{
cache
:
"
no-store
"
});
return
await
resp
.
json
();
return
await
resp
.
json
();
}
}
...
@@ -189,7 +199,7 @@ class ComfyApi extends EventTarget {
...
@@ -189,7 +199,7 @@ class ComfyApi extends EventTarget {
body
.
number
=
number
;
body
.
number
=
number
;
}
}
const
res
=
await
fetch
(
"
.
/prompt
"
,
{
const
res
=
await
this
.
fetch
Api
(
"
/prompt
"
,
{
method
:
"
POST
"
,
method
:
"
POST
"
,
headers
:
{
headers
:
{
"
Content-Type
"
:
"
application/json
"
,
"
Content-Type
"
:
"
application/json
"
,
...
@@ -224,7 +234,7 @@ class ComfyApi extends EventTarget {
...
@@ -224,7 +234,7 @@ class ComfyApi extends EventTarget {
*/
*/
async
getQueue
()
{
async
getQueue
()
{
try
{
try
{
const
res
=
await
fetch
(
"
.
/queue
"
);
const
res
=
await
this
.
fetch
Api
(
"
/queue
"
);
const
data
=
await
res
.
json
();
const
data
=
await
res
.
json
();
return
{
return
{
// Running action uses a different endpoint for cancelling
// Running action uses a different endpoint for cancelling
...
@@ -246,7 +256,7 @@ class ComfyApi extends EventTarget {
...
@@ -246,7 +256,7 @@ class ComfyApi extends EventTarget {
*/
*/
async
getHistory
()
{
async
getHistory
()
{
try
{
try
{
const
res
=
await
fetch
(
"
.
/history
"
);
const
res
=
await
this
.
fetch
Api
(
"
/history
"
);
return
{
History
:
Object
.
values
(
await
res
.
json
())
};
return
{
History
:
Object
.
values
(
await
res
.
json
())
};
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
error
(
error
);
console
.
error
(
error
);
...
@@ -261,7 +271,7 @@ class ComfyApi extends EventTarget {
...
@@ -261,7 +271,7 @@ class ComfyApi extends EventTarget {
*/
*/
async
#
postItem
(
type
,
body
)
{
async
#
postItem
(
type
,
body
)
{
try
{
try
{
await
fetch
(
"
.
/
"
+
type
,
{
await
this
.
fetch
Api
(
"
/
"
+
type
,
{
method
:
"
POST
"
,
method
:
"
POST
"
,
headers
:
{
headers
:
{
"
Content-Type
"
:
"
application/json
"
,
"
Content-Type
"
:
"
application/json
"
,
...
...
web/scripts/app.js
View file @
907c9fbf
...
@@ -404,7 +404,7 @@ export class ComfyApp {
...
@@ -404,7 +404,7 @@ export class ComfyApp {
this
.
images
=
output
.
images
;
this
.
images
=
output
.
images
;
imagesChanged
=
true
;
imagesChanged
=
true
;
imgURLs
=
imgURLs
.
concat
(
output
.
images
.
map
(
params
=>
{
imgURLs
=
imgURLs
.
concat
(
output
.
images
.
map
(
params
=>
{
return
"
.
/view?
"
+
new
URLSearchParams
(
params
).
toString
()
+
app
.
getPreviewFormatParam
();
return
api
.
apiURL
(
"
/view?
"
+
new
URLSearchParams
(
params
).
toString
()
+
app
.
getPreviewFormatParam
()
)
;
}))
}))
}
}
}
}
...
@@ -1005,7 +1005,7 @@ export class ComfyApp {
...
@@ -1005,7 +1005,7 @@ export class ComfyApp {
const
extensions
=
await
api
.
getExtensions
();
const
extensions
=
await
api
.
getExtensions
();
for
(
const
ext
of
extensions
)
{
for
(
const
ext
of
extensions
)
{
try
{
try
{
await
import
(
"
..
"
+
ext
);
await
import
(
api
.
apiURL
(
ext
)
)
;
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
error
(
"
Error loading extension
"
,
ext
,
error
);
console
.
error
(
"
Error loading extension
"
,
ext
,
error
);
}
}
...
...
web/scripts/widgets.js
View file @
907c9fbf
import
{
api
}
from
"
./api.js
"
function
getNumberDefaults
(
inputData
,
defaultStep
)
{
function
getNumberDefaults
(
inputData
,
defaultStep
)
{
let
defaultVal
=
inputData
[
1
][
"
default
"
];
let
defaultVal
=
inputData
[
1
][
"
default
"
];
let
{
min
,
max
,
step
}
=
inputData
[
1
];
let
{
min
,
max
,
step
}
=
inputData
[
1
];
...
@@ -305,7 +307,7 @@ export const ComfyWidgets = {
...
@@ -305,7 +307,7 @@ export const ComfyWidgets = {
subfolder
=
name
.
substring
(
0
,
folder_separator
);
subfolder
=
name
.
substring
(
0
,
folder_separator
);
name
=
name
.
substring
(
folder_separator
+
1
);
name
=
name
.
substring
(
folder_separator
+
1
);
}
}
img
.
src
=
`
.
/view?filename=
${
name
}
&type=input&subfolder=
${
subfolder
}${
app
.
getPreviewFormatParam
()}
`
;
img
.
src
=
api
.
apiURL
(
`/view?filename=
${
name
}
&type=input&subfolder=
${
subfolder
}${
app
.
getPreviewFormatParam
()}
`
)
;
node
.
setSizeForImage
?.();
node
.
setSizeForImage
?.();
}
}
...
@@ -362,7 +364,7 @@ export const ComfyWidgets = {
...
@@ -362,7 +364,7 @@ export const ComfyWidgets = {
// Wrap file in formdata so it includes filename
// Wrap file in formdata so it includes filename
const
body
=
new
FormData
();
const
body
=
new
FormData
();
body
.
append
(
"
image
"
,
file
);
body
.
append
(
"
image
"
,
file
);
const
resp
=
await
fetch
(
"
.
/upload/image
"
,
{
const
resp
=
await
api
.
fetch
Api
(
"
/upload/image
"
,
{
method
:
"
POST
"
,
method
:
"
POST
"
,
body
,
body
,
});
});
...
...
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