@ -2,7 +2,7 @@ import { app } from "../../scripts/app.js";
import { api } from "../../scripts/api.js"
import { api } from "../../scripts/api.js"
export async function sleep ( ms ) {
export async function sleep ( ms ) {
return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
}
}
export function rebootAPI ( ) {
export function rebootAPI ( ) {
@ -21,92 +21,92 @@ export function rebootAPI() {
export async function install _checked _custom _node ( grid _rows , target _i , caller , mode ) {
export async function install _checked _custom _node ( grid _rows , target _i , caller , mode ) {
if ( caller ) {
if ( caller ) {
let failed = '' ;
let failed = '' ;
caller . disableButtons ( ) ;
caller . disableButtons ( ) ;
for ( let i in grid _rows ) {
for ( let i in grid _rows ) {
if ( ! grid _rows [ i ] . checkbox . checked && i != target _i )
if ( ! grid _rows [ i ] . checkbox . checked && i != target _i )
continue ;
continue ;
var target ;
var target ;
if ( grid _rows [ i ] . data . custom _node ) {
if ( grid _rows [ i ] . data . custom _node ) {
target = grid _rows [ i ] . data . custom _node ;
target = grid _rows [ i ] . data . custom _node ;
}
}
else {
else {
target = grid _rows [ i ] . data ;
target = grid _rows [ i ] . data ;
}
}
caller . startInstall ( target ) ;
caller . startInstall ( target ) ;
try {
try {
const response = await api . fetchApi ( ` /customnode/ ${ mode } ` , {
const response = await api . fetchApi ( ` /customnode/ ${ mode } ` , {
method : 'POST' ,
method : 'POST' ,
headers : { 'Content-Type' : 'application/json' } ,
headers : { 'Content-Type' : 'application/json' } ,
body : JSON . stringify ( target )
body : JSON . stringify ( target )
} ) ;
} ) ;
if ( response . status == 400 ) {
if ( response . status == 400 ) {
app . ui . dialog . show ( ` ${ mode } failed: ${ target . title } ` ) ;
app . ui . dialog . show ( ` ${ mode } failed: ${ target . title } ` ) ;
app . ui . dialog . element . style . zIndex = 10010 ;
app . ui . dialog . element . style . zIndex = 10010 ;
continue ;
continue ;
}
}
const status = await response . json ( ) ;
const status = await response . json ( ) ;
app . ui . dialog . close ( ) ;
app . ui . dialog . close ( ) ;
target . installed = 'True' ;
target . installed = 'True' ;
continue ;
continue ;
}
}
catch ( exception ) {
catch ( exception ) {
failed += ` <BR> ${ target . title } ` ;
failed += ` <BR> ${ target . title } ` ;
}
}
}
}
if ( failed != '' ) {
if ( failed != '' ) {
app . ui . dialog . show ( ` ${ mode } failed: ${ failed } ` ) ;
app . ui . dialog . show ( ` ${ mode } failed: ${ failed } ` ) ;
app . ui . dialog . element . style . zIndex = 10010 ;
app . ui . dialog . element . style . zIndex = 10010 ;
}
}
await caller . invalidateControl ( ) ;
await caller . invalidateControl ( ) ;
caller . updateMessage ( "<BR>To apply the installed/updated/disabled/enabled custom node, please <button id='cm-reboot-button' class='cm-small-button'>RESTART</button> ComfyUI. And refresh browser." , 'cm-reboot-button' ) ;
caller . updateMessage ( "<BR>To apply the installed/updated/disabled/enabled custom node, please <button id='cm-reboot-button' class='cm-small-button'>RESTART</button> ComfyUI. And refresh browser." , 'cm-reboot-button' ) ;
}
}
} ;
} ;
export var manager _instance = null ;
export var manager _instance = null ;
export function setManagerInstance ( obj ) {
export function setManagerInstance ( obj ) {
manager _instance = obj ;
manager _instance = obj ;
}
}
function isValidURL ( url ) {
function isValidURL ( url ) {
if ( url . includes ( '&' ) )
if ( url . includes ( '&' ) )
return false ;
return false ;
const pattern = /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/ ;
const pattern = /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/ ;
return pattern . test ( url ) ;
return pattern . test ( url ) ;
}
}
export async function install _pip ( packages ) {
export async function install _pip ( packages ) {
if ( packages . includes ( '&' ) )
if ( packages . includes ( '&' ) )
app . ui . dialog . show ( ` Invalid PIP package enumeration: ' ${ packages } ' ` ) ;
app . ui . dialog . show ( ` Invalid PIP package enumeration: ' ${ packages } ' ` ) ;
const res = await api . fetchApi ( ` /customnode/install/pip?packages= ${ packages } ` ) ;
const res = await api . fetchApi ( ` /customnode/install/pip?packages= ${ packages } ` ) ;
if ( res . status == 200 ) {
if ( res . status == 200 ) {
app . ui . dialog . show ( ` PIP package installation is processed.<br>To apply the pip packages, please click the <button id='cm-reboot-button'><font size='3px'>RESTART</font></button> button in ComfyUI. ` ) ;
app . ui . dialog . show ( ` PIP package installation is processed.<br>To apply the pip packages, please click the <button id='cm-reboot-button'><font size='3px'>RESTART</font></button> button in ComfyUI. ` ) ;
const rebootButton = document . getElementById ( 'cm-reboot-button' ) ;
const rebootButton = document . getElementById ( 'cm-reboot-button' ) ;
const self = this ;
const self = this ;
rebootButton . addEventListener ( "click" , rebootAPI ) ;
rebootButton . addEventListener ( "click" , rebootAPI ) ;
app . ui . dialog . element . style . zIndex = 10010 ;
app . ui . dialog . element . style . zIndex = 10010 ;
}
}
else {
else {
app . ui . dialog . show ( ` Failed to install ' ${ packages } '<BR>See terminal log. ` ) ;
app . ui . dialog . show ( ` Failed to install ' ${ packages } '<BR>See terminal log. ` ) ;
app . ui . dialog . element . style . zIndex = 10010 ;
app . ui . dialog . element . style . zIndex = 10010 ;
}
}
}
}
export async function install _via _git _url ( url , manager _dialog ) {
export async function install _via _git _url ( url , manager _dialog ) {
@ -115,18 +115,18 @@ export async function install_via_git_url(url, manager_dialog) {
}
}
if ( ! isValidURL ( url ) ) {
if ( ! isValidURL ( url ) ) {
app . ui . dialog . show ( ` Invalid Git url ' ${ url } ' ` ) ;
app . ui . dialog . show ( ` Invalid Git url ' ${ url } ' ` ) ;
app . ui . dialog . element . style . zIndex = 10010 ;
app . ui . dialog . element . style . zIndex = 10010 ;
return ;
return ;
}
}
app . ui . dialog . show ( ` Wait...<BR><BR>Installing ' ${ url } ' ` ) ;
app . ui . dialog . show ( ` Wait...<BR><BR>Installing ' ${ url } ' ` ) ;
app . ui . dialog . element . style . zIndex = 10010 ;
app . ui . dialog . element . style . zIndex = 10010 ;
const res = await api . fetchApi ( ` /customnode/install/git_url?url= ${ url } ` ) ;
const res = await api . fetchApi ( ` /customnode/install/git_url?url= ${ url } ` ) ;
if ( res . status == 200 ) {
if ( res . status == 200 ) {
app . ui . dialog . show ( ` ' ${ url } ' is installed<BR>To apply the installed custom node, please <button id='cm-reboot-button'><font size='3px'>RESTART</font></button> ComfyUI. ` ) ;
app . ui . dialog . show ( ` ' ${ url } ' is installed<BR>To apply the installed custom node, please <button id='cm-reboot-button'><font size='3px'>RESTART</font></button> ComfyUI. ` ) ;
const rebootButton = document . getElementById ( 'cm-reboot-button' ) ;
const rebootButton = document . getElementById ( 'cm-reboot-button' ) ;
const self = this ;
const self = this ;
@ -138,10 +138,26 @@ export async function install_via_git_url(url, manager_dialog) {
}
}
} ) ;
} ) ;
app . ui . dialog . element . style . zIndex = 10010 ;
app . ui . dialog . element . style . zIndex = 10010 ;
}
}
else {
else {
app . ui . dialog . show ( ` Failed to install ' ${ url } '<BR>See terminal log. ` ) ;
app . ui . dialog . show ( ` Failed to install ' ${ url } '<BR>See terminal log. ` ) ;
app . ui . dialog . element . style . zIndex = 10010 ;
app . ui . dialog . element . style . zIndex = 10010 ;
}
}
}
export async function free _models ( ) {
let res = await api . fetchApi ( ` /free ` , {
method : 'POST' ,
headers : { 'Content-Type' : 'application/json' } ,
body : '{}'
} ) ;
if ( res . status == 200 ) {
app . ui . dialog . show ( 'Models have been unloaded.' )
}
else {
app . ui . dialog . show ( 'Unloading of models failed.<BR><BR>Installed ComfyUI may be an outdated version.' )
}
app . ui . dialog . element . style . zIndex = 10010 ;
}
}