* feat(canvas): 短剧项目空间 - 建立项目章节与画布关联 MVP * feat(canvas): 短剧项目空间 - 完善项目资产、镜头与流程闭环 Refs #30 * fix(deploy): 本地部署 - 修复前端构建并忽略本地 PostgreSQL 配置 * feat(*): 短剧项目空间 - 完成项目、章节、资产、角色与画布创作闭环 Refs #30 --------- Co-authored-by: ddCat <ddcat666@88.com>
48 lines
2.1 KiB
TypeScript
48 lines
2.1 KiB
TypeScript
import type { ReactNode } from "react";
|
|
import { useEffect, useRef } from "react";
|
|
import { App } from "antd";
|
|
|
|
import { createModelChannel, useConfigStore } from "@/stores/use-config-store";
|
|
import { navigateToSettings } from "@/lib/settings-navigation";
|
|
|
|
export function ClientRootInit({ children }: { children: ReactNode }) {
|
|
const { message } = App.useApp();
|
|
const handledConfigParams = useRef(false);
|
|
const updateConfig = useConfigStore((state) => state.updateConfig);
|
|
const config = useConfigStore((state) => state.config);
|
|
|
|
useEffect(() => {
|
|
if (handledConfigParams.current) return;
|
|
const searchParams = new URLSearchParams(window.location.search);
|
|
const baseUrl = searchParams.get("baseUrl") || searchParams.get("baseurl");
|
|
const ignoredApiKey = searchParams.has("apiKey") || searchParams.has("apikey");
|
|
if (!baseUrl && !ignoredApiKey) return;
|
|
handledConfigParams.current = true;
|
|
searchParams.delete("baseUrl");
|
|
searchParams.delete("baseurl");
|
|
searchParams.delete("apiKey");
|
|
searchParams.delete("apikey");
|
|
window.history.replaceState(null, "", `${window.location.pathname}${searchParams.size ? `?${searchParams}` : ""}${window.location.hash}`);
|
|
const firstChannel = config.channels[0];
|
|
updateConfig(
|
|
"channels",
|
|
firstChannel
|
|
? config.channels.map((channel, index) =>
|
|
index === 0
|
|
? {
|
|
...channel,
|
|
...(baseUrl ? { baseUrl } : {}),
|
|
}
|
|
: channel,
|
|
)
|
|
: [createModelChannel({ id: "default", name: "默认渠道", baseUrl: baseUrl || undefined })],
|
|
);
|
|
if (baseUrl) updateConfig("baseUrl", baseUrl);
|
|
navigateToSettings({ section: "channels" });
|
|
if (ignoredApiKey) message.warning("出于安全考虑,链接中的 API Key 已忽略,请在配置中手动填写");
|
|
else message.success("已导入本地直连地址");
|
|
}, [config.channels, message, updateConfig]);
|
|
|
|
return <>{children}</>;
|
|
}
|