feat: move creation entry config to database
This commit is contained in:
21
src/routing/runtimeNotFoundRecovery.test.ts
Normal file
21
src/routing/runtimeNotFoundRecovery.test.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { expect, test } from 'vitest';
|
||||
|
||||
import { resolveRuntimeNotFoundRecoveryAction } from './runtimeNotFoundRecovery';
|
||||
|
||||
test('runtime not found recovery returns home after direct runtime route alert', () => {
|
||||
expect(resolveRuntimeNotFoundRecoveryAction('/runtime/puzzle')).toEqual({
|
||||
nextStage: 'platform',
|
||||
nextPath: '/',
|
||||
shouldAlert: true,
|
||||
});
|
||||
expect(resolveRuntimeNotFoundRecoveryAction('/runtime/puzzle/')).toEqual({
|
||||
nextStage: 'platform',
|
||||
nextPath: '/',
|
||||
shouldAlert: true,
|
||||
});
|
||||
});
|
||||
|
||||
test('runtime not found recovery only handles direct runtime routes', () => {
|
||||
expect(resolveRuntimeNotFoundRecoveryAction('/gallery/puzzle/detail')).toBeNull();
|
||||
expect(resolveRuntimeNotFoundRecoveryAction('/creation/puzzle/result')).toBeNull();
|
||||
});
|
||||
30
src/routing/runtimeNotFoundRecovery.ts
Normal file
30
src/routing/runtimeNotFoundRecovery.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
export type RuntimeNotFoundRecoveryAction = {
|
||||
nextStage: 'platform';
|
||||
nextPath: '/';
|
||||
shouldAlert: true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 中文注释:直接打开 /runtime/<玩法>?work=<作品号> 时,如果作品不存在,
|
||||
* 弹窗关闭后必须回到首页,避免继续停留在没有运行态数据的空白页面。
|
||||
*/
|
||||
export function resolveRuntimeNotFoundRecoveryAction(
|
||||
pathname: string,
|
||||
): RuntimeNotFoundRecoveryAction | null {
|
||||
const normalizedPath = pathname.trim().toLowerCase().replace(/\/+$/u, '');
|
||||
if (
|
||||
normalizedPath === '/runtime/puzzle' ||
|
||||
normalizedPath === '/runtime/match3d' ||
|
||||
normalizedPath === '/runtime/big-fish' ||
|
||||
normalizedPath === '/runtime/square-hole' ||
|
||||
normalizedPath === '/runtime/visual-novel'
|
||||
) {
|
||||
return {
|
||||
nextStage: 'platform',
|
||||
nextPath: '/',
|
||||
shouldAlert: true,
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user