fix(admin): auto-fill provider base url and block email autofill
This commit is contained in:
parent
b7de92ec4e
commit
801d61f9a6
@ -379,6 +379,32 @@ const PROVIDER_TYPES = [
|
||||
{ value: "fal-video", label: "FAL 视频生成" },
|
||||
];
|
||||
|
||||
const PROVIDER_DEFAULT_BASE_URL: Record<string, string> = {
|
||||
alibaba: "https://dashscope.aliyuncs.com/compatible-mode/v1",
|
||||
"alibaba-image":
|
||||
"https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation",
|
||||
"ruxa-image": "https://api.ruxa.ai",
|
||||
"fal-image": "https://fal.run",
|
||||
"fal-video": "https://fal.run",
|
||||
zhipu: "https://open.bigmodel.cn/api/paas/v4",
|
||||
"volcano-multimodal": "https://ark.cn-beijing.volces.com/api/v3",
|
||||
openai: "https://api.openai.com/v1",
|
||||
"huanke-gemini": "https://api.huandutech.com/v1",
|
||||
"qianwen-video": "https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation",
|
||||
"doubao-video": "https://ark.cn-beijing.volces.com/api/v3",
|
||||
"volcano-vision": "https://ark.cn-beijing.volces.com",
|
||||
"volcano-video": "https://ark.cn-beijing.volces.com/api/v3",
|
||||
};
|
||||
|
||||
function getProviderDefaultBaseUrl(type?: string) {
|
||||
if (!type) return "";
|
||||
return PROVIDER_DEFAULT_BASE_URL[type] || "";
|
||||
}
|
||||
|
||||
function isHttpUrlLike(value: string) {
|
||||
return /^https?:\/\//i.test(value.trim());
|
||||
}
|
||||
|
||||
export function AdminSettingsClient() {
|
||||
const [activeTab, setActiveTab] = useState("users");
|
||||
|
||||
@ -1693,7 +1719,7 @@ export function AdminSettingsClient() {
|
||||
id: "",
|
||||
name: "",
|
||||
type: "openai",
|
||||
baseUrl: "",
|
||||
baseUrl: getProviderDefaultBaseUrl("openai"),
|
||||
apiKey: "",
|
||||
isEnabled: true,
|
||||
});
|
||||
@ -1705,8 +1731,20 @@ export function AdminSettingsClient() {
|
||||
const method = editingProvider ? "PUT" : "POST";
|
||||
const isNewProvider = !editingProvider;
|
||||
const isVolcanoVideo = providerForm.type === 'volcano-video';
|
||||
const defaultBaseUrl = getProviderDefaultBaseUrl(providerForm.type);
|
||||
const normalizedBaseUrl = providerForm.baseUrl.trim();
|
||||
|
||||
let requestData: any = editingProvider ? { ...providerForm, id: editingProvider } : providerForm;
|
||||
|
||||
if (
|
||||
defaultBaseUrl &&
|
||||
(!normalizedBaseUrl || !isHttpUrlLike(normalizedBaseUrl) || normalizedBaseUrl.includes("@"))
|
||||
) {
|
||||
requestData.baseUrl = defaultBaseUrl;
|
||||
} else {
|
||||
requestData.baseUrl = normalizedBaseUrl;
|
||||
}
|
||||
|
||||
if (editingProvider && !providerForm.apiKey) {
|
||||
const { apiKey, ...restData } = requestData;
|
||||
requestData = restData;
|
||||
@ -5434,24 +5472,25 @@ export function AdminSettingsClient() {
|
||||
<Select
|
||||
value={providerForm.type}
|
||||
onValueChange={(value) =>
|
||||
setProviderForm((prev) => ({
|
||||
...prev,
|
||||
type: value as any,
|
||||
baseUrl:
|
||||
!prev.baseUrl && value === "ruxa-image"
|
||||
? "https://api.ruxa.ai"
|
||||
: !prev.baseUrl && value === "fal-image"
|
||||
? "https://fal.run"
|
||||
: !prev.baseUrl && value === "fal-video"
|
||||
? "https://fal.run"
|
||||
: !prev.baseUrl && value === "doubao-video"
|
||||
? "https://ark.cn-beijing.volces.com/api/v3"
|
||||
: !prev.baseUrl && value === "zhipu"
|
||||
? "https://open.bigmodel.cn/api/paas/v4"
|
||||
: !prev.baseUrl && value === "volcano-multimodal"
|
||||
? "https://ark.cn-beijing.volces.com/api/v3"
|
||||
: prev.baseUrl,
|
||||
}))
|
||||
setProviderForm((prev) => {
|
||||
const previousDefaultBaseUrl = getProviderDefaultBaseUrl(prev.type);
|
||||
const nextDefaultBaseUrl = getProviderDefaultBaseUrl(value);
|
||||
const currentBaseUrl = prev.baseUrl.trim();
|
||||
const shouldAutoReplace =
|
||||
!editingProvider ||
|
||||
!currentBaseUrl ||
|
||||
currentBaseUrl === previousDefaultBaseUrl ||
|
||||
!isHttpUrlLike(currentBaseUrl) ||
|
||||
currentBaseUrl.includes("@");
|
||||
|
||||
return {
|
||||
...prev,
|
||||
type: value as any,
|
||||
baseUrl: shouldAutoReplace
|
||||
? nextDefaultBaseUrl || currentBaseUrl
|
||||
: currentBaseUrl,
|
||||
};
|
||||
})
|
||||
}
|
||||
>
|
||||
<SelectTrigger><SelectValue /></SelectTrigger>
|
||||
@ -5470,21 +5509,9 @@ export function AdminSettingsClient() {
|
||||
<Input
|
||||
value={providerForm.baseUrl}
|
||||
onChange={(e) => setProviderForm({ ...providerForm, baseUrl: e.target.value })}
|
||||
placeholder={
|
||||
providerForm.type === "ruxa-image"
|
||||
? "https://api.ruxa.ai"
|
||||
: providerForm.type === "fal-image"
|
||||
? "https://fal.run"
|
||||
: providerForm.type === "fal-video"
|
||||
? "https://fal.run"
|
||||
: providerForm.type === "doubao-video"
|
||||
? "https://ark.cn-beijing.volces.com/api/v3"
|
||||
: providerForm.type === "zhipu"
|
||||
? "https://open.bigmodel.cn/api/paas/v4"
|
||||
: providerForm.type === "volcano-multimodal"
|
||||
? "https://ark.cn-beijing.volces.com/api/v3"
|
||||
: "https://api.openai.com/v1"
|
||||
}
|
||||
autoComplete="off"
|
||||
inputMode="url"
|
||||
placeholder={getProviderDefaultBaseUrl(providerForm.type) || "https://api.openai.com/v1"}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
@ -5494,6 +5521,7 @@ export function AdminSettingsClient() {
|
||||
type={showApiKey ? "text" : "password"}
|
||||
value={providerForm.apiKey}
|
||||
onChange={(e) => setProviderForm({ ...providerForm, apiKey: e.target.value })}
|
||||
autoComplete="new-password"
|
||||
placeholder={editingProvider ? "留空则不修改" : "sk-..."}
|
||||
/>
|
||||
<Button
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user