@ -9,6 +9,29 @@ export const SUPPORTED_OUTPUT_NODE_TYPES = [
"ADE_AnimateDiffCombine" ,
"ADE_AnimateDiffCombine" ,
]
]
var docStyle = document . createElement ( 'style' ) ;
docStyle . innerHTML = `
. cm - menu - container {
column - gap : 20 px ;
display : flex ;
flex - wrap : wrap ;
justify - content : center ;
}
. cm - menu - column {
display : flex ;
flex - direction : column ;
}
. cm - title {
padding : 10 px 10 px 0 10 p ;
background - color : black ;
text - align : center ;
height : 45 px ;
}
` ;
document . head . appendChild ( docStyle ) ;
export function getPotentialOutputsAndOutputNodes ( nodes ) {
export function getPotentialOutputsAndOutputNodes ( nodes ) {
const potential _outputs = [ ] ;
const potential _outputs = [ ] ;
const potential _output _nodes = [ ] ;
const potential _output _nodes = [ ] ;
@ -59,7 +82,7 @@ export function getPotentialOutputsAndOutputNodes(nodes) {
if ( parsedURLVals . type !== "output" ) {
if ( parsedURLVals . type !== "output" ) {
// TODO
// TODO
}
}
potential _outputs . push ( { "type" : "output" , 'title' : node . title , "output" : { "filename" : parsedURLVals . filename , "subfolder" : parsedURLVals . subfolder , "value" : widgetValue , "format" : parsedURLVals . format } } ) ;
potential _outputs . push ( { "type" : "output" , 'title' : node . title , "output" : { "filename" : parsedURLVals . filename , "subfolder" : parsedURLVals . subfolder , "value" : widgetValue , "format" : parsedURLVals . format } } ) ;
}
}
}
}
}
}
@ -81,7 +104,7 @@ export function getPotentialOutputsAndOutputNodes(nodes) {
// TODO
// TODO
continue ;
continue ;
}
}
potential _outputs . push ( { "type" : "output" , 'title' : node . title , "output" : { "filename" : parsedURLVals . filename , "subfolder" : parsedURLVals . subfolder , "type" : parsedURLVals . type , "value" : widgetValue , "format" : parsedURLVals . format } } ) ;
potential _outputs . push ( { "type" : "output" , 'title' : node . title , "output" : { "filename" : parsedURLVals . filename , "subfolder" : parsedURLVals . subfolder , "type" : parsedURLVals . type , "value" : widgetValue , "format" : parsedURLVals . format } } ) ;
}
}
}
}
}
}
@ -178,163 +201,61 @@ export class ShareDialog extends ComfyDialog {
this . share _button = $el ( "button" , {
this . share _button = $el ( "button" , {
type : "submit" ,
type : "submit" ,
textContent : "Share" ,
textContent : "Share" ,
} , [ ] ) ;
style : {
backgroundColor : "blue"
this . final _message = $el ( "div" , { } , [ ] ) ;
// get the user's existing matrix auth and share key
ShareDialog . matrix _auth = { homeserver : "matrix.org" , username : "" , password : "" } ;
try {
api . fetchApi ( ` /manager/get_matrix_auth ` )
. then ( response => response . json ( ) )
. then ( data => {
ShareDialog . matrix _auth = data ;
this . matrix _homeserver _input . value = ShareDialog . matrix _auth . homeserver ;
this . matrix _username _input . value = ShareDialog . matrix _auth . username ;
this . matrix _password _input . value = ShareDialog . matrix _auth . password ;
} )
. catch ( error => {
// console.log(error);
} ) ;
} catch ( error ) {
// console.log(error);
}
// get the user's existing comfyworkflows share key
ShareDialog . cw _sharekey = "" ;
try {
// console.log("Fetching comfyworkflows share key")
api . fetchApi ( ` /manager/get_comfyworkflows_auth ` )
. then ( response => response . json ( ) )
. then ( data => {
ShareDialog . cw _sharekey = data . comfyworkflows _sharekey ;
this . cw _sharekey _input . value = ShareDialog . cw _sharekey ;
} )
. catch ( error => {
// console.log(error);
} ) ;
} catch ( error ) {
// console.log(error);
}
this . share _button . onclick = async ( ) => {
const prompt = await app . graphToPrompt ( ) ;
const nodes = app . graph . _nodes ;
// console.log({ prompt, nodes });
const destinations = [ ] ;
if ( this . matrix _destination _checkbox . checked ) {
destinations . push ( "matrix" ) ;
}
if ( this . comfyworkflows _destination _checkbox . checked ) {
destinations . push ( "comfyworkflows" ) ;
}
// if destinations includes matrix, make an api call to /manager/check_matrix to ensure that the user has configured their matrix settings
if ( destinations . includes ( "matrix" ) ) {
let definedMatrixAuth = ! ! this . matrix _homeserver _input . value && ! ! this . matrix _username _input . value && ! ! this . matrix _password _input . value ;
if ( ! definedMatrixAuth ) {
alert ( "Please set your Matrix account details." ) ;
return ;
}
}
}
} , [ ] ) ;
if ( destinations . includes ( "comfyworkflows" ) && ! this . cw _sharekey _input . value && ! confirm ( "You have NOT set your ComfyWorkflows.com share key. Your art will NOT be connected to your account (it will be shared anonymously). Continue?" ) ) {
this . final _message = $el ( "div" , {
return ;
style : {
color : "white" ,
textAlign : "center" ,
// marginTop: "10px",
// backgroundColor: "black",
padding : "10px" ,
}
}
} , [ ] ) ;
const { potential _outputs , potential _output _nodes } = getPotentialOutputsAndOutputNodes ( nodes ) ;
this . share _finalmessage _container = $el ( "div.cm-menu-container" , {
id : "comfyui-share-finalmessage-container" ,
// console.log({ potential_outputs, potential_output_nodes })
style : {
display : "none" ,
if ( potential _outputs . length === 0 ) {
if ( potential _output _nodes . length === 0 ) {
// todo: add support for other output node types (animatediff combine, etc.)
const supported _nodes _string = SUPPORTED _OUTPUT _NODE _TYPES . join ( ", " ) ;
alert ( ` No supported output node found ( ${ supported _nodes _string } ). To share this workflow, please add an output node to your graph and re-run your prompt. ` ) ;
} else {
alert ( "To share this, first run a prompt. Once it's done, click 'Share'." ) ;
}
this . selectedOutputIndex = 0 ;
this . close ( ) ;
return ;
}
}
} , [
$el ( "div.cm-menu-column" , [
this . final _message ,
$el ( "button" , {
type : "button" ,
textContent : "Close" ,
onclick : ( ) => {
// Reset state
this . matrix _destination _checkbox . checked = false ;
this . comfyworkflows _destination _checkbox . checked = true ;
this . share _button . textContent = "Share" ;
this . share _button . style . display = "inline-block" ;
this . final _message . innerHTML = "" ;
this . final _message . style . color = "white" ;
this . credits _input . value = "" ;
this . title _input . value = "" ;
this . description _input . value = "" ;
this . is _nsfw _checkbox . checked = false ;
this . selectedOutputIndex = 0 ;
// Change the text of the share button to "Sharing..." to indicate that the share process has started
// hide the final message
this . share _button . textContent = "Sharing..." ;
this . share _finalmessage _container . style . display = "none" ;
const response = await api . fetchApi ( ` /manager/share ` , {
// show the share container
method : 'POST' ,
this . share _container . style . display = "flex" ;
headers : { 'Content-Type' : 'application/json' } ,
body : JSON . stringify ( {
matrix _auth : {
homeserver : this . matrix _homeserver _input . value ,
username : this . matrix _username _input . value ,
password : this . matrix _password _input . value ,
} ,
cw _auth : {
cw _sharekey : this . cw _sharekey _input . value ,
} ,
share _destinations : destinations ,
credits : this . credits _input . value ,
title : this . title _input . value ,
description : this . description _input . value ,
is _nsfw : this . is _nsfw _checkbox . checked ,
prompt ,
potential _outputs ,
selected _output _index : this . selectedOutputIndex ,
// potential_output_nodes
} )
} ) ;
if ( response . status != 200 ) {
this . close ( )
try {
const response _json = await response . json ( ) ;
if ( response _json . error ) {
alert ( response _json . error ) ;
this . close ( ) ;
return ;
} else {
alert ( "Failed to share your art. Please try again." ) ;
this . close ( ) ;
return ;
}
}
} catch ( e ) {
} ) ,
alert ( "Failed to share your art. Please try again." ) ;
] )
this . close ( ) ;
] ) ;
return ;
this . share _container = $el ( "div.cm-menu-container" , {
}
id : "comfyui-share-container"
}
} , [
$el ( "div.cm-menu-column" , [
const response _json = await response . json ( ) ;
if ( response _json . comfyworkflows . url ) {
this . final _message . innerHTML = "Your art has been shared: <a href='" + response _json . comfyworkflows . url + "' target='_blank'>" + response _json . comfyworkflows . url + "</a>" ;
if ( response _json . matrix . success ) {
this . final _message . innerHTML += "<br>Your art has been shared in the ComfyUI Matrix server's #share channel!" ;
}
} else {
if ( response _json . matrix . success ) {
this . final _message . innerHTML = "Your art has been shared in the ComfyUI Matrix server's #share channel!" ;
}
}
this . final _message . style . color = "green" ;
// hide the share button
this . share _button . textContent = "Shared!" ;
this . share _button . style . display = "none" ;
// this.close();
}
const res =
[
$el ( "tr.td" , { width : "100%" } , [
$el ( "font" , { size : 6 , color : "white" } , [ ` Share your art ` ] ) ,
] ) ,
$el ( "br" , { } , [ ] ) ,
$el ( "details" , {
$el ( "details" , {
style : {
style : {
border : "1px solid #999" ,
border : "1px solid #999" ,
@ -464,14 +385,15 @@ export class ShareDialog extends ComfyDialog {
$el ( "br" , { } , [ ] ) ,
$el ( "br" , { } , [ ] ) ,
$el ( "div" , { } , [ this . is _nsfw _checkbox , is _nsfw _checkbox _text ] ) ,
$el ( "div" , { } , [ this . is _nsfw _checkbox , is _nsfw _checkbox _text ] ) ,
$el ( "br" , { } , [ ] ) ,
// $el("br", {}, []),
// this.final_message,
// $el("br", {}, []),
] ) ,
$el ( "div.cm-menu-column" , [
this . radio _buttons ,
this . radio _buttons ,
$el ( "br" , { } , [ ] ) ,
$el ( "br" , { } , [ ] ) ,
this . final _message ,
$el ( "br" , { } , [ ] ) ,
this . share _button ,
this . share _button ,
$el ( "button" , {
$el ( "button" , {
@ -490,10 +412,179 @@ export class ShareDialog extends ComfyDialog {
this . description _input . value = "" ;
this . description _input . value = "" ;
this . is _nsfw _checkbox . checked = false ;
this . is _nsfw _checkbox . checked = false ;
this . selectedOutputIndex = 0 ;
this . selectedOutputIndex = 0 ;
// hide the final message
this . share _finalmessage _container . style . display = "none" ;
// show the share container
this . share _container . style . display = "flex" ;
this . close ( )
this . close ( )
}
}
} ) ,
} ) ,
$el ( "br" , { } , [ ] ) ,
$el ( "br" , { } , [ ] ) ,
] ) ,
] ) ;
// get the user's existing matrix auth and share key
ShareDialog . matrix _auth = { homeserver : "matrix.org" , username : "" , password : "" } ;
try {
api . fetchApi ( ` /manager/get_matrix_auth ` )
. then ( response => response . json ( ) )
. then ( data => {
ShareDialog . matrix _auth = data ;
this . matrix _homeserver _input . value = ShareDialog . matrix _auth . homeserver ;
this . matrix _username _input . value = ShareDialog . matrix _auth . username ;
this . matrix _password _input . value = ShareDialog . matrix _auth . password ;
} )
. catch ( error => {
// console.log(error);
} ) ;
} catch ( error ) {
// console.log(error);
}
// get the user's existing comfyworkflows share key
ShareDialog . cw _sharekey = "" ;
try {
// console.log("Fetching comfyworkflows share key")
api . fetchApi ( ` /manager/get_comfyworkflows_auth ` )
. then ( response => response . json ( ) )
. then ( data => {
ShareDialog . cw _sharekey = data . comfyworkflows _sharekey ;
this . cw _sharekey _input . value = ShareDialog . cw _sharekey ;
} )
. catch ( error => {
// console.log(error);
} ) ;
} catch ( error ) {
// console.log(error);
}
this . share _button . onclick = async ( ) => {
const prompt = await app . graphToPrompt ( ) ;
const nodes = app . graph . _nodes ;
// console.log({ prompt, nodes });
const destinations = [ ] ;
if ( this . matrix _destination _checkbox . checked ) {
destinations . push ( "matrix" ) ;
}
if ( this . comfyworkflows _destination _checkbox . checked ) {
destinations . push ( "comfyworkflows" ) ;
}
// if destinations includes matrix, make an api call to /manager/check_matrix to ensure that the user has configured their matrix settings
if ( destinations . includes ( "matrix" ) ) {
let definedMatrixAuth = ! ! this . matrix _homeserver _input . value && ! ! this . matrix _username _input . value && ! ! this . matrix _password _input . value ;
if ( ! definedMatrixAuth ) {
alert ( "Please set your Matrix account details." ) ;
return ;
}
}
if ( destinations . includes ( "comfyworkflows" ) && ! this . cw _sharekey _input . value && ! confirm ( "You have NOT set your ComfyWorkflows.com share key. Your art will NOT be connected to your account (it will be shared anonymously). Continue?" ) ) {
return ;
}
const { potential _outputs , potential _output _nodes } = getPotentialOutputsAndOutputNodes ( nodes ) ;
// console.log({ potential_outputs, potential_output_nodes })
if ( potential _outputs . length === 0 ) {
if ( potential _output _nodes . length === 0 ) {
// todo: add support for other output node types (animatediff combine, etc.)
const supported _nodes _string = SUPPORTED _OUTPUT _NODE _TYPES . join ( ", " ) ;
alert ( ` No supported output node found ( ${ supported _nodes _string } ). To share this workflow, please add an output node to your graph and re-run your prompt. ` ) ;
} else {
alert ( "To share this, first run a prompt. Once it's done, click 'Share'." ) ;
}
this . selectedOutputIndex = 0 ;
this . close ( ) ;
return ;
}
// Change the text of the share button to "Sharing..." to indicate that the share process has started
this . share _button . textContent = "Sharing..." ;
const response = await api . fetchApi ( ` /manager/share ` , {
method : 'POST' ,
headers : { 'Content-Type' : 'application/json' } ,
body : JSON . stringify ( {
matrix _auth : {
homeserver : this . matrix _homeserver _input . value ,
username : this . matrix _username _input . value ,
password : this . matrix _password _input . value ,
} ,
cw _auth : {
cw _sharekey : this . cw _sharekey _input . value ,
} ,
share _destinations : destinations ,
credits : this . credits _input . value ,
title : this . title _input . value ,
description : this . description _input . value ,
is _nsfw : this . is _nsfw _checkbox . checked ,
prompt ,
potential _outputs ,
selected _output _index : this . selectedOutputIndex ,
// potential_output_nodes
} )
} ) ;
if ( response . status != 200 ) {
try {
const response _json = await response . json ( ) ;
if ( response _json . error ) {
alert ( response _json . error ) ;
this . close ( ) ;
return ;
} else {
alert ( "Failed to share your art. Please try again." ) ;
this . close ( ) ;
return ;
}
} catch ( e ) {
alert ( "Failed to share your art. Please try again." ) ;
this . close ( ) ;
return ;
}
}
const response _json = await response . json ( ) ;
if ( response _json . comfyworkflows . url ) {
this . final _message . innerHTML = "Your art has been shared: <a href='" + response _json . comfyworkflows . url + "' target='_blank'>" + response _json . comfyworkflows . url + "</a>" ;
if ( response _json . matrix . success ) {
this . final _message . innerHTML += "<br>Your art has been shared in the ComfyUI Matrix server's #share channel!" ;
}
} else {
if ( response _json . matrix . success ) {
this . final _message . innerHTML = "Your art has been shared in the ComfyUI Matrix server's #share channel!" ;
}
}
this . final _message . style . color = "green" ;
// hide #comfyui-share-container and show #comfyui-share-finalmessage-container
this . share _container . style . display = "none" ;
this . share _finalmessage _container . style . display = "block" ;
// hide the share button
this . share _button . textContent = "Shared!" ;
this . share _button . style . display = "none" ;
// this.close();
}
const res =
[
$el ( "tr.td" , { width : "100%" } , [
$el ( "font" , { size : 6 , color : "white" } , [ ` Share your art ` ] ) ,
] ) ,
$el ( "br" , { } , [ ] ) ,
this . share _finalmessage _container ,
this . share _container ,
] ;
] ;
res [ 0 ] . style . padding = "10px 10px 10px 10px" ;
res [ 0 ] . style . padding = "10px 10px 10px 10px" ;
@ -509,7 +600,7 @@ export class ShareDialog extends ComfyDialog {
const new _radio _buttons = $el ( "div" , {
const new _radio _buttons = $el ( "div" , {
id : "selectOutput-Options" ,
id : "selectOutput-Options" ,
style : {
style : {
'overflow-y' : 'auto ' ,
'overflow-y' : 'scroll ' ,
'max-height' : '400px' ,
'max-height' : '400px' ,
}
}
} , potential _outputs . map ( ( output , index ) => {
} , potential _outputs . map ( ( output , index ) => {
@ -549,7 +640,7 @@ export class ShareDialog extends ComfyDialog {
}
}
} , [ radio _button , radio _button _text , radio _button _img ] ) ;
} , [ radio _button , radio _button _text , radio _button _img ] ) ;
} ) ) ;
} ) ) ;
const header = $el ( "h4 " , {
const header = $el ( "h3 " , {
textContent : "Select an image to share" ,
textContent : "Select an image to share" ,
size : 3 ,
size : 3 ,
color : "white" ,
color : "white" ,
@ -558,9 +649,24 @@ export class ShareDialog extends ComfyDialog {
color : 'white' ,
color : 'white' ,
backgroundColor : 'black' ,
backgroundColor : 'black' ,
padding : '10px' ,
padding : '10px' ,
'margin-top' : '0px' ,
}
}
} , [ ] ) ;
} , [
$el ( "p" , {
textContent : "Scroll to see all outputs" ,
size : 2 ,
color : "white" ,
style : {
'text-align' : 'center' ,
color : 'white' ,
'margin-bottom' : '5px' ,
'font-style' : 'italic' ,
'font-size' : '12px' ,
} ,
} , [ ] )
] ) ;
this . radio _buttons . appendChild ( header ) ;
this . radio _buttons . appendChild ( header ) ;
// this.radio_buttons.appendChild(subheader);
this . radio _buttons . appendChild ( new _radio _buttons ) ;
this . radio _buttons . appendChild ( new _radio _buttons ) ;
this . element . style . display = "block" ;
this . element . style . display = "block" ;
}
}