/** 登录入口在解析JSON之前限制字节数,防止公开入口先无界缓存再交给后端校验。 */ export async function readLoginInput( request: Request, ): Promise> { if (!request.body) throw new SyntaxError("登录内容不合法"); const reader = request.body.getReader(), decoder = new TextDecoder(); let bytes = 0, text = ""; try { for (;;) { const { done, value } = await reader.read(); if (done) break; bytes += value.byteLength; if (bytes > 8192) { await reader.cancel(); throw new RangeError("登录内容过长"); } text += decoder.decode(value, { stream: true }); } text += decoder.decode(); } finally { reader.releaseLock(); } const body: unknown = JSON.parse(text); if (!body || typeof body !== "object" || Array.isArray(body)) throw new SyntaxError("登录内容不合法"); return body as Record; }