fix: (UNSURE) ERR_INVALID_STATE

Stream controller in the endpoint that streams files from the S3 bucket
would ocassionally crash the server by throwing `TypeError
[ERR_INVALID_STATE]: Invalid state: Controller is already closed`. This
should fix that, but as the conditions that cause it to happen are
unknown, this is not certain.
This commit is contained in:
April Hall 2025-02-25 11:03:55 -05:00
parent bbc8f090d8
commit 51c7ddce80
No known key found for this signature in database
GPG Key ID: A49AC35CB186266C

View File

@ -12,7 +12,11 @@ export const GET = async ({ params }) => {
const readableStream = new ReadableStream({
start(controller) {
stream.on('data', (chunk) => controller.enqueue(chunk));
stream.on('data', (chunk) => {
if (controller.desiredSize !== null && controller.desiredSize > 0) {
controller.enqueue(chunk);
}
});
stream.on('end', () => controller.close());
stream.on('error', (err) => controller.error(err));
},