Skip to content

Commit

Permalink
Modify the evidence file stream behavior to stop reading when being t…
Browse files Browse the repository at this point in the history
…erminated by the client

Fix useless code
  • Loading branch information
monsieurswag committed Oct 3, 2024
1 parent 95ce9a7 commit 06304dd
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 06304dd

Please sign in to comment.