Remove forge override from non-forge SD requests

de6c8c1501e48459f39d796c07f431a62761aaee

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +18 -8Ignore whitespace
src/endpoints/stable-diffusion.js+18 -8
@@ -7,6 +7,7 @@ import sanitize from 'sanitize-filename';
7import { sync as writeFileAtomicSync } from 'write-file-atomic';7import { sync as writeFileAtomicSync } from 'write-file-atomic';
8import FormData from 'form-data';8import FormData from 'form-data';
9import urlJoin from 'url-join';9import urlJoin from 'url-join';
10import _ from 'lodash';
1011
11import { delay, getBasicAuthHeader, tryParse } from '../util.js';12import { delay, getBasicAuthHeader, tryParse } from '../util.js';
12import { jsonParser } from '../express-common.js';13import { jsonParser } from '../express-common.js';
@@ -293,23 +294,32 @@ router.post('/set-model', jsonParser, async (request, response) => {
293294
294router.post('/generate', jsonParser, async (request, response) => {295router.post('/generate', jsonParser, async (request, response) => {
295 try {296 try {
296 console.log('SD WebUI request:', request.body);297 try {
297298 const optionsUrl = urlJoin(request.body.url, '/sdapi/v1/options');
298 const url = new URL(request.body.url);299 const optionsResult = await fetch(optionsUrl, { headers: { 'Authorization': getBasicAuthHeader(request.body.auth) } });
299 url.pathname = '/sdapi/v1/txt2img';300 const optionsData = /** @type {any} */ (await optionsResult.json());
301 const isForge = 'forge_preset' in optionsData;
302
303 if (!isForge) {
304 _.unset(request.body, 'override_settings.forge_additional_modules');
305 }
306 } catch (error) {
307 console.log('SD WebUI failed to get options:', error);
308 }
300309
301 const controller = new AbortController();310 const controller = new AbortController();
302 request.socket.removeAllListeners('close');311 request.socket.removeAllListeners('close');
303 request.socket.on('close', function () {312 request.socket.on('close', function () {
304 if (!response.writableEnded) {313 if (!response.writableEnded) {
305 const url = new URL(request.body.url);314 const interruptUrl = urlJoin(request.body.url, '/sdapi/v1/interrupt');
306 url.pathname = '/sdapi/v1/interrupt';315 fetch(interruptUrl, { method: 'POST', headers: { 'Authorization': getBasicAuthHeader(request.body.auth) } });
307 fetch(url, { method: 'POST', headers: { 'Authorization': getBasicAuthHeader(request.body.auth) } });
308 }316 }
309 controller.abort();317 controller.abort();
310 });318 });
311319
312 const result = await fetch(url, {320 console.log('SD WebUI request:', request.body);
321 const txt2imgUrl = urlJoin(request.body.url, '/sdapi/v1/txt2img');
322 const result = await fetch(txt2imgUrl, {
313 method: 'POST',323 method: 'POST',
314 body: JSON.stringify(request.body),324 body: JSON.stringify(request.body),
315 headers: {325 headers: {