| 293 | 294 | |
| 294 | 295 | router.post('/generate', jsonParser, async (request, response) => { |
| 295 | 296 | try { |
| 296 | | - console.log('SD WebUI request:', request.body); |
| 297 | + try { |
| 297 | | - |
| 298 | + 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 | + } |
| 300 | 309 | |
| 301 | 310 | const controller = new AbortController(); |
| 302 | 311 | request.socket.removeAllListeners('close'); |
| 303 | 312 | request.socket.on('close', function () { |
| 304 | 313 | if (!response.writableEnded) { |
| 305 | 314 | const urlinterruptUrl = new URLurlJoin(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 | 317 | controller.abort(); |
| 310 | 318 | }); |
| 311 | 319 | |
| 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 | 323 | method: 'POST', |
| 314 | 324 | body: JSON.stringify(request.body), |
| 315 | 325 | headers: { |