feat: move creation entry config to database

This commit is contained in:
2026-05-11 11:23:24 +08:00
parent 7f2461313e
commit 793d82cccd
37 changed files with 1458 additions and 204 deletions

View File

@@ -1,4 +1,4 @@
import { ArrowRight, Loader2, Sparkles } from 'lucide-react';
import { ArrowRight, Loader2, Sparkles } from 'lucide-react';
import { AnimatePresence, motion } from 'motion/react';
import {
type Dispatch,
@@ -99,10 +99,15 @@ import {
buildPublicWorkStagePath,
pushAppHistoryPath,
} from '../../routing/appPageRoutes';
import { resolveRuntimeNotFoundRecoveryAction } from '../../routing/runtimeNotFoundRecovery';
import {
ApiClientError,
BACKGROUND_AUTH_REQUEST_OPTIONS,
} from '../../services/apiClient';
import {
fetchCreationEntryConfig,
type CreationEntryConfig,
} from '../../services/creationEntryConfigService';
import {
getPublicAuthUserByCode,
getPublicAuthUserById,
@@ -293,6 +298,7 @@ import {
import { PlatformEntryCreationTypeModal } from './PlatformEntryCreationTypeModal';
import type { PlatformCreationTypeId } from './platformEntryCreationTypes';
import {
derivePlatformCreationTypes,
getVisiblePlatformCreationTypes,
isPlatformCreationTypeVisible,
} from './platformEntryCreationTypes';
@@ -875,6 +881,24 @@ function isMissingPuzzleWorkError(error: unknown) {
);
}
function maybeAlertRuntimeNotFoundAndReturnHome() {
if (typeof window === 'undefined') {
return false;
}
const recoveryAction = resolveRuntimeNotFoundRecoveryAction(
window.location.pathname,
);
if (!recoveryAction) {
return false;
}
// 中文注释:直接 runtime 深链找不到作品时,弹窗确认后立刻回首页,避免保留空白运行态。
window.alert('作品不存在或已下架,将返回首页。');
pushAppHistoryPath(recoveryAction.nextPath);
return true;
}
function hasSeenPuzzleOnboarding() {
if (typeof window === 'undefined') {
return true;
@@ -1679,7 +1703,22 @@ export function PlatformEntryFlowShellImpl({
] = useState<string | null>(null);
const [publishSharePayload, setPublishSharePayload] =
useState<PublishShareModalPayload | null>(null);
const isBigFishCreationVisible = isPlatformCreationTypeVisible('big-fish');
const [creationEntryConfig, setCreationEntryConfig] =
useState<CreationEntryConfig | null>(null);
const [creationEntryConfigError, setCreationEntryConfigError] = useState<
string | null
>(null);
const creationEntryTypes = useMemo(
() =>
creationEntryConfig
? derivePlatformCreationTypes(creationEntryConfig.creationTypes)
: [],
[creationEntryConfig],
);
const isBigFishCreationVisible = isPlatformCreationTypeVisible(
creationEntryTypes,
'big-fish',
);
const [profilePlayStats, setProfilePlayStats] =
useState<ProfilePlayStatsResponse | null>(null);
const [profilePlayStatsError, setProfilePlayStatsError] = useState<
@@ -1695,6 +1734,27 @@ export function PlatformEntryFlowShellImpl({
);
const handledInitialPublicWorkCodeRef = useRef<string | null>(null);
useEffect(() => {
let cancelled = false;
setCreationEntryConfigError(null);
void fetchCreationEntryConfig()
.then((config) => {
if (!cancelled) {
setCreationEntryConfig(config);
}
})
.catch((error: unknown) => {
if (!cancelled) {
setCreationEntryConfigError(
error instanceof Error ? error.message : '读取创作入口配置失败。',
);
}
});
return () => {
cancelled = true;
};
}, []);
const platformBootstrap = usePlatformEntryBootstrap({
user: authUi?.user,
canAccessProtectedData: authUi?.canAccessProtectedData,
@@ -4092,7 +4152,9 @@ export function PlatformEntryFlowShellImpl({
setPublicWorkDetailError(null);
setPlatformTab('home');
setSelectionStage('platform');
pushAppHistoryPath('/');
if (!maybeAlertRuntimeNotFoundAndReturnHome()) {
pushAppHistoryPath('/');
}
return false;
}
@@ -5590,7 +5652,9 @@ export function PlatformEntryFlowShellImpl({
setPublicWorkDetailError(null);
setPlatformTab('home');
setSelectionStage('platform');
pushAppHistoryPath('/');
if (!maybeAlertRuntimeNotFoundAndReturnHome()) {
pushAppHistoryPath('/');
}
return;
}
@@ -5809,7 +5873,9 @@ export function PlatformEntryFlowShellImpl({
setPublicWorkDetailError(null);
setPlatformTab('home');
setSelectionStage('platform');
pushAppHistoryPath('/');
if (!maybeAlertRuntimeNotFoundAndReturnHome()) {
pushAppHistoryPath('/');
}
return;
}
@@ -7380,7 +7446,8 @@ export function PlatformEntryFlowShellImpl({
fallbackLabel: string,
) => (
<Suspense fallback={<LazyPanelFallback label={fallbackLabel} />}>
<CustomWorldCreationHub
{creationEntryConfig ? (
<CustomWorldCreationHub
mode={mode}
items={creationHubItems}
loading={
@@ -7410,6 +7477,14 @@ export function PlatformEntryFlowShellImpl({
}
onRetry={() => {
platformBootstrap.setPlatformError(null);
setCreationEntryConfigError(null);
void fetchCreationEntryConfig()
.then(setCreationEntryConfig)
.catch((error: unknown) => {
setCreationEntryConfigError(
error instanceof Error ? error.message : '读取创作入口配置失败。',
);
});
setBigFishError(null);
setMatch3DError(null);
setSquareHoleError(null);
@@ -7431,6 +7506,7 @@ export function PlatformEntryFlowShellImpl({
void refreshVisualNovelShelf();
}}
createError={
creationEntryConfigError ??
sessionController.creationTypeError ??
bigFishError ??
match3dError ??
@@ -7440,6 +7516,7 @@ export function PlatformEntryFlowShellImpl({
visualNovelError
}
createBusy={
!creationEntryConfig ||
sessionController.isCreatingAgentSession ||
isCreativeAgentBusy ||
isCreativeAgentStreaming ||
@@ -7450,6 +7527,8 @@ export function PlatformEntryFlowShellImpl({
isVisualNovelBusy ||
isVisualNovelStreamingReply
}
entryConfig={creationEntryConfig}
creationTypes={creationEntryTypes}
onCreateType={handleCreationHubCreateType}
onOpenDraft={(item) => {
runProtectedAction(() => {
@@ -7530,6 +7609,7 @@ export function PlatformEntryFlowShellImpl({
handleDeleteVisualNovelWork(item);
}}
/>
) : null}
</Suspense>
);
const creationStartContent = (
@@ -7541,7 +7621,7 @@ export function PlatformEntryFlowShellImpl({
role="tablist"
aria-label="选择模板"
>
{getVisiblePlatformCreationTypes().map((item) => {
{getVisiblePlatformCreationTypes(creationEntryTypes).map((item) => {
const selected = item.id === 'puzzle';
const disabled =
item.locked ||
@@ -9117,7 +9197,8 @@ export function PlatformEntryFlowShellImpl({
)}
</AnimatePresence>
<PlatformEntryCreationTypeModal
{creationEntryConfig ? (
<PlatformEntryCreationTypeModal
isOpen={showCreationTypeModal}
isBusy={
sessionController.isCreatingAgentSession ||
@@ -9131,6 +9212,7 @@ export function PlatformEntryFlowShellImpl({
isVisualNovelStreamingReply
}
error={
creationEntryConfigError ??
bigFishError ??
creativeAgentError ??
match3dError ??
@@ -9140,6 +9222,8 @@ export function PlatformEntryFlowShellImpl({
puzzleError ??
sessionController.creationTypeError
}
entryConfig={creationEntryConfig}
creationTypes={creationEntryTypes}
onClose={() => {
if (
sessionController.isCreatingAgentSession ||
@@ -9192,6 +9276,7 @@ export function PlatformEntryFlowShellImpl({
});
}}
/>
) : null}
<PublishShareModal
open={Boolean(publishSharePayload)}
payload={publishSharePayload}