Interrupt AUTO1111 gens on cancel

7e4abaabff3e130ab1e50c8b16842a6b271c5a5f

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

1 files changed, +13 -0Showing whitespace changes
src/endpoints/stable-diffusion.js+13 -0
@@ -323,6 +323,17 @@ router.post('/generate', jsonParser, async (request, response) => {
323 const url = new URL(request.body.url);323 const url = new URL(request.body.url);
324 url.pathname = '/sdapi/v1/txt2img';324 url.pathname = '/sdapi/v1/txt2img';
325325
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 const result = await fetch(url, {337 const result = await fetch(url, {
327 method: 'POST',338 method: 'POST',
328 body: JSON.stringify(request.body),339 body: JSON.stringify(request.body),
@@ -331,6 +342,8 @@ router.post('/generate', jsonParser, async (request, response) => {
331 'Authorization': getBasicAuthHeader(request.body.auth),342 'Authorization': getBasicAuthHeader(request.body.auth),
332 },343 },
333 timeout: 0,344 timeout: 0,
345 // @ts-ignore
346 signal: controller.signal,
334 });347 });
335348
336 if (!result.ok) {349 if (!result.ok) {