Skip to content

Commit 0a3d8da

Browse files
delete old code
1 parent 4fd73c7 commit 0a3d8da

File tree

5 files changed

+2
-215
lines changed

5 files changed

+2
-215
lines changed

index.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const {
9797
comfyui,
9898
comfyui_util,
9999
comfyui_main_ui,
100-
diffusion_chain,
100+
101101
comfyapi,
102102
} = require('./typescripts/dist/bundle')
103103

@@ -1821,6 +1821,3 @@ async function openFileFromUrlExe(url, format = 'gif') {
18211821
await openFileFromUrl(url, format)
18221822
})
18231823
}
1824-
1825-
let comfy_server = new diffusion_chain.ComfyServer('http://127.0.0.1:8188')
1826-
let comfy_object_info = diffusion_chain.ComfyApi.objectInfo(comfy_server)

package-lock.json

-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"@types/react": "^18.2.6",
1010
"@types/react-dom": "^18.2.4",
1111
"changedpi": "^1.0.4",
12-
"diffusion-chain": "file:../diffusion-chain",
1312
"fastify": "^4.10.2",
1413
"jimp": "^0.16.2",
1514
"madge": "^6.0.0",

sdapi_py_re.js

-185
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ const { base64ToBase64Url } = require('./utility/general')
33

44
const py_re = require('./utility/sdapi/python_replacement')
55
const Enum = require('./enum')
6-
const { control_net } = require('./typescripts/dist/bundle')
7-
const { mapPluginSettingsToControlNet, getEnableControlNet, getModuleDetail } =
8-
control_net
96

107
const api = require('./utility/api')
118
//javascript plugin can't read images from local directory so we send a request to local server to read the image file and send it back to plugin as image string base64
@@ -359,186 +356,6 @@ async function requestExtraSingleImage(payload) {
359356
}
360357
}
361358

