mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-29 01:25:33 +08:00
6427ab2128
- provider.rs/types.ts: add is_full_url field to ProviderMeta - forwarder.rs: when isFullUrl is set, use base_url directly instead of appending endpoint path; also handle query passthrough and strip beta=true when transforming to /v1/chat/completions - EndpointField.tsx: add Link2 icon toggle button for full URL mode - ClaudeFormFields.tsx: pass through isFullUrl/onFullUrlChange props - ProviderForm.tsx: manage localIsFullUrl state, persist to meta on save - useProviderActions.ts: block switching to isFullUrl or openai_chat providers when proxy is not running, show warning toast - App.tsx: pass isProxyRunning to useProviderActions - i18n: add fullUrlEnabled/fullUrlDisabled/fullUrlHint and proxyRequiredForSwitch translations for zh/en/ja
101 lines
3.0 KiB
TypeScript
101 lines
3.0 KiB
TypeScript
import { useTranslation } from "react-i18next";
|
|
import { FormLabel } from "@/components/ui/form";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Zap, Link2 } from "lucide-react";
|
|
|
|
interface EndpointFieldProps {
|
|
id: string;
|
|
label: string;
|
|
value: string;
|
|
onChange: (value: string) => void;
|
|
placeholder: string;
|
|
hint?: string;
|
|
showManageButton?: boolean;
|
|
onManageClick?: () => void;
|
|
manageButtonLabel?: string;
|
|
showFullUrlToggle?: boolean;
|
|
isFullUrl?: boolean;
|
|
onFullUrlChange?: (value: boolean) => void;
|
|
}
|
|
|
|
export function EndpointField({
|
|
id,
|
|
label,
|
|
value,
|
|
onChange,
|
|
placeholder,
|
|
hint,
|
|
showManageButton = true,
|
|
onManageClick,
|
|
manageButtonLabel,
|
|
showFullUrlToggle = false,
|
|
isFullUrl = false,
|
|
onFullUrlChange,
|
|
}: EndpointFieldProps) {
|
|
const { t } = useTranslation();
|
|
|
|
const defaultManageLabel = t("providerForm.manageAndTest", {
|
|
defaultValue: "管理和测速",
|
|
});
|
|
|
|
return (
|
|
<div className="space-y-2">
|
|
<div className="flex items-center justify-between">
|
|
<FormLabel htmlFor={id}>{label}</FormLabel>
|
|
{showManageButton && onManageClick && (
|
|
<button
|
|
type="button"
|
|
onClick={onManageClick}
|
|
className="flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors"
|
|
>
|
|
<Zap className="h-3.5 w-3.5" />
|
|
{manageButtonLabel || defaultManageLabel}
|
|
</button>
|
|
)}
|
|
</div>
|
|
<Input
|
|
id={id}
|
|
type="text"
|
|
value={value}
|
|
onChange={(e) => onChange(e.target.value)}
|
|
placeholder={placeholder}
|
|
autoComplete="off"
|
|
/>
|
|
{showFullUrlToggle && onFullUrlChange && (
|
|
<div className="flex items-center gap-2">
|
|
<button
|
|
type="button"
|
|
onClick={() => onFullUrlChange(!isFullUrl)}
|
|
className={`flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-md border transition-colors ${
|
|
isFullUrl
|
|
? "border-primary bg-primary/10 text-primary"
|
|
: "border-border text-muted-foreground hover:text-foreground hover:border-foreground/30"
|
|
}`}
|
|
>
|
|
<Link2 className="h-3.5 w-3.5" />
|
|
{isFullUrl
|
|
? t("providerForm.fullUrlEnabled", {
|
|
defaultValue: "完整 URL 模式",
|
|
})
|
|
: t("providerForm.fullUrlDisabled", {
|
|
defaultValue: "标记为完整 URL",
|
|
})}
|
|
</button>
|
|
{isFullUrl && (
|
|
<span className="text-xs text-muted-foreground">
|
|
{t("providerForm.fullUrlHint", {
|
|
defaultValue: "代理将直接使用此 URL,不拼接路径",
|
|
})}
|
|
</span>
|
|
)}
|
|
</div>
|
|
)}
|
|
{hint ? (
|
|
<div className="p-3 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-700 rounded-lg">
|
|
<p className="text-xs text-amber-600 dark:text-amber-400">{hint}</p>
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
);
|
|
}
|