Remove forge override from non-forge SD requests

This commit is contained in:
Cohee
2024-12-31 00:27:12 +02:00
parent e0af5ff353
commit de6c8c1501

View File

@@ -7,6 +7,7 @@ import sanitize from 'sanitize-filename';
import { sync as writeFileAtomicSync } from 'write-file-atomic';
import FormData from 'form-data';
import urlJoin from 'url-join';
import _ from 'lodash';
import { delay, getBasicAuthHeader, tryParse } from '../util.js';
import { jsonParser } from '../express-common.js';
@@ -293,23 +294,32 @@ router.post('/set-model', jsonParser, async (request, response) => {
router.post('/generate', jsonParser, async (request, response) => {
try {
console.log('SD WebUI request:', request.body);
try {
const optionsUrl = urlJoin(request.body.url, '/sdapi/v1/options');
const optionsResult = await fetch(optionsUrl, { headers: { 'Authorization': getBasicAuthHeader(request.body.auth) } });
const optionsData = /** @type {any} */ (await optionsResult.json());
const isForge = 'forge_preset' in optionsData;
const url = new URL(request.body.url);
url.pathname = '/sdapi/v1/txt2img';
if (!isForge) {
_.unset(request.body, 'override_settings.forge_additional_modules');
}
} catch (error) {
console.log('SD WebUI failed to get options:', error);
}
const controller = new AbortController();
request.socket.removeAllListeners('close');
request.socket.on('close', function () {
if (!response.writableEnded) {
const url = new URL(request.body.url);
url.pathname = '/sdapi/v1/interrupt';
fetch(url, { method: 'POST', headers: { 'Authorization': getBasicAuthHeader(request.body.auth) } });
const interruptUrl = urlJoin(request.body.url, '/sdapi/v1/interrupt');
fetch(interruptUrl, { method: 'POST', headers: { 'Authorization': getBasicAuthHeader(request.body.auth) } });
}
controller.abort();
});
const result = await fetch(url, {
console.log('SD WebUI request:', request.body);
const txt2imgUrl = urlJoin(request.body.url, '/sdapi/v1/txt2img');
const result = await fetch(txt2imgUrl, {
method: 'POST',
body: JSON.stringify(request.body),
headers: {