You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

23 lines
981 B

import { validateGuestCommentEmail } from "../../utils/post-comment-guest";
export type ResolvedGuestFields = {
guestEmail: string | null;
guestIsAnonymous: boolean;
};
export function resolveGuestFields(input: {
viewerPresent: boolean;
guestEmail?: string;
guestIsAnonymous?: boolean;
}): ResolvedGuestFields {
if (input.viewerPresent) {
return { guestEmail: null, guestIsAnonymous: false };
}
// 兼容过渡策略:旧客户端尚未上送 guestEmail/guestIsAnonymous 时,按匿名处理,避免发布窗口内全量 400。
// 待所有客户端完成升级后可移除此分支,恢复严格“默认非匿名且邮箱必填”语义。
const isLegacyGuestPayload = input.guestEmail == null && input.guestIsAnonymous === undefined;
const guestIsAnonymous = input.guestIsAnonymous === true || isLegacyGuestPayload;
const guestEmail = validateGuestCommentEmail(input.guestEmail, guestIsAnonymous);
return { guestEmail, guestIsAnonymous };
}