[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.');
}
const result = await fetch(`/api/sd/comfy/ping`, {
method: 'POST',
headers: getRequestHeaders(),
@ -1180,7 +1179,6 @@ async function loadComfySamplers() {
}
try {
const result = await fetch(`/api/sd/comfy/samplers`, {
method: 'POST',
headers: getRequestHeaders(),
@ -2054,8 +2052,8 @@ async function generateComfyImage(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)));
placeholders.forEach(ph=>{
workflow = workflow.replace('"%seed%"', JSON.stringify(Math.round(Math.random() * Number.MAX_SAFE_INTEGER)));
placeholders.forEach(ph => {
workflow = workflow.replace(`"%${ph}%"`, JSON.stringify(extension_settings.sd[ph]));
});
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() {
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 checkPlaceholders = ()=>{
const popupResult = callPopup(editorHtml, "confirm", undefined, { okButton: "Save", wide: true, large: true, rows: 1 });
const checkPlaceholders = () => {
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 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);

View File

@ -34,28 +34,35 @@
gap: 10px;
width: fit-content;
}
#sd_comfy_workflow_editor_template {
height: 100%;
}
.sd_comfy_workflow_editor {
display: flex;
flex-direction: column;
height: 100%;
}
.sd_comfy_workflow_editor_content {
display: flex;
flex: 1 1 auto;
flex-direction: row;
}
.sd_comfy_workflow_editor_workflow_container {
flex: 1 1 auto;
}
#sd_comfy_workflow_editor_workflow {
font-family: monospace;
}
.sd_comfy_workflow_editor_placeholder_container {
flex: 0 0 auto;
}
.sd_comfy_workflow_editor_placeholder_list {
font-size: x-small;
list-style: none;
@ -63,12 +70,15 @@
padding: 3px 5px;
text-align: left;
}
.sd_comfy_workflow_editor_placeholder_list > li[data-placeholder]:before {
.sd_comfy_workflow_editor_placeholder_list>li[data-placeholder]:before {
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: "❌ ";
}
.sd_comfy_workflow_editor_placeholder_list > li > .notes-link {
.sd_comfy_workflow_editor_placeholder_list>li>.notes-link {
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 {
const url = new URL(request.body.url);
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 {
const url = new URL(request.body.url);
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 {
const url = new URL(request.body.url);
url.pathname = '/object_info'
@ -394,14 +393,14 @@ function registerEndpoints(app, jsonParser) {
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})));
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);
}
});
app.post('/api/sd/comfy/schedulers', jsonParser, async(request, response)=>{
app.post('/api/sd/comfy/schedulers', jsonParser, async (request, response) => {
try {
const url = new URL(request.body.url);
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 {
const url = new URL(request.body.url);
url.pathname = '/prompt'
@ -449,7 +448,7 @@ function registerEndpoints(app, jsonParser) {
}
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);
imgUrl.pathname = '/view';
imgUrl.search = `?filename=${imgInfo.filename}&subfolder=${imgInfo.subfolder}&type=${imgInfo.type}`;