Files
Genarrative/src/components/platform-entry/platformPuzzleIdentityModel.ts

37 lines
1.2 KiB
TypeScript

/** 收口拼图草稿在 session/profile/work 之间的稳定身份互推规则。 */
export function buildPuzzleResultProfileId(
sessionId: string | null | undefined,
) {
const stableSuffix = resolvePuzzleSessionStableSuffix(sessionId);
return stableSuffix ? `puzzle-profile-${stableSuffix}` : null;
}
export function buildPuzzleResultWorkId(sessionId: string | null | undefined) {
const stableSuffix = resolvePuzzleSessionStableSuffix(sessionId);
return stableSuffix ? `puzzle-work-${stableSuffix}` : null;
}
export function buildPuzzleSessionIdFromProfileId(
profileId: string | null | undefined,
) {
const normalizedProfileId = profileId?.trim();
if (!normalizedProfileId?.startsWith('puzzle-profile-')) {
return null;
}
const stableSuffix = normalizedProfileId.slice('puzzle-profile-'.length);
return stableSuffix ? `puzzle-session-${stableSuffix}` : null;
}
function resolvePuzzleSessionStableSuffix(
sessionId: string | null | undefined,
) {
const normalizedSessionId = sessionId?.trim();
if (!normalizedSessionId) {
return null;
}
return normalizedSessionId.startsWith('puzzle-session-')
? normalizedSessionId.slice('puzzle-session-'.length)
: normalizedSessionId;
}