fix(sites): preserve remote throttling reasons and HTTP diagnostics
行为对照:MoviePilot v3.2.4,6ca7b294/f4a68f36;复用现有站点共享桶,明确频控按远端秒数冷却,错误标题脱敏;修复有界响应读取对单个大数据块的限制。
This commit is contained in:
1 parent
32e1d446b5
commit
b44ebc2ba1
3 files changed
+233
-13
No files matched your search
@@ -126,7 +126,7 @@ function concatBytes(chunks: Uint8Array[], total: number): Uint8Array<ArrayBuffe
|
||||
}
|
||||
|
||||
/** 先读最多 max 字节;返回读到的部分、是否读完,以及一个内容不变的新响应(没读完的部分接着原流) */
|
||||
async function peekBody(
|
||||
export async function peekBody(
|
||||
res: Response,
|
||||
max: number,
|
||||
): Promise<{ head: Uint8Array<ArrayBuffer>; complete: boolean; res: Response }> {
|
||||
@@ -134,14 +134,17 @@ async function peekBody(
|
||||
const chunks: Uint8Array[] = [];
|
||||
let total = 0;
|
||||
let complete = false;
|
||||
let remainder: Uint8Array | undefined;
|
||||
while (total < max) {
|
||||
const r = await reader.read();
|
||||
if (r.done) {
|
||||
complete = true;
|
||||
break;
|
||||
}
|
||||
chunks.push(r.value);
|
||||
total += r.value.byteLength;
|
||||
const length = Math.min(r.value.byteLength, max - total);
|
||||
chunks.push(r.value.subarray(0, length));
|
||||
total += length;
|
||||
if (length < r.value.byteLength) remainder = r.value.subarray(length);
|
||||
}
|
||||
const head = concatBytes(chunks, total);
|
||||
const init = { status: res.status, statusText: res.statusText, headers: res.headers };
|
||||
@@ -149,6 +152,7 @@ async function peekBody(
|
||||
const stream = new ReadableStream<Uint8Array>({
|
||||
start(c) {
|
||||
c.enqueue(head);
|
||||
if (remainder) c.enqueue(remainder);
|
||||
},
|
||||
async pull(c) {
|
||||
const r = await reader.read();
|
||||
|
||||
Reference in new issue
Block a user