From f059cd0ee24bc0e238658001f47cc772f58f557a Mon Sep 17 00:00:00 2001 From: npmrun <1549469775@qq.com> Date: Mon, 20 Apr 2026 20:44:24 +0800 Subject: [PATCH] fix(comments): preserve undefined guest anonymity in API parsing Keep guestIsAnonymous undefined when the field is omitted so legacy-client compatibility fallback can trigger. Explicit false remains strict and still requires guest email. Made-with: Cursor --- server/api/public/comments-create-body.test.ts | 15 +++++++++++++++ server/api/public/comments-create-body.ts | 6 +++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/server/api/public/comments-create-body.test.ts b/server/api/public/comments-create-body.test.ts index 1051403..8119aeb 100644 --- a/server/api/public/comments-create-body.test.ts +++ b/server/api/public/comments-create-body.test.ts @@ -25,6 +25,21 @@ describe("parsePublicPostCreateCommentBody", () => { body: "hello", }); }); + + test("keeps guestIsAnonymous as undefined when field is missing", () => { + const parsed = parsePublicPostCreateCommentBody({ + guestDisplayName: "访客C", + guestEmail: undefined, + body: "legacy", + }); + expect(parsed).toEqual({ + parentId: null, + guestDisplayName: "访客C", + guestEmail: undefined, + guestIsAnonymous: undefined, + body: "legacy", + }); + }); }); describe("parseUnlistedCreateCommentBody", () => { diff --git a/server/api/public/comments-create-body.ts b/server/api/public/comments-create-body.ts index 1b467b8..824eec4 100644 --- a/server/api/public/comments-create-body.ts +++ b/server/api/public/comments-create-body.ts @@ -10,7 +10,7 @@ export type ParsedCreateCommentInput = { parentId: number | null; guestDisplayName?: string; guestEmail?: string; - guestIsAnonymous: boolean; + guestIsAnonymous?: boolean; body: string; }; @@ -22,7 +22,7 @@ export function parsePublicPostCreateCommentBody(body: CreateCommentRequestBody) parentId: parseParentId(body.parentId), guestDisplayName: typeof body.guestDisplayName === "string" ? body.guestDisplayName : undefined, guestEmail: typeof body.guestEmail === "string" ? body.guestEmail : undefined, - guestIsAnonymous: body.guestIsAnonymous === true, + guestIsAnonymous: typeof body.guestIsAnonymous === "boolean" ? body.guestIsAnonymous : undefined, body: body.body, }; } @@ -35,7 +35,7 @@ export function parseUnlistedCreateCommentBody(body: CreateCommentRequestBody): parentId: parseParentId(body.parentId), guestDisplayName: typeof body.guestDisplayName === "string" ? body.guestDisplayName : undefined, guestEmail: typeof body.guestEmail === "string" ? body.guestEmail : undefined, - guestIsAnonymous: body.guestIsAnonymous === true, + guestIsAnonymous: typeof body.guestIsAnonymous === "boolean" ? body.guestIsAnonymous : undefined, body: body.body, }; }