362-
//REFACTOR: reuse the same code for (requestControlNetTxt2Img,requestControlNetImg2Img)
363-
async function requestControlNetTxt2Img(plugin_settings) {
364-
console.log('requestControlNetTxt2Img: ')
365-
366-
// const full_url = `${g_sd_url}/controlnet/txt2img`
367-
const full_url = `${g_sd_url}/sdapi/v1/txt2img`
368-
369-
const control_net_settings = mapPluginSettingsToControlNet(plugin_settings)
370-
let control_networks = []
371-
// let active_control_networks = 0
372-
for (let index = 0; index < g_controlnet_max_models; index++) {
373-
if (!getEnableControlNet(index)) {
374-
control_networks[index] = false
375-
continue
376-
}
377-
control_networks[index] = true
378-
379-
if (!control_net_settings['controlnet_units'][index]['input_image']) {
380-
app.showAlert('you need to add a valid ControlNet input image')
381-
throw 'you need to add a valid ControlNet input image'
382-
}
383-
384-
if (!control_net_settings['controlnet_units'][index]['module']) {
385-
app.showAlert('you need to select a valid ControlNet Module')
386-
throw 'you need to select a valid ControlNet Module'
387-
}
388-
389-
if (
390-
(!control_net_settings['controlnet_units'][index]['model'] &&
391-
!getModuleDetail()[
392-
control_net_settings['controlnet_units'][index]['module']
393-
].model_free) ||
394-
control_net_settings['controlnet_units'][index]['model'] === 'none'
395-
) {
396-
app.showAlert('you need to select a valid ControlNet Model')
397-
throw 'you need to select a valid ControlNet Model'
398-
}
399-
// active_control_networks++
400-
}
401-
402-
let request = await fetch(full_url, {
403-
method: 'POST',
404-
headers: {
405-
Accept: 'application/json',
406-
'Content-Type': 'application/json',
407-
},
408-
body: JSON.stringify(control_net_settings),
409-
})
410-
411-
let json = await request.json()
412-
console.log('json:', json)
413-
414-
//update the mask in controlNet tab
415-
const numOfImages = json['images'].length
416-
let numberOfAnnotations =
417-
numOfImages - g_generation_session.last_settings.batch_size
418-
if (numberOfAnnotations < 0) numberOfAnnotations = 0
419-
420-
const base64_mask = json['images'].slice(numOfImages - numberOfAnnotations)
421-
422-
let mask_index = 0
423-
424-
for (let index = 0; index < control_networks.length; index++) {
425-
if (
426-
control_networks[index] == false ||
427-
mask_index >= numberOfAnnotations
428-
)
429-
continue
430-
control_net.setControlDetectMapSrc(base64_mask[mask_index], index)
431-
g_generation_session.controlNetMask[index] = base64_mask[mask_index]
432-
mask_index++
433-
}
434-
// g_generation_session.controlNetMask = base64_mask
435-
436-
const standard_response = await py_re.convertToStandardResponse(
437-
control_net_settings,
438-
json['images'].slice(0, numOfImages - numberOfAnnotations),
439-
plugin_settings['uniqueDocumentId']
440-
)
441-
console.log('standard_response:', standard_response)
442-
443-
return standard_response
444-
}
445-
446-
//REFACTOR: reuse the same code for (requestControlNetTxt2Img,requestControlNetImg2Img)
447-
async function requestControlNetImg2Img(plugin_settings) {
448-
console.log('requestControlNetImg2Img: ')
449-
450-
const full_url = `${g_sd_url}/sdapi/v1/img2img`
451-
const control_net_settings = mapPluginSettingsToControlNet(plugin_settings)
452-
453-
// let control_networks = 0
454-
let control_networks = []
455-
for (let index = 0; index < g_controlnet_max_models; index++) {
456-
if (!getEnableControlNet(index)) {
457-
control_networks[index] = false
458-
continue
459-
}
460-
control_networks[index] = true
461-
if (!control_net_settings['controlnet_units'][index]['input_image']) {
462-
app.showAlert('you need to add a valid ControlNet input image')
463-
throw 'you need to add a valid ControlNet input image'
464-
}
465-
466-
if (!control_net_settings['controlnet_units'][index]['module']) {
467-
app.showAlert('you need to select a valid ControlNet Module')
468-
throw 'you need to select a valid ControlNet Module'
469-
}
470-
if (
471-
(!control_net_settings['controlnet_units'][index]['model'] &&
472-
!getModuleDetail()[
473-
control_net_settings['controlnet_units'][index]['module']
474-
].model_free) ||
475-
control_net_settings['controlnet_units'][index]['model'] === 'none'
476-
) {
477-
app.showAlert('you need to select a valid ControlNet Model')
478-
throw 'you need to select a valid ControlNet Model'
479-
}
480-
}
481-
482-
let request = await fetch(full_url, {
483-
method: 'POST',
484-
headers: {
485-
Accept: 'application/json',
486-
'Content-Type': 'application/json',
487-
},
488-
body: JSON.stringify(control_net_settings),
489-
// body: JSON.stringify(payload),
490-
})
491-
492-
let json = await request.json()
493-
console.log('json:', json)
494-
495-
//update the mask in controlNet tab
496-
const numOfImages = json['images'].length
497-
let numberOfAnnotations =
498-
numOfImages - g_generation_session.last_settings.batch_size
499-
if (numberOfAnnotations < 0) numberOfAnnotations = 0
500-
501-
// To fix a bug: when Ultimate SD Upscale is active and running, the detection maps won’t be retrieved.
502-
// So set its value to 0 to avoid the result images being loaded in the annotation map interface.
503-
if (
504-
scripts.script_store.isInstalled() &&
505-
scripts.script_store.is_active &&
506-
scripts.script_store.selected_script_name !== 'None' &&
507-
scripts.script_store.is_selected_script_available
508-
) {
509-
numberOfAnnotations = 0
510-
}
511-
const base64_mask = json['images'].slice(numOfImages - numberOfAnnotations)
512-
513-
let mask_index = 0
514-
for (let index = 0; index < control_networks.length; index++) {
515-
if (
516-
control_networks[index] == false ||
517-
mask_index >= numberOfAnnotations
518-
)
519-
continue
520-
control_net.setControlDetectMapSrc(base64_mask[mask_index], index)
521-
g_generation_session.controlNetMask[index] = base64_mask[mask_index]
522-
mask_index++
523-
}
524-
525-
// g_generation_session.controlNetMask = base64_mask
526-
527-
const standard_response = await py_re.convertToStandardResponse(
528-
control_net_settings,
529-
json['images'].slice(0, numOfImages - numberOfAnnotations),
530-
plugin_settings['uniqueDocumentId']
531-
)
532-
console.log('standard_response:', standard_response)
533-
534-
// //get all images except last because it's the mask
535-
// for (const image of json['images'].slice(0, -1)) {
536-
// await io.IO.base64ToLayer(image)
537-
// }
538-
539-
return standard_response
540-
}
541-
542359
async function isWebuiRunning() {
543360
console.log('isWebuiRunning: ')
544361
let json = []
@@ -577,7 +394,5 @@ module.exports = {
577394
// requestHordeStatus,
578395
requestExtraSingleImage,
579396

580-
requestControlNetTxt2Img,
581-
requestControlNetImg2Img,
582397
isWebuiRunning,
583398
}

typescripts/entry.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ export { toJS } from 'mobx'
4343
export { default as node_fs } from 'fs'
4444
export { default as comfyui_util } from './comfyui/util'
4545
export { default as comfyui_main_ui } from './comfyui/main_ui'
46-
export * as diffusion_chain from 'diffusion-chain'
46+
4747
export { default as comfyapi } from './comfyui/comfyapi'

0 commit comments

Comments
 (0)