refactor: 收口公开码搜索计划
This commit is contained in:
@@ -512,6 +512,10 @@ import {
|
||||
resolveMatch3DRuntimeGeneratedBackgroundAsset,
|
||||
resolveMatch3DRuntimeGeneratedItemAssets,
|
||||
} from './platformMatch3DRuntimeProfile';
|
||||
import {
|
||||
type PlatformPublicCodeSearchStep,
|
||||
resolvePlatformPublicCodeSearchPlan,
|
||||
} from './platformPublicCodeSearchModel';
|
||||
import {
|
||||
getPlatformPublicGalleryEntryKey,
|
||||
getPlatformRecommendRuntimeKind,
|
||||
@@ -13449,53 +13453,17 @@ export function PlatformEntryFlowShellImpl({
|
||||
|
||||
const handlePublicCodeSearch = useCallback(
|
||||
async (keyword: string) => {
|
||||
const normalizedKeyword = keyword.trim();
|
||||
if (!normalizedKeyword) {
|
||||
const searchPlan = resolvePlatformPublicCodeSearchPlan(keyword);
|
||||
if (!searchPlan) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { normalizedKeyword } = searchPlan;
|
||||
|
||||
setIsSearchingPublicCode(true);
|
||||
setPublicSearchError(null);
|
||||
setSearchedPublicUser(null);
|
||||
|
||||
const upperKeyword = normalizedKeyword.toUpperCase();
|
||||
const shouldSearchUserIdFirst = /^user[_-][a-z0-9_-]+$/iu.test(
|
||||
normalizedKeyword,
|
||||
);
|
||||
const shouldSearchBigFishFirst = upperKeyword.startsWith('BF');
|
||||
const shouldSearchBabyObjectFirst = upperKeyword.startsWith('BO');
|
||||
const shouldSearchJumpHopFirst = upperKeyword.startsWith('JH');
|
||||
const shouldSearchWoodenFishFirst = upperKeyword.startsWith('WF');
|
||||
const shouldSearchMatch3DFirst = upperKeyword.startsWith('M3');
|
||||
const shouldSearchPuzzleFirst = upperKeyword.startsWith('PZ');
|
||||
const shouldSearchSquareHoleFirst = upperKeyword.startsWith('SH');
|
||||
const shouldSearchVisualNovelFirst = upperKeyword.startsWith('VN');
|
||||
const shouldSearchBarkBattleFirst = upperKeyword.startsWith('BB');
|
||||
const shouldSearchWorkFirst =
|
||||
!shouldSearchUserIdFirst &&
|
||||
!shouldSearchBabyObjectFirst &&
|
||||
!shouldSearchBigFishFirst &&
|
||||
!shouldSearchJumpHopFirst &&
|
||||
!shouldSearchWoodenFishFirst &&
|
||||
!shouldSearchMatch3DFirst &&
|
||||
!shouldSearchPuzzleFirst &&
|
||||
!shouldSearchSquareHoleFirst &&
|
||||
!shouldSearchVisualNovelFirst &&
|
||||
!shouldSearchBarkBattleFirst &&
|
||||
(upperKeyword.startsWith('CW') || /^\d{1,8}$/u.test(normalizedKeyword));
|
||||
const shouldSearchUserFirst =
|
||||
shouldSearchUserIdFirst ||
|
||||
upperKeyword.startsWith('SY') ||
|
||||
(!shouldSearchWorkFirst &&
|
||||
!shouldSearchBigFishFirst &&
|
||||
!shouldSearchBabyObjectFirst &&
|
||||
!shouldSearchJumpHopFirst &&
|
||||
!shouldSearchWoodenFishFirst &&
|
||||
!shouldSearchMatch3DFirst &&
|
||||
!shouldSearchPuzzleFirst &&
|
||||
!shouldSearchSquareHoleFirst &&
|
||||
!shouldSearchVisualNovelFirst);
|
||||
|
||||
const tryOpenGalleryEntry = async () => {
|
||||
const entry =
|
||||
await getRpgEntryWorldGalleryDetailByCode(normalizedKeyword);
|
||||
@@ -13717,95 +13685,66 @@ export function PlatformEntryFlowShellImpl({
|
||||
);
|
||||
};
|
||||
|
||||
try {
|
||||
if (shouldSearchUserIdFirst) {
|
||||
const user = await getPublicAuthUserById(normalizedKeyword);
|
||||
setSearchedPublicUser(user);
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldSearchPuzzleFirst) {
|
||||
await tryOpenPuzzleGalleryEntry();
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldSearchBigFishFirst) {
|
||||
await tryOpenBigFishGalleryEntry();
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldSearchJumpHopFirst) {
|
||||
await tryOpenJumpHopGalleryEntry();
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldSearchWoodenFishFirst) {
|
||||
await tryOpenWoodenFishGalleryEntry();
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldSearchBabyObjectFirst) {
|
||||
await tryOpenBabyObjectMatchGalleryEntry();
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldSearchMatch3DFirst) {
|
||||
await tryOpenMatch3DGalleryEntry();
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldSearchSquareHoleFirst) {
|
||||
await tryOpenSquareHoleGalleryEntry();
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldSearchVisualNovelFirst) {
|
||||
await tryOpenVisualNovelGalleryEntry();
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldSearchBarkBattleFirst) {
|
||||
await tryOpenBarkBattleGalleryEntry();
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldSearchWorkFirst) {
|
||||
try {
|
||||
await tryOpenGalleryEntry();
|
||||
const runSearchStep = async (step: PlatformPublicCodeSearchStep) => {
|
||||
switch (step) {
|
||||
case 'user-id': {
|
||||
const user = await getPublicAuthUserById(normalizedKeyword);
|
||||
setSearchedPublicUser(user);
|
||||
return;
|
||||
} catch {
|
||||
// 作品号优先时允许继续回退到用户号搜索。
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldSearchUserFirst) {
|
||||
try {
|
||||
case 'public-user-code': {
|
||||
const user = await getPublicAuthUserByCode(normalizedKeyword);
|
||||
setSearchedPublicUser(user);
|
||||
return;
|
||||
} catch {
|
||||
// 用户号优先时允许继续回退到作品号搜索。
|
||||
}
|
||||
}
|
||||
|
||||
if (!shouldSearchWorkFirst) {
|
||||
try {
|
||||
case 'rpg-work':
|
||||
await tryOpenGalleryEntry();
|
||||
return;
|
||||
} catch {
|
||||
// 常规作品未命中时继续尝试汪汪声浪作品号。
|
||||
}
|
||||
|
||||
try {
|
||||
case 'puzzle-work':
|
||||
await tryOpenPuzzleGalleryEntry();
|
||||
return;
|
||||
case 'big-fish-work':
|
||||
await tryOpenBigFishGalleryEntry();
|
||||
return;
|
||||
case 'jump-hop-work':
|
||||
await tryOpenJumpHopGalleryEntry();
|
||||
return;
|
||||
case 'wooden-fish-work':
|
||||
await tryOpenWoodenFishGalleryEntry();
|
||||
return;
|
||||
case 'baby-object-match-work':
|
||||
await tryOpenBabyObjectMatchGalleryEntry();
|
||||
return;
|
||||
case 'match3d-work':
|
||||
await tryOpenMatch3DGalleryEntry();
|
||||
return;
|
||||
case 'square-hole-work':
|
||||
await tryOpenSquareHoleGalleryEntry();
|
||||
return;
|
||||
case 'visual-novel-work':
|
||||
await tryOpenVisualNovelGalleryEntry();
|
||||
return;
|
||||
case 'bark-battle-work':
|
||||
await tryOpenBarkBattleGalleryEntry();
|
||||
return;
|
||||
} catch {
|
||||
// 汪汪声浪作品未命中时继续回退到陶泥号搜索。
|
||||
default: {
|
||||
const exhaustive: never = step;
|
||||
return exhaustive;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const user = await getPublicAuthUserByCode(normalizedKeyword);
|
||||
setSearchedPublicUser(user);
|
||||
try {
|
||||
for (const [index, step] of searchPlan.steps.entries()) {
|
||||
try {
|
||||
await runSearchStep(step);
|
||||
return;
|
||||
} catch (error) {
|
||||
if (index === searchPlan.steps.length - 1) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
if (selectionStage === 'work-detail') {
|
||||
setSelectedPublicWorkDetail(null);
|
||||
|
||||
Reference in New Issue
Block a user