mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Remove forge override from non-forge SD requests
This commit is contained in:
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user