feat(growth): 接入游客推荐与权益体验
- 登录:新增游客体验、登录承接和同源及请求体积校验 - 推荐与埋点:接入曝光回执、兴趣偏好和按账号隔离的重试队列 - 聊天体验:展示剩余额度、支持回答反馈及故事记忆管理 - 文档和测试:同步业务边界,覆盖队列幂等与代理登录校验
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
/** 登录入口在解析JSON之前限制字节数,防止公开入口先无界缓存再交给后端校验。 */
|
||||
export async function readLoginInput(
|
||||
request: Request,
|
||||
): Promise<Record<string, unknown>> {
|
||||
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<string, unknown>;
|
||||
}
|
||||
Reference in New Issue
Block a user