| 323 | 323 | const url = new URL(request.body.url); |
| 324 | 324 | url.pathname = '/sdapi/v1/txt2img'; |
| 325 | 325 | |
| 326 | + const controller = new AbortController(); |
| 327 | + request.socket.removeAllListeners('close'); |
| 328 | + request.socket.on('close', function () { |
| 329 | + if (!response.writableEnded) { |
| 330 | + const url = new URL(request.body.url); |
| 331 | + url.pathname = '/sdapi/v1/interrupt'; |
| 332 | + fetch(url, { method: 'POST', headers: { 'Authorization': getBasicAuthHeader(request.body.auth) } }); |
| 333 | + } |
| 334 | + controller.abort(); |
| 335 | + }); |
| 336 | + |
| 326 | 337 | const result = await fetch(url, { |
| 327 | 338 | method: 'POST', |
| 328 | 339 | body: JSON.stringify(request.body), |