[chore] Reformat

This commit is contained in:
Cohee 2023-11-19 21:17:02 +02:00
parent 5e6fcd28b2
commit 9dcc23825a
3 changed files with 96 additions and 89 deletions

View File

@ -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);

View File

@ -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;
} }

View File

@ -348,8 +348,7 @@ function registerEndpoints(app, jsonParser) {
} }
}); });
app.post('/api/sd/comfy/ping', jsonParser, async (request, response) => {
app.post('/api/sd/comfy/ping', jsonParser, async(request, response)=>{
try { try {
const url = new URL(request.body.url); const url = new URL(request.body.url);
url.pathname = '/system_stats' url.pathname = '/system_stats'
@ -366,7 +365,7 @@ function registerEndpoints(app, jsonParser) {
} }
}); });
app.post('/api/sd/comfy/samplers', jsonParser, async(request, response)=>{ app.post('/api/sd/comfy/samplers', 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'
@ -384,7 +383,7 @@ function registerEndpoints(app, jsonParser) {
} }
}); });
app.post('/api/sd/comfy/models', 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'
@ -394,14 +393,14 @@ function registerEndpoints(app, jsonParser) {
throw new Error('ComfyUI returned an error.'); 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.CheckpointLoaderSimple.input.required.ckpt_name[0].map(it => ({ value: it, text: it })));
} 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/schedulers', 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'
@ -419,7 +418,7 @@ function registerEndpoints(app, jsonParser) {
} }
}); });
app.post('/api/sd/comfy/generate', jsonParser, async(request, response)=>{ app.post('/api/sd/comfy/generate', jsonParser, async (request, response) => {
try { try {
const url = new URL(request.body.url); const url = new URL(request.body.url);
url.pathname = '/prompt' url.pathname = '/prompt'
@ -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}`;