From 70eace9de439a699f10be59cc512aa96e4c8f4a9 Mon Sep 17 00:00:00 2001 From: stringsplit <77242831+nbitzz@users.noreply.github.com> Date: Wed, 6 Mar 2024 18:43:36 +0000 Subject: [PATCH] uhhh...? can't test; not home. prolly doesn't work @Jack5079 --- src/server/routes/api/v0/primaryApi.ts | 34 ++++++++++++-------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/server/routes/api/v0/primaryApi.ts b/src/server/routes/api/v0/primaryApi.ts index 3e6376e..974c401 100644 --- a/src/server/routes/api/v0/primaryApi.ts +++ b/src/server/routes/api/v0/primaryApi.ts @@ -69,27 +69,25 @@ export default function (files: Files) { } } + if (range) { + ctx.status(206) + ctx.header( + "Content-Length", + (range.end - range.start + 1).toString() + ) + ctx.header( + "Content-Range", + `bytes ${range.start}-${range.end}/${file.sizeInBytes}` + ) + } + + if (ctx.req.method == "HEAD") + return ctx.body(null) + return files .readFileStream(fileId, range) .then(async (stream) => { - if (range) { - ctx.status(206) - ctx.header( - "Content-Length", - (range.end - range.start + 1).toString() - ) - ctx.header( - "Content-Range", - `bytes ${range.start}-${range.end}/${file.sizeInBytes}` - ) - } - - return ctx.req.method == "HEAD" ? ctx.body(null) : startHonoStream(ctx, async (webStream) => { - await webStream.pipe(Readable.toWeb(stream) as ReadableStream) - }, async (err, webStream) => { - console.error(err) - await webStream.close() - }) + return new Response(Readable.toWeb(stream) as ReadableStream, ctx.res) }) .catch((err) => { return ServeError(ctx, err.status, err.message)