Skip to content

Commit

Permalink
Merge pull request #896 from intuitem/CA-188-BUG-frontend-server-cras…
Browse files Browse the repository at this point in the history
…h-when-an-attachment-is-loading-while-the-user-quit-the-page

Modify the evidence file stream behavior to stop reading when being terminated by the client
  • Loading branch information
Mohamed-Hacene authored Oct 8, 2024
2 parents da8e978 + 06304dd commit da0c4cc
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ export const GET: RequestHandler = async ({ fetch, setHeaders, params }) => {
}

const reader = attachmentResponse.body.getReader();
let readerTerminated = false;
const stream = new ReadableStream({
start(controller) {
function push() {
if (readerTerminated) {
return;
}
reader.read().then(({ done, value }) => {
if (done) {
controller.close();
Expand All @@ -42,6 +46,9 @@ export const GET: RequestHandler = async ({ fetch, setHeaders, params }) => {
});
}
push();
},
cancel() {
readerTerminated = true;
}
});

Expand Down

0 comments on commit da0c4cc

Please sign in to comment.