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

---------
This commit is contained in:
synchrone
2026-10-24 08:58:58 +08:00
committed by GitHub
parent 1f77947137
commit ab97c63292
+4 -1
View File
@@ -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<Buffer>) {
if (c.req.method === 'HEAD') {
return c.body(null);
}
return stream(c, async (stream) => {
let aborted = false;
stream.onAbort(() => {