| 293 | | 294 | |
| 294 | router.post('/generate', jsonParser, async (request, response) => { | 295 | router.post('/generate', jsonParser, async (request, response) => { |
| 295 | try { | 296 | try { |
| 296 | console.log('SD WebUI request:', request.body); | 297 | try { |
| | 298 | const optionsUrl = urlJoin(request.body.url, '/sdapi/v1/options'); |
| | 299 | const optionsResult = await fetch(optionsUrl, { headers: { 'Authorization': getBasicAuthHeader(request.body.auth) } }); |
| | 300 | const optionsData = /** @type {any} */ (await optionsResult.json()); |
| | 301 | const isForge = 'forge_preset' in optionsData; |
| 297 | | 302 | |
| 298 | const url = new URL(request.body.url); | 303 | if (!isForge) { |
| 299 | url.pathname = '/sdapi/v1/txt2img'; | 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 | 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 | }); |
| 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 | method: 'POST', | 323 | method: 'POST', |
| 314 | body: JSON.stringify(request.body), | 324 | body: JSON.stringify(request.body), |
| 315 | headers: { | 325 | headers: { |