This commit is contained in:
2026-05-09 18:24:08 +08:00
parent a0ed128bde
commit bc704d0c22
38 changed files with 481 additions and 378 deletions

View File

@@ -99,7 +99,10 @@ import {
buildPublicWorkStagePath,
pushAppHistoryPath,
} from '../../routing/appPageRoutes';
import { ApiClientError } from '../../services/apiClient';
import {
ApiClientError,
BACKGROUND_AUTH_REQUEST_OPTIONS,
} from '../../services/apiClient';
import {
getPublicAuthUserByCode,
getPublicAuthUserById,
@@ -383,11 +386,8 @@ const AGENT_RESULT_STRUCTURAL_BLOCKER_CODES = new Set([
'publish_missing_main_chapter',
'publish_missing_first_act',
]);
const RECOMMEND_RUNTIME_BACKGROUND_AUTH_OPTIONS = {
skipRefresh: true,
notifyAuthStateChange: false,
clearAuthOnUnauthorized: false,
};
const RECOMMEND_RUNTIME_BACKGROUND_AUTH_OPTIONS =
BACKGROUND_AUTH_REQUEST_OPTIONS;
const PUBLIC_PUZZLE_RUNTIME_AUTH_OPTIONS =
RECOMMEND_RUNTIME_BACKGROUND_AUTH_OPTIONS;

View File

@@ -211,6 +211,7 @@ async function openExistingRpgDraft(
}
const ISOLATED_RUNTIME_AUTH_OPTIONS = {
authImpact: 'local',
skipRefresh: true,
notifyAuthStateChange: false,
clearAuthOnUnauthorized: false,
@@ -3682,6 +3683,10 @@ test('formal puzzle runtime uses frontend move merge logic and backend leaderboa
},
ISOLATED_RUNTIME_AUTH_OPTIONS,
);
vi.mocked(listProfileSaveArchives).mockClear();
vi.mocked(listProfileSaveArchives).mockRejectedValueOnce(
new Error('后台存档刷新 401'),
);
await user.click(document.querySelector('[data-piece-id="piece-0"]')!);
await user.click(document.querySelector('[data-piece-id="piece-1"]')!);
@@ -3711,6 +3716,9 @@ test('formal puzzle runtime uses frontend move merge logic and backend leaderboa
);
expect(dialog).toBeTruthy();
expect(screen.getByText('测试玩家')).toBeTruthy();
expect(listProfileSaveArchives).toHaveBeenCalledWith(
ISOLATED_RUNTIME_AUTH_OPTIONS,
);
await user.click(within(dialog).getByRole('button', { name: '下一关' }));

View File

@@ -22,14 +22,22 @@ import {
resumeRpgProfileSaveArchive,
upsertRpgProfileBrowseHistory,
} from '../../services/rpg-entry';
import {
RUNTIME_BACKGROUND_AUTH_OPTIONS,
type RuntimeRequestOptions,
} from '../../services/rpg-runtime/rpgRuntimeRequest';
import type { CustomWorldProfile } from '../../types';
import type { PlatformHomeTab } from './RpgEntryHomeView';
import { resolveRpgEntryErrorMessage } from './rpgEntryShared';
const PLATFORM_BOOTSTRAP_AUTH_OPTIONS = RUNTIME_BACKGROUND_AUTH_OPTIONS;
type UseRpgEntryBootstrapParams = {
user: AuthUser | null | undefined;
canAccessProtectedData?: boolean | undefined;
getProfileDashboard: () => Promise<ProfileDashboardSummary | null>;
getProfileDashboard: (
options?: RuntimeRequestOptions,
) => Promise<ProfileDashboardSummary | null>;
handleContinueGame: (
snapshot?: HydratedSavedGameSnapshot | null,
) => void;
@@ -99,7 +107,9 @@ export function useRpgEntryBootstrap(
setDashboardError(null);
try {
setProfileDashboard(await getProfileDashboard());
setProfileDashboard(
await getProfileDashboard(PLATFORM_BOOTSTRAP_AUTH_OPTIONS),
);
} catch (error) {
setDashboardError(
resolveRpgEntryErrorMessage(error, '读取个人数据看板失败。'),
@@ -115,7 +125,9 @@ export function useRpgEntryBootstrap(
return [];
}
const nextItems = await listRpgCreationWorks();
const nextItems = await listRpgCreationWorks(
PLATFORM_BOOTSTRAP_AUTH_OPTIONS,
);
setCustomWorldWorkEntries(nextItems);
return nextItems;
}, [canReadProtectedData, user]);
@@ -132,7 +144,9 @@ export function useRpgEntryBootstrap(
return [];
}
const nextEntries = await listRpgEntryWorldLibrary();
const nextEntries = await listRpgEntryWorldLibrary(
PLATFORM_BOOTSTRAP_AUTH_OPTIONS,
);
setSavedCustomWorldEntries(nextEntries);
return nextEntries;
}, [canReadProtectedData, user]);
@@ -147,7 +161,9 @@ export function useRpgEntryBootstrap(
setSaveError(null);
try {
const nextEntries = await listRpgProfileSaveArchives();
const nextEntries = await listRpgProfileSaveArchives(
PLATFORM_BOOTSTRAP_AUTH_OPTIONS,
);
setSaveEntries(nextEntries);
return nextEntries;
} catch (error) {
@@ -161,7 +177,10 @@ export function useRpgEntryBootstrap(
setHistoryError(null);
try {
const syncedEntries = await upsertRpgProfileBrowseHistory(entry);
const syncedEntries = await upsertRpgProfileBrowseHistory(
entry,
PLATFORM_BOOTSTRAP_AUTH_OPTIONS,
);
setHistoryEntries(syncedEntries);
} catch (error) {
setHistoryError(
@@ -237,18 +256,20 @@ export function useRpgEntryBootstrap(
saveArchivesResult,
] = await Promise.allSettled([
canReadProtectedData
? listRpgEntryWorldLibrary()
? listRpgEntryWorldLibrary(PLATFORM_BOOTSTRAP_AUTH_OPTIONS)
: Promise.resolve([]),
canReadProtectedData
? listRpgCreationWorks()
? listRpgCreationWorks(PLATFORM_BOOTSTRAP_AUTH_OPTIONS)
: Promise.resolve([]),
listRpgEntryWorldGallery(),
canReadProtectedData ? getProfileDashboard() : Promise.resolve(null),
canReadProtectedData
? listRpgProfileBrowseHistory()
? getProfileDashboard(PLATFORM_BOOTSTRAP_AUTH_OPTIONS)
: Promise.resolve(null),
canReadProtectedData
? listRpgProfileBrowseHistory(PLATFORM_BOOTSTRAP_AUTH_OPTIONS)
: Promise.resolve([]),
canReadProtectedData
? listRpgProfileSaveArchives()
? listRpgProfileSaveArchives(PLATFORM_BOOTSTRAP_AUTH_OPTIONS)
: Promise.resolve([]),
]);