[chore] Reformat
This commit is contained in:
parent
5e6fcd28b2
commit
9dcc23825a
|
@ -906,7 +906,6 @@ async function validateComfyUrl() {
|
||||||
throw new Error('URL is not set.');
|
throw new Error('URL is not set.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const result = await fetch(`/api/sd/comfy/ping`, {
|
const result = await fetch(`/api/sd/comfy/ping`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: getRequestHeaders(),
|
headers: getRequestHeaders(),
|
||||||
|
@ -1180,7 +1179,6 @@ async function loadComfySamplers() {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const result = await fetch(`/api/sd/comfy/samplers`, {
|
const result = await fetch(`/api/sd/comfy/samplers`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: getRequestHeaders(),
|
headers: getRequestHeaders(),
|
||||||
|
@ -2054,8 +2052,8 @@ async function generateComfyImage(prompt) {
|
||||||
];
|
];
|
||||||
|
|
||||||
let workflow = extension_settings.sd.comfy_workflow.replace('"%prompt%"', JSON.stringify(prompt));
|
let workflow = extension_settings.sd.comfy_workflow.replace('"%prompt%"', JSON.stringify(prompt));
|
||||||
workflow = workflow.replace('"%seed%"', JSON.stringify(Math.round(Math.random()*Number.MAX_SAFE_INTEGER)));
|
workflow = workflow.replace('"%seed%"', JSON.stringify(Math.round(Math.random() * Number.MAX_SAFE_INTEGER)));
|
||||||
placeholders.forEach(ph=>{
|
placeholders.forEach(ph => {
|
||||||
workflow = workflow.replace(`"%${ph}%"`, JSON.stringify(extension_settings.sd[ph]));
|
workflow = workflow.replace(`"%${ph}%"`, JSON.stringify(extension_settings.sd[ph]));
|
||||||
});
|
});
|
||||||
console.log(`{
|
console.log(`{
|
||||||
|
@ -2071,18 +2069,18 @@ async function generateComfyImage(prompt) {
|
||||||
}`,
|
}`,
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
return {format:'png', data:await promptResult.text()};
|
return { format: 'png', data: await promptResult.text() };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onComfyOpenWorkflowEditorClick() {
|
async function onComfyOpenWorkflowEditorClick() {
|
||||||
const editorHtml = $(await $.get('scripts/extensions/stable-diffusion/comfyWorkflowEditor.html'));
|
const editorHtml = $(await $.get('scripts/extensions/stable-diffusion/comfyWorkflowEditor.html'));
|
||||||
const popupResult = callPopup(editorHtml, "confirm", undefined, {okButton: "Save", wide:true, large:true, rows:1 });
|
const popupResult = callPopup(editorHtml, "confirm", undefined, { okButton: "Save", wide: true, large: true, rows: 1 });
|
||||||
const checkPlaceholders = ()=>{
|
const checkPlaceholders = () => {
|
||||||
const workflow = $('#sd_comfy_workflow_editor_workflow').val().toString();
|
const workflow = $('#sd_comfy_workflow_editor_workflow').val().toString();
|
||||||
$('.sd_comfy_workflow_editor_placeholder_list > li[data-placeholder]').each(function(idx) {
|
$('.sd_comfy_workflow_editor_placeholder_list > li[data-placeholder]').each(function (idx) {
|
||||||
const key = this.getAttribute('data-placeholder');
|
const key = this.getAttribute('data-placeholder');
|
||||||
const found = workflow.search(`"%${key}%"`) != -1;
|
const found = workflow.search(`"%${key}%"`) != -1;
|
||||||
this.classList[found?'remove':'add']('sd_comfy_workflow_editor_not_found');
|
this.classList[found ? 'remove' : 'add']('sd_comfy_workflow_editor_not_found');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
$('#sd_comfy_workflow_editor_workflow').val(extension_settings.sd.comfy_workflow);
|
$('#sd_comfy_workflow_editor_workflow').val(extension_settings.sd.comfy_workflow);
|
||||||
|
|
|
@ -34,28 +34,35 @@
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
width: fit-content;
|
width: fit-content;
|
||||||
}
|
}
|
||||||
|
|
||||||
#sd_comfy_workflow_editor_template {
|
#sd_comfy_workflow_editor_template {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sd_comfy_workflow_editor {
|
.sd_comfy_workflow_editor {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sd_comfy_workflow_editor_content {
|
.sd_comfy_workflow_editor_content {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex: 1 1 auto;
|
flex: 1 1 auto;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sd_comfy_workflow_editor_workflow_container {
|
.sd_comfy_workflow_editor_workflow_container {
|
||||||
flex: 1 1 auto;
|
flex: 1 1 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
#sd_comfy_workflow_editor_workflow {
|
#sd_comfy_workflow_editor_workflow {
|
||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sd_comfy_workflow_editor_placeholder_container {
|
.sd_comfy_workflow_editor_placeholder_container {
|
||||||
flex: 0 0 auto;
|
flex: 0 0 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sd_comfy_workflow_editor_placeholder_list {
|
.sd_comfy_workflow_editor_placeholder_list {
|
||||||
font-size: x-small;
|
font-size: x-small;
|
||||||
list-style: none;
|
list-style: none;
|
||||||
|
@ -63,12 +70,15 @@
|
||||||
padding: 3px 5px;
|
padding: 3px 5px;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
.sd_comfy_workflow_editor_placeholder_list > li[data-placeholder]:before {
|
|
||||||
|
.sd_comfy_workflow_editor_placeholder_list>li[data-placeholder]:before {
|
||||||
content: "✅ ";
|
content: "✅ ";
|
||||||
}
|
}
|
||||||
.sd_comfy_workflow_editor_placeholder_list > li.sd_comfy_workflow_editor_not_found:before {
|
|
||||||
|
.sd_comfy_workflow_editor_placeholder_list>li.sd_comfy_workflow_editor_not_found:before {
|
||||||
content: "❌ ";
|
content: "❌ ";
|
||||||
}
|
}
|
||||||
.sd_comfy_workflow_editor_placeholder_list > li > .notes-link {
|
|
||||||
|
.sd_comfy_workflow_editor_placeholder_list>li>.notes-link {
|
||||||
cursor: help;
|
cursor: help;
|
||||||
}
|
}
|
|
@ -348,91 +348,90 @@ function registerEndpoints(app, jsonParser) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.post('/api/sd/comfy/ping', jsonParser, async (request, response) => {
|
||||||
|
try {
|
||||||
|
const url = new URL(request.body.url);
|
||||||
|
url.pathname = '/system_stats'
|
||||||
|
|
||||||
app.post('/api/sd/comfy/ping', jsonParser, async(request, response)=>{
|
const result = await fetch(url);
|
||||||
try {
|
if (!result.ok) {
|
||||||
const url = new URL(request.body.url);
|
throw new Error('ComfyUI returned an error.');
|
||||||
url.pathname = '/system_stats'
|
}
|
||||||
|
|
||||||
const result = await fetch(url);
|
return response.sendStatus(200);
|
||||||
if (!result.ok) {
|
} catch (error) {
|
||||||
throw new Error('ComfyUI returned an error.');
|
console.log(error);
|
||||||
}
|
return response.sendStatus(500);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return response.sendStatus(200);
|
app.post('/api/sd/comfy/samplers', jsonParser, async (request, response) => {
|
||||||
} catch (error) {
|
try {
|
||||||
console.log(error);
|
const url = new URL(request.body.url);
|
||||||
return response.sendStatus(500);
|
url.pathname = '/object_info'
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.post('/api/sd/comfy/samplers', jsonParser, async(request, response)=>{
|
const result = await fetch(url);
|
||||||
try {
|
if (!result.ok) {
|
||||||
const url = new URL(request.body.url);
|
throw new Error('ComfyUI returned an error.');
|
||||||
url.pathname = '/object_info'
|
}
|
||||||
|
|
||||||
const result = await fetch(url);
|
|
||||||
if (!result.ok) {
|
|
||||||
throw new Error('ComfyUI returned an error.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await result.json();
|
|
||||||
return response.send(data.KSampler.input.required.sampler_name[0]);
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
return response.sendStatus(500);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.post('/api/sd/comfy/models', jsonParser, async(request, response)=>{
|
|
||||||
try {
|
|
||||||
const url = new URL(request.body.url);
|
|
||||||
url.pathname = '/object_info'
|
|
||||||
|
|
||||||
const result = await fetch(url);
|
|
||||||
if (!result.ok) {
|
|
||||||
throw new Error('ComfyUI returned an error.');
|
|
||||||
}
|
|
||||||
const data = await result.json();
|
const data = await result.json();
|
||||||
return response.send(data.CheckpointLoaderSimple.input.required.ckpt_name[0].map(it=>({value:it,text:it})));
|
return response.send(data.KSampler.input.required.sampler_name[0]);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
return response.sendStatus(500);
|
return response.sendStatus(500);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post('/api/sd/comfy/schedulers', jsonParser, async(request, response)=>{
|
app.post('/api/sd/comfy/models', jsonParser, async (request, response) => {
|
||||||
try {
|
try {
|
||||||
const url = new URL(request.body.url);
|
const url = new URL(request.body.url);
|
||||||
url.pathname = '/object_info'
|
url.pathname = '/object_info'
|
||||||
|
|
||||||
const result = await fetch(url);
|
const result = await fetch(url);
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
throw new Error('ComfyUI returned an error.');
|
throw new Error('ComfyUI returned an error.');
|
||||||
}
|
}
|
||||||
|
const data = await result.json();
|
||||||
|
return response.send(data.CheckpointLoaderSimple.input.required.ckpt_name[0].map(it => ({ value: it, text: it })));
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
return response.sendStatus(500);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const data = await result.json();
|
app.post('/api/sd/comfy/schedulers', jsonParser, async (request, response) => {
|
||||||
return response.send(data.KSampler.input.required.scheduler[0]);
|
try {
|
||||||
} catch (error) {
|
const url = new URL(request.body.url);
|
||||||
console.log(error);
|
url.pathname = '/object_info'
|
||||||
return response.sendStatus(500);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.post('/api/sd/comfy/generate', jsonParser, async(request, response)=>{
|
const result = await fetch(url);
|
||||||
try {
|
if (!result.ok) {
|
||||||
const url = new URL(request.body.url);
|
throw new Error('ComfyUI returned an error.');
|
||||||
url.pathname = '/prompt'
|
}
|
||||||
|
|
||||||
const promptResult = await fetch(url, {
|
const data = await result.json();
|
||||||
|
return response.send(data.KSampler.input.required.scheduler[0]);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
return response.sendStatus(500);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post('/api/sd/comfy/generate', jsonParser, async (request, response) => {
|
||||||
|
try {
|
||||||
|
const url = new URL(request.body.url);
|
||||||
|
url.pathname = '/prompt'
|
||||||
|
|
||||||
|
const promptResult = await fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: request.body.prompt,
|
body: request.body.prompt,
|
||||||
});
|
});
|
||||||
if (!promptResult.ok) {
|
if (!promptResult.ok) {
|
||||||
throw new Error('ComfyUI returned an error.');
|
throw new Error('ComfyUI returned an error.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await promptResult.json();
|
const data = await promptResult.json();
|
||||||
const id = data.prompt_id;
|
const id = data.prompt_id;
|
||||||
let item;
|
let item;
|
||||||
const historyUrl = new URL(request.body.url);
|
const historyUrl = new URL(request.body.url);
|
||||||
|
@ -449,7 +448,7 @@ function registerEndpoints(app, jsonParser) {
|
||||||
}
|
}
|
||||||
await delay(100);
|
await delay(100);
|
||||||
}
|
}
|
||||||
const imgInfo = Object.keys(item.outputs).map(it=>item.outputs[it].images).flat()[0];
|
const imgInfo = Object.keys(item.outputs).map(it => item.outputs[it].images).flat()[0];
|
||||||
const imgUrl = new URL(request.body.url);
|
const imgUrl = new URL(request.body.url);
|
||||||
imgUrl.pathname = '/view';
|
imgUrl.pathname = '/view';
|
||||||
imgUrl.search = `?filename=${imgInfo.filename}&subfolder=${imgInfo.subfolder}&type=${imgInfo.type}`;
|
imgUrl.search = `?filename=${imgInfo.filename}&subfolder=${imgInfo.subfolder}&type=${imgInfo.type}`;
|
||||||
|
@ -459,10 +458,10 @@ function registerEndpoints(app, jsonParser) {
|
||||||
}
|
}
|
||||||
const imgBuffer = await imgResponse.buffer();
|
const imgBuffer = await imgResponse.buffer();
|
||||||
return response.send(imgBuffer.toString('base64'));
|
return response.send(imgBuffer.toString('base64'));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return response.sendStatus(500);
|
return response.sendStatus(500);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
Loading…
Reference in New Issue