refactor: 收口公开码搜索映射

This commit is contained in:
2026-06-04 06:04:55 +08:00
parent 217cc881e6
commit e570d50e9f
9 changed files with 749 additions and 123 deletions

View File

@@ -3,9 +3,11 @@ import { describe, expect, it } from 'vitest';
import {
buildCustomWorldPublicWorkCode,
buildJumpHopPublicWorkCode,
buildMatch3DPublicWorkCode,
buildWoodenFishPublicWorkCode,
isSameCustomWorldPublicWorkCode,
isSameJumpHopPublicWorkCode,
isSameMatch3DPublicWorkCode,
isSameWoodenFishPublicWorkCode,
} from './publicWorkCode';
@@ -34,6 +36,24 @@ describe('publicWorkCode', () => {
);
});
it('matches current and legacy match3d public work prefixes', () => {
expect(buildMatch3DPublicWorkCode('match3d-profile-12345678')).toBe(
'M3-12345678',
);
expect(
isSameMatch3DPublicWorkCode(
'M3-12345678',
'match3d-profile-12345678',
),
).toBe(true);
expect(
isSameMatch3DPublicWorkCode(
'M3D-12345678',
'match3d-profile-12345678',
),
).toBe(true);
});
it('builds and matches custom world public work codes from profile ids', () => {
expect(buildCustomWorldPublicWorkCode('world-public-1')).toBe('CW-00000001');
expect(isSameCustomWorldPublicWorkCode('cw-00000001', 'world-public-1')).toBe(

View File

@@ -29,6 +29,14 @@ export function buildMatch3DPublicWorkCode(profileId: string) {
return `M3-${suffix}`;
}
function buildLegacyMatch3DPublicWorkCode(profileId: string) {
const normalized = normalizePublicCodeText(profileId);
const fallback = normalized || '00000000';
const suffix = fallback.slice(-8).padStart(8, '0');
return `M3D-${suffix}`;
}
export function buildSquareHolePublicWorkCode(profileId: string) {
const normalized = normalizePublicCodeText(profileId);
const fallback = normalized || '00000000';
@@ -134,6 +142,8 @@ export function isSameMatch3DPublicWorkCode(keyword: string, profileId: string)
return (
normalizedKeyword ===
normalizePublicCodeText(buildMatch3DPublicWorkCode(profileId)) ||
normalizedKeyword ===
normalizePublicCodeText(buildLegacyMatch3DPublicWorkCode(profileId)) ||
normalizedKeyword === normalizePublicCodeText(profileId)
);
}