From ab97c63292500656e59068cb2cd8242177353c8d Mon Sep 17 00:00:00 2001 From: synchrone Date: Sat, 24 Oct 2026 02:58:58 +0200 Subject: [PATCH] fix(route/telegram): pass media range limit to iterDownload in bytes (#23672) * fix(route/telegram): pass media range limit to iterDownload in bytes iterDownload counts limit in bytes, but streamDocument passed the number of 512 KiB blocks. Every Range request therefore stopped after a single block while Content-Length promised the whole range, so players stalled and retried on each seek. * fix: ignore HEAD instead of holding download slot --------- --- lib/routes/telegram/channel-media.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/routes/telegram/channel-media.ts b/lib/routes/telegram/channel-media.ts index 71e05335d4..8c78cc00a6 100644 --- a/lib/routes/telegram/channel-media.ts +++ b/lib/routes/telegram/channel-media.ts @@ -95,7 +95,7 @@ async function* streamDocument(client: TelegramClient, obj: Api.Document, thumbS requestSize, dcId: obj.dcId, offset: alignedOffset, - limit: limit ? Math.ceil(limit.subtract(alignedOffset).add(1).toJSNumber() / requestSize) : undefined, + limit: limit ? limit.subtract(alignedOffset).add(1).toJSNumber() : undefined, } ); for await (const chunk of chunks) { @@ -166,6 +166,9 @@ export async function configureMiddlewares(ctx: Context) { } } function streamResponse(c: Context, bodyIter: AsyncGenerator) { + if (c.req.method === 'HEAD') { + return c.body(null); + } return stream(c, async (stream) => { let aborted = false; stream.onAbort(() => {